111
|
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" } */
|
|
8
|
|
9 typedef __SIZE_TYPE__ size_t;
|
|
10
|
|
11 void sink (void*);
|
|
12
|
131
|
13 static size_t alloc_size_limit (void)
|
111
|
14 {
|
|
15 return 123;
|
|
16 }
|
|
17
|
131
|
18 static size_t alloca_limit (void)
|
111
|
19 {
|
|
20 return 234;
|
|
21 }
|
|
22
|
131
|
23 static size_t vla_limit (void)
|
111
|
24 {
|
|
25 return 345;
|
|
26 }
|
|
27
|
|
28 void test_alloca (void)
|
|
29 {
|
|
30 void *p;
|
|
31
|
|
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);
|
|
36
|
|
37 p = __builtin_alloca (alloca_limit () + 1); /* { dg-warning "argument to .alloca. is too large" } */
|
|
38 sink (p);
|
|
39 }
|
|
40
|
|
41 void test_vla (void)
|
|
42 {
|
|
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);
|
|
47
|
|
48 char vla2 [vla_limit () + 1]; /* { dg-warning "argument to variable-length array is too large" } */
|
|
49 sink (vla2);
|
|
50 }
|
|
51
|
|
52 void test_malloc (void)
|
|
53 {
|
|
54 void *p;
|
|
55 p = __builtin_malloc (alloc_size_limit ());
|
|
56 sink (p);
|
|
57
|
|
58 p = __builtin_malloc (alloc_size_limit () + 1); /* { dg-warning "argument 1 value .124\[lu\]*. exceeds maximum object size 123" } */
|
|
59 sink (p);
|
|
60 }
|