Small ChangeLog tweak.
[official-gcc.git] / gcc / testsuite / gcc.dg / attr-alloc_size-8.c
blobb8ba9424b4e5186418162968924e01275d0c5af3
1 /* PR c/78284 - warn on malloc with very large arguments
2 Test to exercise the interaction of the -Walloca-larger-than,
3 -Wvla-larger-than, and -Walloc-size-larger-than options. The former
4 two more specific options override the more general latter option. */
5 /* { dg-do compile } */
6 /* { dg-require-effective-target alloca } */
7 /* { dg-options "-O2 -Walloc-size-larger-than=123 -Walloca-larger-than=234 -Wvla-larger-than=345" } */
9 #define SIZE_MAX __SIZE_MAX__
11 typedef __SIZE_TYPE__ size_t;
13 void sink (void*);
15 size_t alloc_size_limit (void)
17 return 123;
20 size_t alloca_limit (void)
22 return 234;
25 size_t vla_limit (void)
27 return 345;
30 void test_alloca (void)
32 void *p;
34 /* No warning should be issued for the following call because the more
35 permissive alloca limit overrides the stricter alloc_size limit. */
36 p = __builtin_alloca (alloca_limit ());
37 sink (p);
39 p = __builtin_alloca (alloca_limit () + 1); /* { dg-warning "argument to .alloca. is too large" } */
40 sink (p);
43 void test_vla (void)
45 /* Same as above, no warning should be issued here because the more
46 permissive VLA limit overrides the stricter alloc_size limit. */
47 char vla1 [vla_limit ()];
48 sink (vla1);
50 char vla2 [vla_limit () + 1]; /* { dg-warning "argument to variable-length array is too large" } */
51 sink (vla2);
54 void test_malloc (void)
56 void *p;
57 p = __builtin_malloc (alloc_size_limit ());
58 sink (p);
60 p = __builtin_malloc (alloc_size_limit () + 1); /* { dg-warning "argument 1 value .124\[lu\]*. exceeds maximum object size 123" } */
61 sink (p);