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);
57 #define T(X, S0, S1) \
58 if (__builtin_object_size (X, 0) != (S0)) \
60 if (__builtin_object_size (X, 1) != (S1)) \
62 if (__builtin_object_size (X, 2) != (S0)) \
64 if (__builtin_object_size (X, 3) != (S1)) \
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)
78 union A
*a1
= malloc (s
);
79 union A
*a2
= malloc (o
+ 212);
90 union B
*b1
= malloc (s
);
91 union B
*b2
= malloc (o
+ 212);
102 s
= sizeof (struct C
);
103 o
= __builtin_offsetof (struct C
, c2
);
104 struct C
*c1
= malloc (s
);
105 struct C
*c2
= malloc (o
+ 212);
107 TS (c1
->c2
.a1
, s
- o
);
108 TF (c1
->c2
.a2
, s
- o
);
111 TS (c2
->c2
.a1
, s
- o
);
112 TF (c2
->c2
.a2
, s
- o
);
116 s
= sizeof (struct D
);
117 o
= __builtin_offsetof (struct D
, d2
);
118 struct D
*d1
= malloc (s
);
119 struct D
*d2
= malloc (o
+ 212);
121 TS (d1
->d2
.b1
, s
- o
);
122 TS (d1
->d2
.b2
.a1
, s
- o
);
123 TF (d1
->d2
.b2
.a2
, s
- o
);
126 TS (d2
->d2
.b1
, s
- o
);
127 TS (d2
->d2
.b2
.a1
, s
- o
);
128 TF (d2
->d2
.b2
.a2
, s
- o
);
132 s
= sizeof (union E
);
133 o
= __builtin_offsetof (union E
, e1
.c2
);
134 union E
*e1
= malloc (s
);
135 union E
*e2
= malloc (o
+ 212);
137 TS (e1
->e1
.c2
.a1
, s
- o
);
138 TF (e1
->e1
.c2
.a2
, s
- o
);
142 TS (e2
->e1
.c2
.a1
, s
- o
);
143 TF (e2
->e1
.c2
.a2
, s
- o
);
148 s
= sizeof (union F
);
149 o
= __builtin_offsetof (union F
, f2
.d2
);
150 union F
*f1
= malloc (s
);
151 union F
*f2
= malloc (o
+ 212);
154 TS (f1
->f2
.d2
.b1
, s
- o
);
155 TS (f1
->f2
.d2
.b2
.a1
, s
- o
);
156 TF (f1
->f2
.d2
.b2
.a2
, s
- o
);
160 TS (f2
->f2
.d2
.b1
, s
- o
);
161 TS (f2
->f2
.d2
.b2
.a1
, s
- o
);
162 TF (f2
->f2
.d2
.b2
.a2
, s
- o
);
166 s
= sizeof (struct G
);
167 o
= __builtin_offsetof (struct G
, g2
);
168 struct G
*g1
= malloc (s
);
169 struct G
*g2
= malloc (o
+ 212);
171 TA (g1
->g1
.a2
, s
, sizeof (g1
->g1
.a2
));
175 TA (g2
->g1
.a2
, s
, sizeof (g1
->g1
.a2
));
180 s
= sizeof (struct H
);
181 o
= __builtin_offsetof (struct H
, h2
);
182 o2
= __builtin_offsetof (struct H
, h2
.e1
.c2
);
183 struct H
*h1
= malloc (s
);
184 struct H
*h2
= malloc (o2
+ 212);
186 TS (h1
->h2
.e1
.c1
, s
- o
);
187 TS (h1
->h2
.e1
.c2
.a1
, s
- o2
);
188 TA (h1
->h2
.e1
.c2
.a2
, s
- o2
, sizeof (h1
->h2
.e1
.c2
.a2
));
189 TF (h1
->h2
.e2
, s
- o
);
192 TS (h2
->h2
.e1
.c1
, s
- o
);
193 TS (h2
->h2
.e1
.c2
.a1
, s
- o2
);
194 TA (h2
->h2
.e1
.c2
.a2
, s
- o2
, sizeof (h2
->h2
.e1
.c2
.a2
));
195 TF (h2
->h2
.e2
, s
- o
);