Debian Codegraph @

gcc/testsuite/gcc.dg/Walloca-1.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-Walloca-larger-than=2000 -O2 -ftrack-macro-expansion=0" } */
3
4 #define alloca __builtin_alloca
5
6 typedef __SIZE_TYPE__ size_t;
7 extern size_t strlen(const char *);
8
9 extern void useit (char *);
10
11 int num;
12
13 void foo1 (size_t len, size_t len2, size_t len3)
14 {
15 int i;
16
17 for (i=0; i < 123; ++i)
18 {
19 char *s = alloca (566); /* { dg-warning "'alloca' within a loop" } */
20 useit (s);
21 }
22
23 char *s = alloca (123);
24 useit (s); // OK, constant argument to alloca
25
26 s = alloca (num); // { dg-warning "\(may be too large|unbounded use\)" }
27 useit (s);
28
29 s = alloca (30000); /* { dg-warning "is too large" } */
30 useit (s);
31
32 if (len < 2000)
33 {
34 s = alloca(len); // OK, bounded
35 useit (s);
36 }
37
38 if (len + len2 < 2000) // OK, bounded
39 {
40 s = alloca(len + len2);
41 useit (s);
42 }
43
44 if (len3 <= 2001)
45 {
46 s = alloca(len3); /* { dg-warning "may be too large" } */
47 useit(s);
48 }
49 }
50
51 void foo2 (__SIZE_TYPE__ len)
52 {
53 // Test that a direct call to __builtin_alloca_with_align is not confused
54 // with a VLA.
55 void *p = __builtin_alloca_with_align (len, 8); // { dg-warning "unbounded use of 'alloca'" }
56 useit (p);
57 }
58
59 void foo3 (unsigned char a)
60 {
61 if (a == 0)
62 useit (__builtin_alloca (a)); // { dg-warning "argument to 'alloca' is zero" }
63 }