1 /* PR middle-end/82608 - missing -Warray-bounds on an out-of-bounds VLA index
3 { dg-options "-O2 -Wall -Wno-uninitialized -ftrack-macro-expansion=0" }
4 { dg-require-effective-target alloca } */
8 typedef __INT16_TYPE__
int16_t;
10 #define alloca(n) __builtin_alloca (n)
12 void* calloc (size_t, size_t);
13 void* malloc (size_t);
15 void sink (void*, ...);
16 #define sink(...) sink (0, __VA_ARGS__)
18 #define T(x) (sink (x))
20 __attribute__ ((alloc_size (1))) void* alloc (size_t);
23 void test_alloca_cst (void)
29 T (p
[1]); // { dg-warning "subscript 1 is outside array bounds of 'char\\\[1\\\]'" }
36 T (p
[2]); // { dg-warning "subscript 2 is outside array bounds of 'char\\\[2\\\]'" }
42 T (p
[0]), T (p
[1]), T (p
[2]);
43 T (p
[3]); // { dg-warning "subscript 3 is outside array bounds of 'char\\\[3\\\]'" }
48 void test_alloca_char_range (int i
, unsigned n
, size_t sz
)
51 // Be sure to exercise signed as well as unsigned arguments.
54 T (p
[0]), T (p
[1]), T (p
[12345]);
55 T (p
[-1]); // { dg-warning "subscript -1 is outside array bounds of 'char\\\[" }
61 T (p
[0]), T (p
[1]), T (p
[12345]);
62 T (p
[-1]); // { dg-warning "subscript -1 is outside array bounds of 'char\\\[" }
66 char *p
= alloca (sz
);
68 T (p
[0]), T (p
[1]), T (p
[23456]);
69 T (p
[-1]); // { dg-warning "subscript -1 is outside array bounds of 'char\\\[" }
73 char *p
= alloca (UR (0, 1));
76 T (p
[1]); // { dg-warning "subscript 1 is outside array bounds of 'char\\\[1\\\]'" }
80 char *p
= alloca (UR (0, 2));
83 sink (p
[2]); // { dg-warning "subscript 2 is outside array bounds of 'char\\\[2\\\]'" }
87 char *p
= alloca (UR (0, 3));
89 T (p
[0]), T (p
[1]), T (p
[2]);
90 T (p
[3]); // { dg-warning "subscript 3 is outside array bounds of 'char\\\[3\\\]'" }
94 char *p
= alloca (UR (1, 3));
96 T (p
[0]), T (p
[1]), T (p
[2]);
97 T (p
[3]); // { dg-warning "subscript 3 is outside array bounds of 'char\\\[3\\\]'" }
101 char *p
= alloca (UR (2, 3));
103 T (p
[0]), T (p
[1]), T (p
[2]);
104 T (p
[3]); // { dg-warning "subscript 3 is outside array bounds of 'char\\\[3\\\]'" }
109 void test_alloca_int16_range (unsigned n
)
113 p
= alloca (n
); // { dg-message "allocated by " }
115 T (p
[0]), T (p
[1]), T (p
[12345]);
116 T (p
[-1]); // { dg-warning "subscript -1 is outside array bounds of 'int16_t\\\[" }
120 p
= alloca (UR (0, 1)); // { dg-message "at offset \\d+ into object of size \\\[0, 1] allocated by '__builtin_alloca'" "note" }
122 T (p
[0]); // { dg-warning "subscript 'int16_t {aka short int}\\\[0\\\]' is partly outside array bounds of 'unsigned char\\\[1]'" }
123 T (p
[1]); // { dg-warning "subscript 1 is outside array bounds of 'int16_t\\\[0]'" }
127 p
= alloca (UR (0, 2)); // { dg-message "at offset \\d+ into object of size \\\[0, 2] allocated by '__builtin_alloca'" "note" }
130 sink (p
[1]); // { dg-warning "subscript 1 is outside array bounds of 'int16_t\\\[1]'" }
131 sink (p
[2]); // { dg-warning "subscript 2 is outside array bounds of 'int16_t\\\[1\\\]'" }
135 p
= alloca (UR (0, 3)); // { dg-message "at offset \\d+ into object of size \\\[0, 3] allocated by '__builtin_alloca'" "note" }
138 T (p
[1]); // { dg-warning "subscript 'int16_t {aka short int}\\\[1\\\]' is partly outside array bounds of 'unsigned char\\\[3]'" }
139 T (p
[2]); // { dg-warning "subscript 2 is outside array bounds of 'int16_t\\\[1\\\]'" }
140 T (p
[3]); // { dg-warning "subscript 3 is outside array bounds of 'int16_t\\\[1\\\]'" }
144 p
= alloca (UR (1, 3)); // { dg-message "at offset 1|2|3 into object of size \\\[1, 3] allocated by '__builtin_alloca'" "note" }
147 T (p
[1]); // { dg-warning "subscript 'int16_t {aka short int}\\\[1\\\]' is partly outside array bounds of 'unsigned char\\\[3]'" }
148 T (p
[2]); // { dg-warning "subscript 2 is outside array bounds of 'int16_t\\\[1\\\]'" }
149 T (p
[3]); // { dg-warning "subscript 3 is outside array bounds of 'int16_t\\\[1\\\]'" }
153 p
= alloca (UR (2, 3)); // { dg-message "at offset 2|4 into object of size \\\[2, 3] allocated by '__builtin_alloca'" "note" }
156 T (p
[1]); // { dg-warning "subscript 'int16_t {aka short int}\\\[1\\\]' is partly outside array bounds of 'unsigned char\\\[3]'" }
157 T (p
[2]); // { dg-warning "subscript 2 is outside array bounds of 'int16_t\\\[1\\\]'" }
158 T (p
[3]); // { dg-warning "subscript 3 is outside array bounds of 'int16_t\\\[1\\\]'" }
162 p
= alloca (UR (3, 4)); // { dg-message "at offset 4|6 into object of size \\\[3, 4] allocated by '__builtin_alloca'" "note" }
166 T (p
[2]); // { dg-warning "subscript 2 is outside array bounds of 'int16_t\\\[2\\\]'" }
167 T (p
[3]); // { dg-warning "subscript 3 is outside array bounds of 'int16_t\\\[2\\\]'" }
172 void test_vla_cst (void)
179 T (a
[1]); // { dg-warning "subscript 1 is (above|outside) array bounds " }
187 T (a
[2]); // { dg-warning "subscript 2 is (above|outside) array bounds " }
194 T (p
[0]), T (p
[1]), T (p
[2]);
195 T (p
[3]); // { dg-warning "subscript 3 is (above|outside) array bounds " }
200 void test_vla_char_range (int i
, unsigned n
, size_t sz
)
205 T (a
[0]), T (a
[1]), T (a
[12345]);
206 T (a
[-1]); // { dg-warning "subscript -1 is (below|outside) array bounds of 'char\\\[" }
212 T (a
[0]), T (a
[1]), T (a
[12345]);
213 T (a
[-1]); // { dg-warning "subscript -1 is (below|outside) array bounds of 'char\\\[" }
219 T (a
[0]), T (a
[1]), T (a
[23456]);
220 T (a
[-1]); // { dg-warning "subscript -1 is (below|outside) array bounds of 'char\\\[" }
227 T (a
[1]); // { dg-warning "subscript 1 is outside array bounds of 'char\\\[1\\\]'" "pr82608" { xfail *-*-* } }
234 sink (a
[2]); // { dg-warning "subscript 2 is outside array bounds of 'char\\\[2\\\]'" "pr82608" { xfail *-*-* } }
240 T (a
[0]), T (a
[1]), T (a
[2]);
241 T (a
[3]); // { dg-warning "subscript 3 is outside array bounds of 'char\\\[3\\\]'" "pr82608" { xfail *-*-* } }
247 T (a
[0]), T (a
[1]), T (a
[2]);
248 T (a
[3]); // { dg-warning "subscript 3 is outside array bounds of 'char\\\[3\\\]'" "pr82608" { xfail *-*-* } }
254 T (a
[0]), T (a
[1]), T (a
[2]);
255 T (a
[3]); // { dg-warning "subscript 3 is outside array bounds of 'char\\\[3\\\]'" "pr82608" { xfail *-*-* } }