1 /* PR tree-optimization/99475 - bogus -Warray-bounds accessing an array
2 element of empty structs
4 { dg-options "-O2 -Wall" } */
9 /* Suppose the contents are empty in the development configuration
10 but non-empty in others. Out of bounds accesses to elements of
11 the arrays below should be diagnosed in all configurations,
12 including when S is empty, even if they are folded away. */
17 extern struct S sa3
[3];
18 extern struct S sa2_3
[2][3];
19 extern struct S sa3_4_5
[3][4][5];
24 void access_sa3 (void)
26 sa3
[0] = (struct S
){ };
27 sa3
[1] = (struct S
){ };
28 sa3
[2] = (struct S
){ };
29 sa3
[3] = (struct S
){ }; // { dg-warning "\\\[-Warray-bounds" "pr?????" { xfail *-*-* } }
32 void access_sa3_ptr (void)
34 struct S
*p
= &sa3
[0];
36 p
[0] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
37 p
[1] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
38 p
[2] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
39 p
[3] = (struct S
){ }; // { dg-warning "\\\[-Warray-bounds" "pr?????" { xfail *-*-* } }
42 void access_sa2_3_ptr (void)
44 struct S
*p
= &sa2_3
[0][0];
46 p
[0] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
47 p
[1] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
48 p
[2] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
49 p
[6] = (struct S
){ }; // { dg-warning "\\\[-Warray-bounds" "pr?????" { xfail *-*-* } }
52 void access_sa3_4_5_ptr (struct S s
, int i
)
54 struct S
*p
= &sa3_4_5
[0][0][0];
56 p
[0] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
57 p
[1] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
58 p
[2] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
59 p
[60] = (struct S
){ }; // { dg-warning "\\\[-Warray-bounds" "pr?????" { xfail *-*-* } }
63 void access_vla3 (struct S s
, unsigned n
)
65 struct S vla3
[3 < n
? 3 : n
];
67 vla3
[0] = (struct S
){ };
68 vla3
[1] = (struct S
){ };
69 vla3
[2] = (struct S
){ };
70 vla3
[3] = (struct S
){ }; // { dg-warning "\\\[-Warray-bounds" "pr?????" { xfail *-*-* } }
75 void access_vla3_ptr (struct S s
, unsigned n
)
77 struct S vla3
[3 < n
? 3 : n
];
78 struct S
*p
= &vla3
[0];
80 p
[0] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
81 p
[1] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
82 p
[2] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
83 p
[3] = (struct S
){ }; // { dg-warning "\\\[-Warray-bounds" "pr?????" { xfail *-*-* } }
88 void access_vla2_3_ptr (struct S s
, unsigned n
)
90 struct S vla2_3
[2 < n
? 2 : n
][3 < n
? 3 : n
];
91 struct S
*p
= &vla2_3
[0][0];
93 p
[0] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
94 p
[1] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
95 p
[2] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
96 p
[6] = (struct S
){ }; // { dg-warning "\\\[-Warray-bounds" "pr?????" { xfail *-*-* } }
101 void access_vla3_4_5_ptr (struct S s
, unsigned n
)
103 struct S vla3_4_5
[3 < n
? 3 : n
][4 < n
? 4 : n
][5 < n
? 5 : n
];
104 struct S
*p
= &vla3_4_5
[0][0][0];
106 p
[0] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
107 p
[1] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
108 p
[2] = (struct S
){ }; // { dg-bogus "\\\[-Warray-bounds" }
109 p
[60] = (struct S
){ }; // { dg-warning "\\\[-Warray-bounds" "pr?????" { xfail *-*-* } }