1 /* PR middle-end/94940 - spurious -Warray-bounds for a zero length array
4 { dg-options "-O2 -Wall" } */
10 int a2
[2]; // can only alias a3[0 - 2]
11 int a1
[1]; // can alias all of the union
15 void test_ua3_ua0_a0 (int i
)
17 ua3_a0
.a0
[0] = 0; // { dg-bogus "\\\[-Warray-bounds" }
18 ua3_a0
.a0
[1] = 0; // { dg-bogus "\\\[-Warray-bounds" }
19 ua3_a0
.a0
[2] = 0; // { dg-bogus "\\\[-Warray-bounds" }
20 ua3_a0
.a0
[3] = 0; // { dg-warning "\\\[-Warray-bounds" }
21 ua3_a0
.a0
[4] = 0; // { dg-warning "\\\[-Warray-bounds" }
22 ua3_a0
.a0
[i
] = 0; // { dg-bogus "\\\[-Warray-bounds" }
26 ua3_a0
.a0
[i
] = 0; // { dg-warning "\\\[-Warray-bounds" }
30 ua3_a0
.a0
[i
] = 0; // { dg-warning "\\\[-Warray-bounds" }
33 void test_ua3_ua0_a1 (int i
)
35 /* Abusing one-element array members the same way as those of
36 length zero is discouraged but so far acceted without warnings.
37 This should change at some point. */
42 ua3_a0
.a1
[3] = 0; // { dg-warning "\\\[-Warray-bounds" }
47 ua3_a0
.a1
[i
] = 0; // { dg-warning "\\\[-Warray-bounds" }
51 ua3_a0
.a1
[i
] = 0; // { dg-warning "\\\[-Warray-bounds" }
54 void test_ua3_ua0_a2 (int i
)
58 ua3_a0
.a2
[2] = 0; // { dg-warning "\\\[-Warray-bounds" }
63 ua3_a0
.a2
[i
] = 0; // { dg-warning "\\\[-Warray-bounds" }
67 ua3_a0
.a2
[i
] = 0; // { dg-warning "\\\[-Warray-bounds" }
72 int a2
[2]; // can only alias a3[0 - 1]
76 void test_ua2_ua3 (int i
)
78 ua2_a3
.a2
[0] = 0; // { dg-bogus "\\\[-Warray-bounds" }
79 ua2_a3
.a2
[1] = 0; // { dg-bogus "\\\[-Warray-bounds" }
80 ua2_a3
.a2
[2] = 0; // { dg-warning "\\\[-Warray-bounds" }
85 ua2_a3
.a2
[i
] = 0; // { dg-warning "\\\[-Warray-bounds" }
89 extern struct SUa2_a0
{
96 void test_sua2_sua0 (int i
)
100 n
+= sua2_a0
.u
.a0
[2]; // { dg-warning "\\\[-Warray-bounds" }
101 n
+= sua2_a0
.u
.a0
[i
];
105 n
+= sua2_a0
.u
.a0
[i
]; // { dg-warning "\\\[-Warray-bounds" }
108 void test_sua2_sua0_ptr (int i
)
110 union Ua2_a0
*p
= &sua2_a0
.u
;
114 n
+= p
->a0
[2]; // { dg-warning "\\\[-Warray-bounds" }
119 extern struct SUSa3_a0
{
124 int a2
[2]; // can alias s.a3[0 - 2]
125 int a1
[1]; // can alias s.a3[0 - 2]
126 int a0
[0]; // can alias s.a3[0]
130 void test_susa3_sua0 (int i
, int j
)
132 n
+= susa3_ua0
.u
.a0
[0];
133 n
+= susa3_ua0
.u
.a0
[1];
134 n
+= susa3_ua0
.u
.a0
[2];
135 n
+= susa3_ua0
.u
.a0
[3]; // { dg-warning "\\\[-Warray-bounds" }
138 void test_susa3_sua0_ptr (int i
, int j
)
140 union USa3_a0
*p
= &susa3_ua0
.u
;
144 n
+= p
->a0
[3]; // { dg-warning "\\\[-Warray-bounds" }
147 void test_susa3_sua1 (int i
)
149 n
+= susa3_ua0
.u
.a1
[0];
150 n
+= susa3_ua0
.u
.a1
[1];
151 n
+= susa3_ua0
.u
.a1
[2];
152 n
+= susa3_ua0
.u
.a1
[3]; // { dg-warning "\\\[-Warray-bounds" }
156 n
+= susa3_ua0
.u
.a1
[i
]; // { dg-warning "\\\[-Warray-bounds" }
159 void test_susa3_sua2 (void)
161 n
+= susa3_ua0
.u
.a2
[0];
162 n
+= susa3_ua0
.u
.a2
[1];
163 n
+= susa3_ua0
.u
.a2
[2]; // { dg-warning "\\\[-Warray-bounds" }
164 n
+= susa3_ua0
.u
.a2
[3]; // { dg-warning "\\\[-Warray-bounds" }
179 void test_susi3_susi0 (int i
)
181 n
+= susa3_usa0
.u
.s2
.a0
[0];
182 n
+= susa3_usa0
.u
.s2
.a0
[1];
183 n
+= susa3_usa0
.u
.s2
.a0
[2];
184 n
+= susa3_usa0
.u
.s2
.a0
[3]; // { dg-warning "\\\[-Warray-bounds" }
185 n
+= susa3_usa0
.u
.s2
.a0
[i
];
189 n
+= susa3_usa0
.u
.s2
.a0
[i
]; // { dg-warning "\\\[-Warray-bounds" }