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;
15 size_t alloc_size_limit (void)
20 size_t alloca_limit (void)
25 size_t vla_limit (void)
30 void test_alloca (void)
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 ());
39 p
= __builtin_alloca (alloca_limit () + 1); /* { dg-warning "argument to .alloca. is too large" } */
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 ()];
50 char vla2
[vla_limit () + 1]; /* { dg-warning "argument to variable-length array is too large" } */
54 void test_malloc (void)
57 p
= __builtin_malloc (alloc_size_limit ());
60 p
= __builtin_malloc (alloc_size_limit () + 1); /* { dg-warning "argument 1 value .124\[lu\]*. exceeds maximum object size 123" } */