2016-12-07 Thomas Preud'homme <thomas.preudhomme@arm.com>
[official-gcc.git] / gcc / testsuite / gcc.dg / Wvla-larger-than-2.c
blob96814dcaac08cbc02d127a2571c667f4e5c8da23
1 /* { dg-do compile } */
2 /* { dg-require-effective-target stdint_types } */
3 /* { dg-options "-O2 -Wvla-larger-than=40" } */
5 #include <stdint.h>
7 void f0 (void *);
8 void
9 f1 (__SIZE_TYPE__ a)
11 if (a <= 10)
13 // 10 * 4 bytes = 40: OK!
14 uint32_t x[a];
15 f0 (x);
19 void
20 f2 (__SIZE_TYPE__ a)
22 if (a <= 11)
24 // 11 * 4 bytes = 44: Not OK.
25 uint32_t x[a]; // { dg-warning "array may be too large" }
26 // { dg-message "note:.*argument may be as large as 44" "note" { target *-*-* } 25 }
27 f0 (x);
31 void
32 f3 (__SIZE_TYPE__ a, __SIZE_TYPE__ b)
34 if (a <= 5 && b <= 3)
36 // 5 * 3 * 4 bytes = 60: Not OK.
37 uint32_t x[a][b]; // { dg-warning "array may be too large" }
38 f0 (x);
42 void
43 f4 (__SIZE_TYPE__ a, __SIZE_TYPE__ b)
45 if (a <= 5 && b <= 2)
47 // 5 * 2 * 4 bytes = 40 bytes: OK!
48 uint32_t x[a][b];
49 f0 (x);
53 void
54 f5 (__SIZE_TYPE__ len)
56 // Test that a direct call to __builtin_alloca_with_align is not
57 // confused with a VLA.
58 void *p = __builtin_alloca_with_align (len, 8);
59 f0 (p);
62 void
63 f6 (unsigned stuff)
65 int n = 7000;
66 do {
67 char a[n]; // { dg-warning "variable-length array is too large" }
68 f0 (a);
69 } while (stuff--);