PR middle-end/85602 - -Wsizeof-pointer-memaccess for strncat with size of source
[official-gcc.git] / gcc / testsuite / gcc.dg / Walloca-1.c
blob85e9160e8455e9bfd68d8bd0c4d9e83a87069249
1 /* { dg-do compile } */
2 /* { dg-require-effective-target alloca } */
3 /* { dg-options "-Walloca-larger-than=2000 -O2 -ftrack-macro-expansion=0" } */
5 #define alloca __builtin_alloca
7 typedef __SIZE_TYPE__ size_t;
8 extern size_t strlen(const char *);
10 extern void useit (char *);
12 int num;
14 void foo1 (size_t len, size_t len2, size_t len3)
16 int i;
18 for (i=0; i < 123; ++i)
20 char *s = alloca (566); /* { dg-warning "'alloca' within a loop" } */
21 useit (s);
24 char *s = alloca (123);
25 useit (s); // OK, constant argument to alloca
27 s = alloca (num); // { dg-warning "large due to conversion" "" { target lp64 } }
28 // { dg-warning "unbounded use of 'alloca'" "" { target { ! lp64 } } .-1 }
29 useit (s);
31 s = alloca (30000); /* { dg-warning "is too large" } */
32 useit (s);
34 if (len < 2000)
36 s = alloca(len); // OK, bounded
37 useit (s);
40 if (len + len2 < 2000) // OK, bounded
42 s = alloca(len + len2);
43 useit (s);
46 if (len3 <= 2001)
48 s = alloca(len3); /* { dg-warning "may be too large" } */
49 useit(s);
53 void foo2 (__SIZE_TYPE__ len)
55 // Test that a direct call to __builtin_alloca_with_align is not confused
56 // with a VLA.
57 void *p = __builtin_alloca_with_align (len, 8); // { dg-warning "unbounded use of 'alloca'" }
58 useit (p);
61 void foo3 (unsigned char a)
63 if (a == 0)
64 useit (__builtin_alloca (a)); // { dg-warning "argument to 'alloca' is zero" }