Debian Codegraph @

gcc/testsuite/g++.dg/warn/Warray-bounds-24.C

raw
1 /* PR middle-end/99502 - missing -Warray-bounds on partial out of bounds
2 access in C++
3 { dg-do compile }
4 { dg-options "-O2 -Wall" } */
5
6 inline void* operator new (__SIZE_TYPE__, void *p) { return p; }
7
8 struct B0 { int b0i, b0a[0]; };
9 struct B1: virtual B0 { int b1i, b1a[0]; };
10 struct B2: virtual B0 { int b2i, b2a[0]; };
11 struct D1: B1, B2 { int d1i, d1a[0]; };
12 struct D2: D1 { int d2i, d2a[0]; };
13 struct D3: D2 { int d3i, d3a[0]; };
14
15 void sink (void*);
16
17
18 void test_D1 ()
19 {
20 {
21 char *p = new char[sizeof (D1)];
22 new (p) D1 ();
23 sink (p);
24 }
25
26 {
27 char *p = new char[sizeof (D1) - 1];
28 new (p) D1 (); // { dg-warning "-Warray-bounds" }
29 sink (p);
30 }
31 }
32
33 void test_D1_b0a ()
34 {
35 {
36 D1 *p = (D1*)new char[sizeof (D1)];
37 *p->b0a = __LINE__; // { dg-warning "-Warray-bounds" "pr99630" { xfail *-*-* } }
38 sink (p);
39 }
40
41 {
42 D1 *p = (D1*)new char[3];
43 *p->b0a = __LINE__; // { dg-warning "-Warray-bounds" }
44 sink (p);
45 }
46 }
47
48 void test_D1_b1a ()
49 {
50 {
51 D1 *p = (D1*)new char[sizeof (D1)];
52 *p->b1a = __LINE__; // { dg-warning "-Warray-bounds" }
53 sink (p);
54 }
55
56 {
57 D1 *p = (D1*)new char[3];
58 *p->b1a = __LINE__; // { dg-warning "-Warray-bounds" }
59 sink (p);
60 }
61 }
62
63 void test_D1_b2a ()
64 {
65 {
66 D1 *p = (D1*)new char[sizeof (D1)];
67 *p->b2a = __LINE__; // { dg-warning "-Warray-bounds" }
68 sink (p);
69 }
70
71 {
72 D1 *p = (D1*)new char[3];
73 *p->b2a = __LINE__; // { dg-warning "-Warray-bounds" }
74 sink (p);
75 }
76 }
77
78 void test_D1_d1a ()
79 {
80 {
81 D1 *p = (D1*)new char[sizeof (D1)];
82 *p->d1a = __LINE__; // { dg-warning "-Warray-bounds" }
83 sink (p);
84 }
85
86 {
87 D1 *p = (D1*)new char[3];
88 *p->d1a = __LINE__; // { dg-warning "-Warray-bounds" }
89 sink (p);
90 }
91 }
92
93
94 void test_D2 ()
95 {
96 {
97 char *p = new char[sizeof (D2)];
98 new (p) D2 ();
99 sink (p);
100 }
101
102 {
103 char *p = new char[sizeof (D2) - 1];
104 new (p) D2 (); // { dg-warning "-Warray-bounds" }
105 sink (p);
106 }
107 }
108
109 void test_D2_b0a ()
110 {
111 {
112 D2 *p = (D2*)new char[sizeof (D2)];
113 *p->b0a = __LINE__; // { dg-warning "-Warray-bounds" "pr99630" { xfail *-*-* } }
114 sink (p);
115 }
116
117 {
118 D2 *p = (D2*)new char[3];
119 *p->b0a = __LINE__; // { dg-warning "-Warray-bounds" }
120 sink (p);
121 }
122 }
123
124 void test_D2_b1a ()
125 {
126 {
127 D2 *p = (D2*)new char[sizeof (D2)];
128 *p->b1a = __LINE__; // { dg-warning "-Warray-bounds" }
129 sink (p);
130 }
131
132 {
133 D2 *p = (D2*)new char[3];
134 *p->b1a = __LINE__; // { dg-warning "-Warray-bounds" }
135 sink (p);
136 }
137 }
138
139 void test_D2_b2a ()
140 {
141 {
142 D2 *p = (D2*)new char[sizeof (D2)];
143 *p->b2a = __LINE__; // { dg-warning "-Warray-bounds" }
144 sink (p);
145 }
146
147 {
148 D2 *p = (D2*)new char[3];
149 *p->b2a = __LINE__; // { dg-warning "-Warray-bounds" }
150 sink (p);
151 }
152 }
153
154 void test_D2_d1a ()
155 {
156 {
157 D2 *p = (D2*)new char[sizeof (D2)];
158 *p->d1a = __LINE__; // { dg-warning "-Warray-bounds" }
159 sink (p);
160 }
161
162 {
163 D2 *p = (D2*)new char[3];
164 *p->d1a = __LINE__; // { dg-warning "-Warray-bounds" }
165 sink (p);
166 }
167 }
168
169 void test_D2_d2a ()
170 {
171 {
172 D2 *p = (D2*)new char[sizeof (D2)];
173 *p->d2a = __LINE__; // { dg-warning "-Warray-bounds" }
174 sink (p);
175 }
176
177 {
178 D2 *p = (D2*)new char[3];
179 *p->d2a = __LINE__; // { dg-warning "-Warray-bounds" }
180 sink (p);
181 }
182 }
183
184
185 void test_D3 ()
186 {
187 {
188 char *p = new char[sizeof (D3)];
189 new (p) D3 ();
190 sink (p);
191 }
192
193 {
194 char *p = new char[sizeof (D3) - 1];
195 new (p) D3 (); // { dg-warning "-Warray-bounds" }
196 sink (p);
197 }
198 }
199
200 void test_D3_b0a ()
201 {
202 {
203 D3 *p = (D3*)new char[sizeof (D3)];
204 *p->b0a = __LINE__; // { dg-warning "-Warray-bounds" "pr99630" { xfail *-*-* } }
205 sink (p);
206 }
207
208 {
209 D3 *p = (D3*)new char[3];
210 *p->b0a = __LINE__; // { dg-warning "-Warray-bounds" }
211 sink (p);
212 }
213 }
214
215 void test_D3_b1a ()
216 {
217 {
218 D3 *p = (D3*)new char[sizeof (D3)];
219 *p->b1a = __LINE__; // { dg-warning "-Warray-bounds" }
220 sink (p);
221 }
222
223 {
224 D3 *p = (D3*)new char[3];
225 *p->b1a = __LINE__; // { dg-warning "-Warray-bounds" }
226 sink (p);
227 }
228 }
229
230 void test_D3_b2a ()
231 {
232 {
233 D3 *p = (D3*)new char[sizeof (D3)];
234 *p->b2a = __LINE__; // { dg-warning "-Warray-bounds" }
235 sink (p);
236 }
237
238 {
239 D3 *p = (D3*)new char[3];
240 *p->b2a = __LINE__; // { dg-warning "-Warray-bounds" }
241 sink (p);
242 }
243 }
244
245 void test_D3_d1a ()
246 {
247 {
248 D3 *p = (D3*)new char[sizeof (D3)];
249 *p->d1a = __LINE__; // { dg-warning "-Warray-bounds" }
250 sink (p);
251 }
252
253 {
254 D3 *p = (D3*)new char[3];
255 *p->d1a = __LINE__; // { dg-warning "-Warray-bounds" }
256 sink (p);
257 }
258 }
259
260 void test_D3_d2a ()
261 {
262 {
263 D3 *p = (D3*)new char[sizeof (D3)];
264 *p->d2a = __LINE__; // { dg-warning "-Warray-bounds" }
265 sink (p);
266 }
267
268 {
269 D3 *p = (D3*)new char[3];
270 *p->d2a = __LINE__; // { dg-warning "-Warray-bounds" }
271 sink (p);
272 }
273 }
274
275 void test_D3_d3a ()
276 {
277 {
278 D3 *p = (D3*)new char[sizeof (D3)];
279 *p->d3a = __LINE__; // { dg-warning "-Warray-bounds" }
280 sink (p);
281 }
282
283 {
284 D3 *p = (D3*)new char[3];
285 *p->d3a = __LINE__; // { dg-warning "-Warray-bounds" }
286 sink (p);
287 }
288 }
289