1 // RUN: %clang_cc1 -std=c++14 -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts %s 2>/dev/null \
2 // RUN: | FileCheck %s --strict-whitespace
29 class C
: public virtual A
,
50 struct DerivedStruct
: public BaseStruct
{
64 struct I
: public virtual D
80 struct M
: public virtual K
85 struct N
: public L
, public M
90 struct O
: public H
, public G
{
94 struct P
: public M
, public virtual L
{
103 virtual void ia() = 0;
106 class ICh
: public virtual IA
{
114 virtual int asd() {return -90;}
117 struct s
: public virtual f
{
120 virtual int asd() {return -9;}
123 struct sd
: virtual s
, virtual ICh
{
127 virtual int asd() {return -1;}
134 struct CV
: virtual BV
{
144 // This needs only for building layouts.
145 // Without this clang doesn`t dump record layouts.
147 // This avoid "Can't yet mangle constructors!" for MS ABI.
163 // CHECK-LABEL: 0 | class B{{$}}
164 // CHECK-NEXT: 0 | (B vftable pointer)
165 // CHECK-NEXT: 4 | int b_field
167 // CHECK-NEXT: sizeof=8, align=4
168 // CHECK-NEXT: nvsize=8, nvalign=4
170 // CHECK-LABEL: 0 | class A{{$}}
171 // CHECK-NEXT: 0 | class B (primary base)
172 // CHECK-NEXT: 0 | (B vftable pointer)
173 // CHECK-NEXT: 4 | int b_field
174 // CHECK-NEXT: 8 | int a_field
175 // CHECK-NEXT: 12 | char one
177 // CHECK-NEXT: sizeof=16, align=4
178 // CHECK-NEXT: nvsize=16, nvalign=4
180 // CHECK-LABEL: 0 | class D{{$}}
181 // CHECK-NEXT: 0 | (D vftable pointer)
182 // CHECK-NEXT: 8 | double a
184 // CHECK-NEXT: sizeof=16, align=8
185 // CHECK-NEXT: nvsize=16, nvalign=8
187 // CHECK-LABEL: 0 | class C{{$}}
188 // CHECK-NEXT: 0 | class D (primary base)
189 // CHECK-NEXT: 0 | (D vftable pointer)
190 // CHECK-NEXT: 8 | double a
191 // CHECK-NEXT: 16 | class B (base)
192 // CHECK-NEXT: 16 | (B vftable pointer)
193 // CHECK-NEXT: 20 | int b_field
194 // CHECK-NEXT: 24 | (C vbtable pointer)
195 // CHECK-NEXT: 32 | double c1_field
196 // CHECK-NEXT: 40 | int c2_field
197 // CHECK-NEXT: 48 | double c3_field
198 // CHECK-NEXT: 56 | int c4_field
199 // CHECK-NEXT: 64 | class A (virtual base)
200 // CHECK-NEXT: 64 | class B (primary base)
201 // CHECK-NEXT: 64 | (B vftable pointer)
202 // CHECK-NEXT: 68 | int b_field
203 // CHECK-NEXT: 72 | int a_field
204 // CHECK-NEXT: 76 | char one
206 // CHECK-NEXT: sizeof=80, align=8
207 // CHECK-NEXT: nvsize=64, nvalign=8
209 // CHECK-LABEL: 0 | struct BaseStruct{{$}}
210 // CHECK-NEXT: 0 | double v0
211 // CHECK-NEXT: 8 | float v1
212 // CHECK-NEXT: 16 | class C fg
213 // CHECK-NEXT: 16 | class D (primary base)
214 // CHECK-NEXT: 16 | (D vftable pointer)
215 // CHECK-NEXT: 24 | double a
216 // CHECK-NEXT: 32 | class B (base)
217 // CHECK-NEXT: 32 | (B vftable pointer)
218 // CHECK-NEXT: 36 | int b_field
219 // CHECK-NEXT: 40 | (C vbtable pointer)
220 // CHECK-NEXT: 48 | double c1_field
221 // CHECK-NEXT: 56 | int c2_field
222 // CHECK-NEXT: 64 | double c3_field
223 // CHECK-NEXT: 72 | int c4_field
224 // CHECK-NEXT: 80 | class A (virtual base)
225 // CHECK-NEXT: 80 | class B (primary base)
226 // CHECK-NEXT: 80 | (B vftable pointer)
227 // CHECK-NEXT: 84 | int b_field
228 // CHECK-NEXT: 88 | int a_field
229 // CHECK-NEXT: 92 | char one
230 // CHECK-NEXT: sizeof=96, align=8
231 // CHECK-NEXT: nvsize=96, nvalign=8
233 // CHECK-LABEL: 0 | struct DerivedStruct{{$}}
234 // CHECK-NEXT: 0 | struct BaseStruct (base)
235 // CHECK-NEXT: 0 | double v0
236 // CHECK-NEXT: 8 | float v1
237 // CHECK-NEXT: 16 | class C fg
238 // CHECK-NEXT: 16 | class D (primary base)
239 // CHECK-NEXT: 16 | (D vftable pointer)
240 // CHECK-NEXT: 24 | double a
241 // CHECK-NEXT: 32 | class B (base)
242 // CHECK-NEXT: 32 | (B vftable pointer)
243 // CHECK-NEXT: 36 | int b_field
244 // CHECK-NEXT: 40 | (C vbtable pointer)
245 // CHECK-NEXT: 48 | double c1_field
246 // CHECK-NEXT: 56 | int c2_field
247 // CHECK-NEXT: 64 | double c3_field
248 // CHECK-NEXT: 72 | int c4_field
249 // CHECK-NEXT: 80 | class A (virtual base)
250 // CHECK-NEXT: 80 | class B (primary base)
251 // CHECK-NEXT: 80 | (B vftable pointer)
252 // CHECK-NEXT: 84 | int b_field
253 // CHECK-NEXT: 88 | int a_field
254 // CHECK-NEXT: 92 | char one
255 // CHECK-NEXT: 96 | int x
256 // CHECK-NEXT: sizeof=104, align=8
257 // CHECK-NEXT: nvsize=104, nvalign=8
259 // CHECK-LABEL:0 | struct G
260 // CHECK-NEXT: 0 | int g_field
261 // CHECK-NEXT: sizeof=4, align=4
262 // CHECK-NEXT: nvsize=4, nvalign=4
264 // CHECK-LABEL: 0 | struct H{{$}}
265 // CHECK-NEXT: 0 | struct G (base)
266 // CHECK-NEXT: 0 | int g_field
267 // CHECK-NEXT: 4 | (H vbtable pointer)
268 // CHECK-NEXT: 8 | class D (virtual base)
269 // CHECK-NEXT: 8 | (D vftable pointer)
270 // CHECK-NEXT: 16 | double a
271 // CHECK-NEXT: sizeof=24, align=8
272 // CHECK-NEXT: nvsize=8, nvalign=8
274 // CHECK-LABEL: 0 | struct I{{$}}
275 // CHECK-NEXT: 0 | (I vftable pointer)
276 // CHECK-NEXT: 8 | (I vbtable pointer)
277 // CHECK-NEXT: 16 | double q
278 // CHECK-NEXT: 24 | class D (virtual base)
279 // CHECK-NEXT: 24 | (D vftable pointer)
280 // CHECK-NEXT: 32 | double a
281 // CHECK-NEXT: sizeof=40, align=8
282 // CHECK-NEXT: nvsize=24, nvalign=8
284 // CHECK-LABEL: 0 | struct L{{$}}
285 // CHECK-NEXT: 0 | int l
286 // CHECK-NEXT: sizeof=4, align=4
287 // CHECK-NEXT: nvsize=4, nvalign=4
289 // CHECK-LABEL: 0 | struct K{{$}}
290 // CHECK-NEXT: 0 | int k
291 // CHECK-NEXT: sizeof=4, align=4
292 // CHECK-NEXT: nvsize=4, nvalign=4
294 // CHECK-LABEL: 0 | struct M{{$}}
295 // CHECK-NEXT: 0 | (M vbtable pointer)
296 // CHECK-NEXT: 4 | int m
297 // CHECK-NEXT: 8 | struct K (virtual base)
298 // CHECK-NEXT: 8 | int k
299 // CHECK-NEXT: sizeof=12, align=4
301 // CHECK-LABEL: 0 | struct N{{$}}
302 // CHECK-NEXT: 0 | (N vftable pointer)
303 // CHECK-NEXT: 4 | struct L (base)
304 // CHECK-NEXT: 4 | int l
305 // CHECK-NEXT: 8 | struct M (base)
306 // CHECK-NEXT: 8 | (M vbtable pointer)
307 // CHECK-NEXT: 12 | int m
308 // CHECK-NEXT: 16 | struct K (virtual base)
309 // CHECK-NEXT: 16 | int k
310 // CHECK-NEXT: sizeof=20, align=4
311 // CHECK-NEXT: nvsize=16, nvalign=4
313 // CHECK-LABEL: 0 | struct O{{$}}
314 // CHECK-NEXT: 0 | (O vftable pointer)
315 // CHECK-NEXT: 8 | struct H (base)
316 // CHECK-NEXT: 8 | struct G (base)
317 // CHECK-NEXT: 8 | int g_field
318 // CHECK-NEXT: 12 | (H vbtable pointer)
319 // CHECK-NEXT: 16 | struct G (base)
320 // CHECK-NEXT: 16 | int g_field
321 // CHECK-NEXT: 24 | class D (virtual base)
322 // CHECK-NEXT: 24 | (D vftable pointer)
323 // CHECK-NEXT: 32 | double a
324 // CHECK-NEXT: | [sizeof=40, align=8
325 // CHECK-NEXT: | nvsize=24, nvalign=8]
327 // CHECK-LABEL: 0 | struct P{{$}}
328 // CHECK-NEXT: 0 | struct M (base)
329 // CHECK-NEXT: 0 | (M vbtable pointer)
330 // CHECK-NEXT: 4 | int m
331 // CHECK-NEXT: 8 | int p
332 // CHECK-NEXT: 12 | struct K (virtual base)
333 // CHECK-NEXT: 12 | int k
334 // CHECK-NEXT: 16 | struct L (virtual base)
335 // CHECK-NEXT: 16 | int l
336 // CHECK-NEXT: sizeof=20, align=4
337 // CHECK-NEXT: nvsize=12, nvalign=4
339 // CHECK-LABEL: 0 | struct R (empty){{$}}
340 // CHECK-NEXT: sizeof=1, align=1
341 // CHECK-NEXT: nvsize=0, nvalign=1
343 // CHECK-LABEL: 0 | struct f{{$}}
344 // CHECK-NEXT: 0 | (f vftable pointer)
345 // CHECK-NEXT: sizeof=4, align=4
346 // CHECK-NEXT: nvsize=4, nvalign=4
348 // CHECK-LABEL: 0 | struct s{{$}}
349 // CHECK-NEXT: 0 | (s vftable pointer)
350 // CHECK-NEXT: 4 | (s vbtable pointer)
351 // CHECK-NEXT: 8 | int r
352 // CHECK-NEXT: 12 | (vtordisp for vbase f)
353 // CHECK-NEXT: 16 | struct f (virtual base)
354 // CHECK-NEXT: 16 | (f vftable pointer)
355 // CHECK-NEXT: sizeof=20, align=4
356 // CHECK-NEXT: nvsize=12, nvalign=4
358 // CHECK-LABEL: 0 | class IA{{$}}
359 // CHECK-NEXT: 0 | (IA vftable pointer)
360 // CHECK-NEXT: sizeof=4, align=4
361 // CHECK-NEXT: nvsize=4, nvalign=4
363 // CHECK-LABEL: 0 | class ICh{{$}}
364 // CHECK-NEXT: 0 | (ICh vftable pointer)
365 // CHECK-NEXT: 4 | (ICh vbtable pointer)
366 // CHECK-NEXT: 8 | (vtordisp for vbase IA)
367 // CHECK-NEXT: 12 | class IA (virtual base)
368 // CHECK-NEXT: 12 | (IA vftable pointer)
369 // CHECK-NEXT: sizeof=16, align=4
370 // CHECK-NEXT: nvsize=8, nvalign=4
372 // CHECK-LABEL: 0 | struct sd{{$}}
373 // CHECK-NEXT: 0 | (sd vbtable pointer)
374 // CHECK-NEXT: 4 | int q
375 // CHECK-NEXT: 8 | char y
376 // CHECK-NEXT: 12 | (vtordisp for vbase f)
377 // CHECK-NEXT: 16 | struct f (virtual base)
378 // CHECK-NEXT: 16 | (f vftable pointer)
379 // CHECK-NEXT: 20 | struct s (virtual base)
380 // CHECK-NEXT: 20 | (s vftable pointer)
381 // CHECK-NEXT: 24 | (s vbtable pointer)
382 // CHECK-NEXT: 28 | int r
383 // CHECK-NEXT: 32 | (vtordisp for vbase IA)
384 // CHECK-NEXT: 36 | class IA (virtual base)
385 // CHECK-NEXT: 36 | (IA vftable pointer)
386 // CHECK-NEXT: 40 | class ICh (virtual base)
387 // CHECK-NEXT: 40 | (ICh vftable pointer)
388 // CHECK-NEXT: 44 | (ICh vbtable pointer)
389 // CHECK-NEXT: sizeof=48, align=4
390 // CHECK-NEXT: nvsize=12, nvalign=4
392 // CHECK-LABEL: 0 | struct AV{{$}}
393 // CHECK-NEXT: 0 | (AV vftable pointer)
394 // CHECK-NEXT: sizeof=4, align=4
395 // CHECK-NEXT: nvsize=4, nvalign=4
397 // CHECK-LABEL: 0 | struct BV{{$}}
398 // CHECK-NEXT: 0 | struct AV (primary base)
399 // CHECK-NEXT: 0 | (AV vftable pointer)
400 // CHECK-NEXT: sizeof=4, align=4
401 // CHECK-NEXT: nvsize=4, nvalign=4
403 // CHECK-LABEL: 0 | struct CV{{$}}
404 // CHECK-NEXT: 0 | (CV vbtable pointer)
405 // CHECK-NEXT: 4 | (vtordisp for vbase BV)
406 // CHECK-NEXT: 8 | struct BV (virtual base)
407 // CHECK-NEXT: 8 | struct AV (primary base)
408 // CHECK-NEXT: 8 | (AV vftable pointer)
409 // CHECK-NEXT: sizeof=12, align=4
410 // CHECK-NEXT: nvsize=4, nvalign=4
412 // CHECK-LABEL: 0 | struct DV{{$}}
413 // CHECK-NEXT: 0 | struct BV (primary base)
414 // CHECK-NEXT: 0 | struct AV (primary base)
415 // CHECK-NEXT: 0 | (AV vftable pointer)
416 // CHECK-NEXT: sizeof=4, align=4
417 // CHECK-NEXT: nvsize=4, nvalign=4
419 // CHECK-LABEL: 0 | struct EV{{$}}
420 // CHECK-NEXT: 0 | struct DV (primary base)
421 // CHECK-NEXT: 0 | struct BV (primary base)
422 // CHECK-NEXT: 0 | struct AV (primary base)
423 // CHECK-NEXT: 0 | (AV vftable pointer)
424 // CHECK-NEXT: 4 | struct CV (base)
425 // CHECK-NEXT: 4 | (CV vbtable pointer)
426 // CHECK-NEXT: 8 | (vtordisp for vbase BV)
427 // CHECK-NEXT: 12 | struct BV (virtual base)
428 // CHECK-NEXT: 12 | struct AV (primary base)
429 // CHECK-NEXT: 12 | (AV vftable pointer)
430 // CHECK-NEXT: sizeof=16, align=4
431 // CHECK-NEXT: nvsize=8, nvalign=4
433 // CHECK: %class.D = type { ptr, double }
434 // CHECK: %class.B = type { ptr, i32 }
435 // CHECK: %class.A = type { %class.B, i32, i8 }
436 // CHECK: %class.C = type { %class.D, %class.B, ptr, double, i32, double, i32, [4 x i8], %class.A }
437 // CHECK: %class.C.base = type { %class.D, %class.B, ptr, double, i32, double, i32 }
438 // CHECK: %struct.BaseStruct = type { double, float, %class.C }
439 // CHECK: %struct.DerivedStruct = type { %struct.BaseStruct, i32 }
440 // CHECK: %struct.H = type { %struct.G, ptr, %class.D }
441 // CHECK: %struct.I = type { ptr, [4 x i8], ptr, double, %class.D }
442 // CHECK: %struct.I.base = type { ptr, [4 x i8], ptr, double }
443 // CHECK: %struct.M = type { ptr, i32, %struct.K }
444 // CHECK: %struct.M.base = type { ptr, i32 }
445 // CHECK: %struct.N = type { ptr, %struct.L, %struct.M.base, %struct.K }
446 // CHECK: %struct.O = type { ptr, [4 x i8], %struct.H.base, %struct.G, %class.D }
447 // CHECK: %struct.O.base = type { ptr, [4 x i8], %struct.H.base, %struct.G, [4 x i8] }
448 // CHECK: %struct.P = type { %struct.M.base, i32, %struct.K, %struct.L }
449 // CHECK: %struct.R = type { i8 }
450 // CHECK: %struct.f = type { ptr }
451 // CHECK: %struct.s = type { ptr, ptr, i32, i32, %struct.f }
452 // CHECK: %class.IA = type { ptr }
453 // CHECK: %class.ICh = type { ptr, ptr, i32, %class.IA }
454 // CHECK: %struct.sd = type { ptr, i32, i8, i32, %struct.f, %struct.s.base, i32, %class.IA, %class.ICh.base }
455 // CHECK: %struct.AV = type { ptr }
456 // CHECK: %struct.BV = type { %struct.AV }
457 // CHECK: %struct.CV = type { ptr, i32, %struct.BV }
458 // CHECK: %struct.CV.base = type { ptr }
459 // CHECK: %struct.DV = type { %struct.BV }
460 // CHECK: %struct.EV = type { %struct.DV, %struct.CV.base, i32, %struct.BV }
461 // CHECK: %struct.EV.base = type { %struct.DV, %struct.CV.base }
463 // Overriding a method means that all the vbases containing that
464 // method need a vtordisp. Note: this code will cause an error in cl.exe.
466 struct A
{ virtual void foo(); };
468 struct C
: virtual A
, virtual B
{ C(); virtual void foo(); };
471 // CHECK-LABEL: 0 | struct test1::C{{$}}
472 // CHECK-NEXT: 0 | (C vbtable pointer)
473 // CHECK-NEXT: 4 | (vtordisp for vbase A)
474 // CHECK-NEXT: 8 | struct test1::A (virtual base)
475 // CHECK-NEXT: 8 | (A vftable pointer)
476 // CHECK-NEXT: 12 | (vtordisp for vbase B)
477 // CHECK-NEXT: 16 | struct test1::B (virtual base)
478 // CHECK-NEXT: 16 | struct test1::A (primary base)
479 // CHECK-NEXT: 16 | (A vftable pointer)
480 // CHECK-NEXT: sizeof=20, align=4
481 // CHECK-NEXT: nvsize=4, nvalign=4