1 /* PR tree-optimization/99475 - bogus -Warray-bounds accessing an array
2 element of empty structs
4 { dg-options "-O2 -Wall -Wno-strict-aliasing" } */
8 #define NOIPA __attribute__ ((noipa))
12 extern struct S sa3
[3];
13 extern struct S sa2_3
[2][3];
14 extern struct S sa3_4_5
[3][4][5];
19 NOIPA
void access_sa3 (void)
21 ((bool*)sa3
)[0] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
22 ((bool*)sa3
)[1] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
23 ((bool*)sa3
)[2] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
24 ((bool*)sa3
)[3] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
27 NOIPA
void access_sa3_ptr (void)
29 bool *p
= (bool*)&sa3
[0];
31 p
[0] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
32 p
[1] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
33 p
[2] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
34 p
[3] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
37 NOIPA
void access_sa2_3_ptr (void)
39 bool *p
= (bool*)&sa2_3
[0][0];
41 p
[0] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
42 p
[1] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
43 p
[2] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
44 p
[6] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
47 NOIPA
void access_sa3_4_5_ptr (struct S s
, int i
)
49 bool *p
= (bool*)&sa3_4_5
[0][0][0];
51 p
[0] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
52 p
[1] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
53 p
[2] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
54 p
[60] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
58 NOIPA
void access_vla3 (struct S s
, unsigned n
)
60 struct S vla3
[3 < n
? 3 : n
];
62 ((bool*)vla3
)[0] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
63 ((bool*)vla3
)[1] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
64 ((bool*)vla3
)[2] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
65 ((bool*)vla3
)[3] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
70 NOIPA
void access_vla3_ptr (struct S s
, unsigned n
)
72 struct S vla3
[3 < n
? 3 : n
];
73 bool *p
= (bool*)&vla3
[0];
75 p
[0] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
76 p
[1] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
77 p
[2] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
78 p
[3] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
83 NOIPA
void access_vla2_3_ptr (struct S s
, unsigned n
)
85 struct S vla2_3
[2 < n
? 2 : n
][3 < n
? 3 : n
];
86 bool *p
= (bool*)&vla2_3
[0][0];
88 p
[0] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
89 p
[1] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
90 p
[2] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
91 p
[6] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
96 NOIPA
void access_vla3_4_5_ptr (struct S s
, unsigned n
)
98 struct S vla3_4_5
[3 < n
? 3 : n
][4 < n
? 4 : n
][5 < n
? 5 : n
];
99 bool *p
= (bool*)&vla3_4_5
[0][0][0];
101 p
[0] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
102 p
[1] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
103 p
[2] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
104 p
[60] = __LINE__
; // { dg-warning "\\\[-Warray-bounds" }
109 // { dg-prune-output "empty struct has size 0 in C" }