annotate gcc/testsuite/gcc.dg/Warray-bounds-61.c @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 /* PR middle-end/94940 - spurious -Warray-bounds for a zero length array
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
2 member of union
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
3 { dg-do compile }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
4 { dg-options "-O2 -Wall" } */
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
5
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
6 extern int n;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
7
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
8 extern union Ua3_a0 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
9 int a3[3];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
10 int a2[2]; // can only alias a3[0 - 2]
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
11 int a1[1]; // can alias all of the union
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
12 int a0[0]; // ditto
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
13 } ua3_a0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
14
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
15 void test_ua3_ua0_a0 (int i)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
16 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
17 ua3_a0.a0[0] = 0; // { dg-bogus "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
18 ua3_a0.a0[1] = 0; // { dg-bogus "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19 ua3_a0.a0[2] = 0; // { dg-bogus "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20 ua3_a0.a0[3] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21 ua3_a0.a0[4] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22 ua3_a0.a0[i] = 0; // { dg-bogus "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24 if (i < __LINE__)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25 i = 5;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 ua3_a0.a0[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 if (i > -1)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29 i = -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 ua3_a0.a0[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 void test_ua3_ua0_a1 (int i)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 /* Abusing one-element array members the same way as those of
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36 length zero is discouraged but so far acceted without warnings.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 This should change at some point. */
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 ua3_a0.a1[0] = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40 ua3_a0.a1[1] = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 ua3_a0.a1[2] = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42 ua3_a0.a1[3] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43 ua3_a0.a1[i] = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45 if (i > -1)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46 i = -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 ua3_a0.a1[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49 if (i < 7)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50 i = 7;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51 ua3_a0.a1[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54 void test_ua3_ua0_a2 (int i)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 ua3_a0.a2[0] = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 ua3_a0.a2[1] = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58 ua3_a0.a2[2] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59 ua3_a0.a2[i] = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 if (i < __LINE__)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 i = __LINE__;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63 ua3_a0.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65 if (i > -1)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66 i = -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 ua3_a0.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71 extern union Ua2_a3 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72 int a2[2]; // can only alias a3[0 - 1]
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73 int a3[3];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 } ua2_a3;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76 void test_ua2_ua3 (int i)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78 ua2_a3.a2[0] = 0; // { dg-bogus "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
79 ua2_a3.a2[1] = 0; // { dg-bogus "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
80 ua2_a3.a2[2] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
81 ua2_a3.a2[i] = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
82
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
83 if (i < __LINE__)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
84 i = __LINE__;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
85 ua2_a3.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
86 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
87
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
88
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
89 extern struct SUa2_a0 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
90 union Ua2_a0 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
91 int a2[2];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
92 int a0[0];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
93 } u;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
94 } sua2_a0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
95
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
96 void test_sua2_sua0 (int i)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
97 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
98 n += sua2_a0.u.a0[0];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
99 n += sua2_a0.u.a0[1];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
100 n += sua2_a0.u.a0[2]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
101 n += sua2_a0.u.a0[i];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
102
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
103 if (i < __LINE__)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
104 i = __LINE__;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
105 n += sua2_a0.u.a0[i]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
106 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
107
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
108 void test_sua2_sua0_ptr (int i)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
109 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
110 union Ua2_a0 *p = &sua2_a0.u;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
111
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
112 n += p->a0[0];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
113 n += p->a0[1];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
114 n += p->a0[2]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
115 n += p->a0[i];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
116 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
117
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
118
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
119 extern struct SUSa3_a0 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
120 union USa3_a0 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
121 struct {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
122 int a3[3];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
123 } s;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
124 int a2[2]; // can alias s.a3[0 - 2]
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
125 int a1[1]; // can alias s.a3[0 - 2]
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
126 int a0[0]; // can alias s.a3[0]
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
127 } u;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
128 } susa3_ua0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
129
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
130 void test_susa3_sua0 (int i, int j)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
131 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
132 n += susa3_ua0.u.a0[0];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
133 n += susa3_ua0.u.a0[1];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
134 n += susa3_ua0.u.a0[2];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
135 n += susa3_ua0.u.a0[3]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
136 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
137
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
138 void test_susa3_sua0_ptr (int i, int j)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
139 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
140 union USa3_a0 *p = &susa3_ua0.u;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
141 n += p->a0[0];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
142 n += p->a0[1];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
143 n += p->a0[2];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
144 n += p->a0[3]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
145 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
146
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
147 void test_susa3_sua1 (int i)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
148 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
149 n += susa3_ua0.u.a1[0];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
150 n += susa3_ua0.u.a1[1];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
151 n += susa3_ua0.u.a1[2];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
152 n += susa3_ua0.u.a1[3]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
153
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
154 if (i < __LINE__)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
155 i = __LINE__;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
156 n += susa3_ua0.u.a1[i]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
157 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
158
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
159 void test_susa3_sua2 (void)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
160 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
161 n += susa3_ua0.u.a2[0];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
162 n += susa3_ua0.u.a2[1];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
163 n += susa3_ua0.u.a2[2]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
164 n += susa3_ua0.u.a2[3]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
165 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
166
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
167
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
168 extern struct {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
169 union {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
170 struct {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
171 int a3[3];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
172 } s1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
173 struct {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
174 int a0[0];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
175 } s2;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
176 } u;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
177 } susa3_usa0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
178
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
179 void test_susi3_susi0 (int i)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
180 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
181 n += susa3_usa0.u.s2.a0[0];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
182 n += susa3_usa0.u.s2.a0[1];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
183 n += susa3_usa0.u.s2.a0[2];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
184 n += susa3_usa0.u.s2.a0[3]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
185 n += susa3_usa0.u.s2.a0[i];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
186
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
187 if (i < __LINE__)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
188 i = __LINE__;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
189 n += susa3_usa0.u.s2.a0[i]; // { dg-warning "\\\[-Warray-bounds" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
190 }