gcc/testsuite/ChangeLog:
[official-gcc.git] / gcc / testsuite / gcc.dg / attr-alloc_size-8.c
blob91d7eb58e298f77f1561a47c44ce58043b7b0e6f
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 typedef __SIZE_TYPE__ size_t;
11 void sink (void*);
13 static size_t alloc_size_limit (void)
15 return 123;
18 static size_t alloca_limit (void)
20 return 234;
23 static size_t vla_limit (void)
25 return 345;
28 void test_alloca (void)
30 void *p;
32 /* No warning should be issued for the following call because the more
33 permissive alloca limit overrides the stricter alloc_size limit. */
34 p = __builtin_alloca (alloca_limit ());
35 sink (p);
37 p = __builtin_alloca (alloca_limit () + 1); /* { dg-warning "argument to .alloca. is too large" } */
38 sink (p);
41 void test_vla (void)
43 /* Same as above, no warning should be issued here because the more
44 permissive VLA limit overrides the stricter alloc_size limit. */
45 char vla1 [vla_limit ()];
46 sink (vla1);
48 char vla2 [vla_limit () + 1]; /* { dg-warning "argument to variable-length array is too large" } */
49 sink (vla2);
52 void test_malloc (void)
54 void *p;
55 p = __builtin_malloc (alloc_size_limit ());
56 sink (p);
58 p = __builtin_malloc (alloc_size_limit () + 1); /* { dg-warning "argument 1 value .124\[lu\]*. exceeds maximum object size 123" } */
59 sink (p);