Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / gcc.dg / Warray-bounds-78.c
blob73c335fd8a6bac83e2c9aa6c70894c1d429bd511
1 /* PR tree-optimization/99475 - bogus -Warray-bounds accessing an array
2 element of empty structs
3 { dg-do compile }
4 { dg-options "-O2 -Wall -Wno-strict-aliasing" } */
6 typedef _Bool bool;
8 #define NOIPA __attribute__ ((noipa))
10 struct S { };
12 extern struct S sa3[3];
13 extern struct S sa2_3[2][3];
14 extern struct S sa3_4_5[3][4][5];
16 void sink (void*);
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" }
67 sink (vla3);
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" }
80 sink (vla3);
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" }
93 sink (vla2_3);
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" }
106 sink (vla3_4_5);
109 // { dg-prune-output "empty struct has size 0 in C" }