1 /* PR middle-end/92333 - missing variable name referencing VLA in warnings
2 PR middle-end/82608 - missing -Warray-bounds on an out-of-bounds VLA index
3 { dg-do compile }
4 { dg-options "-O2 -Wall" }
5 { dg-additional-options "-mtune=generic" { target { i?86-*-* x86_64-*-* } } } */
6
7 void sink (void*);
8
9 void test_char_vla_location (void)
10 {
11 unsigned nelts = 7;
12
13 char vla[nelts]; // { dg-message "declared here|while referencing" }
14
15 vla[0] = __LINE__;
16 vla[nelts] = 0; // { dg-warning "\\\[-Warray-bounds" }
17
18 sink (vla);
19 }
20
21 void test_int_vla_location (void)
22 {
23 unsigned nelts = 7;
24
25 int vla[nelts]; // { dg-message "declared here|while referencing" }
26
27 vla[0] = __LINE__;
28 vla[nelts] = 1; // { dg-warning "\\\[-Warray-bounds" }
29
30 sink (vla);
31 }
32
33 void test_struct_char_vla_location (void)
34 {
35 unsigned nelts = 7;
36
37 struct {
38 char cvla[nelts]; // { dg-message "declared here|while referencing" }
39 } s;
40
41 s.cvla[0] = __LINE__;
42 s.cvla[nelts - 1] = 0; // { dg-warning "\\\[-Wstringop-overflow" "pr102706" { target { vect_slp_v2qi_store_align } } }
43 s.cvla[nelts] = 0; // { dg-warning "\\\[-Warray-bounds" }
44
45 sink (&s);
46 }
47
48
49 void test_struct_int_vla_location (void)
50 {
51 unsigned nelts = 7;
52
53 struct {
54 int ivla[nelts]; // { dg-message "declared here|while referencing" }
55 } s;
56
57 s.ivla[0] = __LINE__;
58 s.ivla[nelts - 1] = 0;
59 s.ivla[nelts] = 0; // { dg-warning "\\\[-Warray-bounds" }
60
61 sink (&s);
62 }