Corrected date in changelog
[official-gcc.git] / gcc / testsuite / gcc.dg / builtin-object-size-13.c
blob80a6280e3f9df962004774d990d3f1bc2a2f7d8d
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
4 typedef __SIZE_TYPE__ size_t;
5 extern void *malloc (size_t);
6 extern void free (void *);
7 extern void abort (void);
9 union A
11 int a1;
12 char a2[3];
15 union B
17 long long b1;
18 union A b2;
21 struct C
23 int c1;
24 union A c2;
27 struct D
29 int d1;
30 union B d2;
33 union E
35 struct C e1;
36 char e2[3];
39 union F
41 int f1;
42 struct D f2;
45 struct G
47 union A g1;
48 char g2;
51 struct H
53 int h1;
54 union E h2;
57 #define T(X, S0, S1) \
58 if (__builtin_object_size (X, 0) != (S0)) \
59 abort (); \
60 if (__builtin_object_size (X, 1) != (S1)) \
61 abort (); \
62 if (__builtin_object_size (X, 2) != (S0)) \
63 abort (); \
64 if (__builtin_object_size (X, 3) != (S1)) \
65 abort ()
66 #define TS(X, S0) T(&X, S0, sizeof (X))
67 #define TA(X, S0, S1) \
68 T(X, S0, S1); T(&X[0], S0, S1); T(&X[1], (S0) - 1, (S1) - 1)
69 #define TF(X, S0) TA(X, S0, S0)
71 int
72 main (void)
74 size_t s, o, o2;
76 s = sizeof (union A);
77 o = 0;
78 union A *a1 = malloc (s);
79 union A *a2 = malloc (o + 212);
80 TS (a1->a1, s);
81 s = o + 212;
82 TS (a2->a1, s);
83 free (a2);
84 free (a1);
85 s = sizeof (union A);
86 o = 0;
87 a1 = malloc (s);
88 a2 = malloc (o + 212);
89 TF (a1->a2, s);
90 s = o + 212;
91 TF (a2->a2, s);
92 free (a2);
93 free (a1);
95 s = sizeof (union B);
96 o = 0;
97 union B *b1 = malloc (s);
98 union B *b2 = malloc (o + 212);
99 TS (b1->b1, s);
100 s = o + 212;
101 TS (b2->b1, s);
102 free (b2);
103 free (b1);
104 s = sizeof (union B);
105 o = 0;
106 b1 = malloc (s);
107 b2 = malloc (o + 212);
108 TS (b1->b2.a1, s);
109 s = o + 212;
110 TS (b2->b2.a1, s);
111 free (b2);
112 free (b1);
113 s = sizeof (union B);
114 o = 0;
115 b1 = malloc (s);
116 b2 = malloc (o + 212);
117 TF (b1->b2.a2, s);
118 s = o + 212;
119 TF (b2->b2.a2, s);
120 free (b2);
121 free (b1);
123 s = sizeof (struct C);
124 o = __builtin_offsetof (struct C, c2);
125 struct C *c1 = malloc (s);
126 struct C *c2 = malloc (o + 212);
127 TS (c1->c1, s);
128 s = o + 212;
129 TS (c2->c1, s);
130 free (c2);
131 free (c1);
132 s = sizeof (struct C);
133 o = __builtin_offsetof (struct C, c2);
134 c1 = malloc (s);
135 c2 = malloc (o + 212);
136 TS (c1->c2.a1, s - o);
137 s = o + 212;
138 TS (c2->c2.a1, s - o);
139 free (c2);
140 free (c1);
141 s = sizeof (struct C);
142 o = __builtin_offsetof (struct C, c2);
143 c1 = malloc (s);
144 c2 = malloc (o + 212);
145 TF (c1->c2.a2, s - o);
146 s = o + 212;
147 TF (c2->c2.a2, s - o);
148 free (c2);
149 free (c1);
151 s = sizeof (struct D);
152 o = __builtin_offsetof (struct D, d2);
153 struct D *d1 = malloc (s);
154 struct D *d2 = malloc (o + 212);
155 TS (d1->d1, s);
156 s = o + 212;
157 TS (d2->d1, s);
158 free (d2);
159 free (d1);
160 s = sizeof (struct D);
161 o = __builtin_offsetof (struct D, d2);
162 d1 = malloc (s);
163 d2 = malloc (o + 212);
164 TS (d1->d2.b1, s - o);
165 s = o + 212;
166 TS (d2->d2.b1, s - o);
167 free (d2);
168 free (d1);
169 s = sizeof (struct D);
170 o = __builtin_offsetof (struct D, d2);
171 d1 = malloc (s);
172 d2 = malloc (o + 212);
173 TS (d1->d2.b2.a1, s - o);
174 s = o + 212;
175 TS (d2->d2.b2.a1, s - o);
176 free (d2);
177 free (d1);
178 s = sizeof (struct D);
179 o = __builtin_offsetof (struct D, d2);
180 d1 = malloc (s);
181 d2 = malloc (o + 212);
182 TF (d1->d2.b2.a2, s - o);
183 s = o + 212;
184 TF (d2->d2.b2.a2, s - o);
185 free (d2);
186 free (d1);
188 s = sizeof (union E);
189 o = __builtin_offsetof (union E, e1.c2);
190 union E *e1 = malloc (s);
191 union E *e2 = malloc (o + 212);
192 TS (e1->e1.c1, s);
193 s = o + 212;
194 TS (e2->e1.c1, s);
195 free (e2);
196 free (e1);
197 s = sizeof (union E);
198 o = __builtin_offsetof (union E, e1.c2);
199 e1 = malloc (s);
200 e2 = malloc (o + 212);
201 TS (e1->e1.c2.a1, s - o);
202 s = o + 212;
203 TS (e2->e1.c2.a1, s - o);
204 free (e2);
205 free (e1);
206 s = sizeof (union E);
207 o = __builtin_offsetof (union E, e1.c2);
208 e1 = malloc (s);
209 e2 = malloc (o + 212);
210 TF (e1->e1.c2.a2, s - o);
211 s = o + 212;
212 TF (e2->e1.c2.a2, s - o);
213 free (e2);
214 free (e1);
215 s = sizeof (union E);
216 o = __builtin_offsetof (union E, e1.c2);
217 e1 = malloc (s);
218 e2 = malloc (o + 212);
219 TF (e1->e2, s);
220 s = o + 212;
221 TF (e2->e2, s);
222 free (e2);
223 free (e1);
225 s = sizeof (union F);
226 o = __builtin_offsetof (union F, f2.d2);
227 union F *f1 = malloc (s);
228 union F *f2 = malloc (o + 212);
229 TS (f1->f1, s);
230 s = o + 212;
231 TS (f2->f1, s);
232 free (f2);
233 free (f1);
234 s = sizeof (union F);
235 o = __builtin_offsetof (union F, f2.d2);
236 f1 = malloc (s);
237 f2 = malloc (o + 212);
238 TS (f1->f2.d1, s);
239 s = o + 212;
240 TS (f2->f2.d1, s);
241 free (f2);
242 free (f1);
243 s = sizeof (union F);
244 o = __builtin_offsetof (union F, f2.d2);
245 f1 = malloc (s);
246 f2 = malloc (o + 212);
247 TS (f1->f2.d2.b1, s - o);
248 s = o + 212;
249 TS (f2->f2.d2.b1, s - o);
250 free (f2);
251 free (f1);
252 s = sizeof (union F);
253 o = __builtin_offsetof (union F, f2.d2);
254 f1 = malloc (s);
255 f2 = malloc (o + 212);
256 TS (f1->f2.d2.b2.a1, s - o);
257 s = o + 212;
258 TS (f2->f2.d2.b2.a1, s - o);
259 free (f2);
260 free (f1);
261 s = sizeof (union F);
262 o = __builtin_offsetof (union F, f2.d2);
263 f1 = malloc (s);
264 f2 = malloc (o + 212);
265 TF (f1->f2.d2.b2.a2, s - o);
266 s = o + 212;
267 TF (f2->f2.d2.b2.a2, s - o);
268 free (f2);
269 free (f1);
271 s = sizeof (struct G);
272 o = __builtin_offsetof (struct G, g2);
273 struct G *g1 = malloc (s);
274 struct G *g2 = malloc (o + 212);
275 TS (g1->g1.a1, s);
276 s = o + 212;
277 TS (g2->g1.a1, s);
278 free (g2);
279 free (g1);
280 s = sizeof (struct G);
281 o = __builtin_offsetof (struct G, g2);
282 g1 = malloc (s);
283 g2 = malloc (o + 212);
284 TA (g1->g1.a2, s, sizeof (g1->g1.a2));
285 s = o + 212;
286 TA (g2->g1.a2, s, sizeof (g1->g1.a2));
287 free (g2);
288 free (g1);
289 s = sizeof (struct G);
290 o = __builtin_offsetof (struct G, g2);
291 g1 = malloc (s);
292 g2 = malloc (o + 212);
293 TS (g1->g2, s - o);
294 s = o + 212;
295 TS (g2->g2, s - o);
296 free (g2);
297 free (g1);
299 s = sizeof (struct H);
300 o = __builtin_offsetof (struct H, h2);
301 o2 = __builtin_offsetof (struct H, h2.e1.c2);
302 struct H *h1 = malloc (s);
303 struct H *h2 = malloc (o2 + 212);
304 TS (h1->h1, s);
305 s = o2 + 212;
306 TS (h2->h1, s);
307 free (h2);
308 free (h1);
309 s = sizeof (struct H);
310 o = __builtin_offsetof (struct H, h2);
311 o2 = __builtin_offsetof (struct H, h2.e1.c2);
312 h1 = malloc (s);
313 h2 = malloc (o2 + 212);
314 TS (h1->h2.e1.c1, s - o);
315 s = o2 + 212;
316 TS (h2->h2.e1.c1, s - o);
317 free (h2);
318 free (h1);
319 s = sizeof (struct H);
320 o = __builtin_offsetof (struct H, h2);
321 o2 = __builtin_offsetof (struct H, h2.e1.c2);
322 h1 = malloc (s);
323 h2 = malloc (o2 + 212);
324 TS (h1->h2.e1.c2.a1, s - o2);
325 s = o2 + 212;
326 TS (h2->h2.e1.c2.a1, s - o2);
327 free (h2);
328 free (h1);
329 s = sizeof (struct H);
330 o = __builtin_offsetof (struct H, h2);
331 o2 = __builtin_offsetof (struct H, h2.e1.c2);
332 h1 = malloc (s);
333 h2 = malloc (o2 + 212);
334 TA (h1->h2.e1.c2.a2, s - o2, sizeof (h1->h2.e1.c2.a2));
335 s = o2 + 212;
336 TA (h2->h2.e1.c2.a2, s - o2, sizeof (h2->h2.e1.c2.a2));
337 free (h2);
338 free (h1);
339 s = sizeof (struct H);
340 o = __builtin_offsetof (struct H, h2);
341 o2 = __builtin_offsetof (struct H, h2.e1.c2);
342 h1 = malloc (s);
343 h2 = malloc (o2 + 212);
344 TF (h1->h2.e2, s - o);
345 s = o2 + 212;
346 TF (h2->h2.e2, s - o);
347 free (h2);
348 free (h1);
350 return 0;