comparison gcc/testsuite/gcc.dg/Wvla-larger-than-2.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* { dg-do compile } */
2 /* { dg-require-effective-target stdint_types } */
3 /* { dg-require-effective-target alloca } */
4 /* { dg-options "-O2 -Wvla-larger-than=40" } */
5
6 #include <stdint.h>
7
8 void f0 (void *);
9 void
10 f1 (__SIZE_TYPE__ a)
11 {
12 if (a <= 10)
13 {
14 // 10 * 4 bytes = 40: OK!
15 uint32_t x[a];
16 f0 (x);
17 }
18 }
19
20 void
21 f2 (__SIZE_TYPE__ a)
22 {
23 if (a <= 11)
24 {
25 // 11 * 4 bytes = 44: Not OK.
26 uint32_t x[a]; // { dg-warning "array may be too large" }
27 // { dg-message "note:.*argument may be as large as 44" "note" { target *-*-* } .-1 }
28 f0 (x);
29 }
30 }
31
32 void
33 f3 (__SIZE_TYPE__ a, __SIZE_TYPE__ b)
34 {
35 if (a <= 5 && b <= 3)
36 {
37 // 5 * 3 * 4 bytes = 60: Not OK.
38 uint32_t x[a][b]; // { dg-warning "array may be too large" }
39 f0 (x);
40 }
41 }
42
43 void
44 f4 (__SIZE_TYPE__ a, __SIZE_TYPE__ b)
45 {
46 if (a <= 5 && b <= 2)
47 {
48 // 5 * 2 * 4 bytes = 40 bytes: OK!
49 uint32_t x[a][b];
50 f0 (x);
51 }
52 }
53
54 void
55 f5 (__SIZE_TYPE__ len)
56 {
57 // Test that a direct call to __builtin_alloca_with_align is not
58 // confused with a VLA.
59 void *p = __builtin_alloca_with_align (len, 8);
60 f0 (p);
61 }
62
63 void
64 f6 (unsigned stuff)
65 {
66 int n = 7000;
67 do {
68 char a[n]; // { dg-warning "variable-length array is too large" }
69 f0 (a);
70 } while (stuff--);
71 }