blob: ea3f899ea249db680591680522b628e422e1b555 [file] [log] [blame]
Eli Friedman2fe36362011-09-27 19:12:27 +00001// RUN: %clang_cc1 -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -cxx-abi microsoft %s 2>&1 \
2// RUN: | FileCheck %s
3
4#pragma pack(push, 8)
5
6class B {
7public:
8 virtual void b(){}
9 int b_field;
10protected:
11private:
12};
13
14class A : public B {
15public:
16 int a_field;
17 virtual void a(){}
18 char one;
19protected:
20private:
21};
22
23class D {
24public:
25 virtual void b(){}
26 double a;
27};
28
29class C : public virtual A,
30 public D, public B {
31public:
32 double c1_field;
33 int c2_field;
34 double c3_field;
35 int c4_field;
36 virtual void foo(){}
37 virtual void bar(){}
38protected:
39private:
40};
41
42struct BaseStruct
43{
44 BaseStruct(){}
45 double v0;
46 float v1;
47 C fg;
48};
49
50struct DerivedStruct : public BaseStruct {
51 int x;
52};
53
54struct G
55{
Eli Friedman97c0aef2011-10-18 00:55:28 +000056 int g_field;
57};
58
59struct H : public G,
60 public virtual D
61{
Eli Friedman2fe36362011-09-27 19:12:27 +000062};
63
Eli Friedman227e4832011-10-21 22:49:56 +000064struct I : public virtual D
65{
66 virtual ~I(){}
67 double q;
68};
69
John McCall9da23522011-11-08 04:01:03 +000070struct K
71{
72 int k;
73};
74
75struct L
76{
77 int l;
78};
79
80struct M : public virtual K
81{
82 int m;
83};
84
85struct N : public L, public M
86{
87 virtual void f(){}
88};
89
90struct O : public H, public G {
91 virtual void fo(){}
92};
93
94struct P : public M, public virtual L {
95 int p;
96};
97
Eli Friedman901dd662011-12-01 00:37:01 +000098struct R {};
John McCall9da23522011-11-08 04:01:03 +000099
Eli Friedman2fe36362011-09-27 19:12:27 +0000100#pragma pack(pop)
101
102// This needs only for building layouts.
103// Without this clang doesn`t dump record layouts.
104int main() {
105 // This avoid "Can't yet mangle constructors!" for MS ABI.
106 C* c;
107 c->foo();
108 DerivedStruct* v;
Eli Friedman97c0aef2011-10-18 00:55:28 +0000109 H* g;
Eli Friedman2fe36362011-09-27 19:12:27 +0000110 BaseStruct* u;
Eli Friedman227e4832011-10-21 22:49:56 +0000111 I* i;
John McCall9da23522011-11-08 04:01:03 +0000112 N* n;
113 O* o;
114 P* p;
Eli Friedman901dd662011-12-01 00:37:01 +0000115 R* r;
Eli Friedman2fe36362011-09-27 19:12:27 +0000116 return 0;
117}
118
119// CHECK: 0 | class D
Eli Friedman227e4832011-10-21 22:49:56 +0000120// CHECK-NEXT: 0 | (D vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000121// CHECK-NEXT: 8 | double a
122
123// CHECK-NEXT: sizeof=16, dsize=16, align=8
124// CHECK-NEXT: nvsize=16, nvalign=8
125
John McCall9da23522011-11-08 04:01:03 +0000126// CHECK: %class.D = type { i32 (...)**, double }
Eli Friedman9bc2c6e2011-10-21 23:03:08 +0000127
Eli Friedman2fe36362011-09-27 19:12:27 +0000128// CHECK: 0 | class B
Eli Friedman227e4832011-10-21 22:49:56 +0000129// CHECK-NEXT: 0 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000130// CHECK-NEXT: 4 | int b_field
131
132// CHECK-NEXT: sizeof=8, dsize=8, align=4
133// CHECK-NEXT: nvsize=8, nvalign=4
134
John McCall9da23522011-11-08 04:01:03 +0000135// CHECK: %class.B = type { i32 (...)**, i32 }
Eli Friedman9bc2c6e2011-10-21 23:03:08 +0000136
Eli Friedman2fe36362011-09-27 19:12:27 +0000137// CHECK: 0 | class A
138// CHECK-NEXT: 0 | class B (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000139// CHECK-NEXT: 0 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000140// CHECK-NEXT: 4 | int b_field
141// CHECK-NEXT: 8 | int a_field
142// CHECK-NEXT: 12 | char one
143
144// CHECK-NEXT: sizeof=16, dsize=16, align=4
145// CHECK-NEXT: nvsize=16, nvalign=4
146
147// CHECK: 0 | class C
148// CHECK-NEXT: 0 | class D (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000149// CHECK-NEXT: 0 | (D vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000150// CHECK-NEXT: 8 | double a
151// CHECK-NEXT: 16 | class B (base)
Eli Friedman227e4832011-10-21 22:49:56 +0000152// CHECK-NEXT: 16 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000153// CHECK-NEXT: 20 | int b_field
154// CHECK-NEXT: 24 | (C vbtable pointer)
155// CHECK-NEXT: 32 | double c1_field
156// CHECK-NEXT: 40 | int c2_field
157// CHECK-NEXT: 48 | double c3_field
158// CHECK-NEXT: 56 | int c4_field
159// CHECK-NEXT: 64 | class A (virtual base)
160// CHECK-NEXT: 64 | class B (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000161// CHECK-NEXT: 64 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000162// CHECK-NEXT: 68 | int b_field
163// CHECK-NEXT: 72 | int a_field
164// CHECK-NEXT: 76 | char one
165
166// CHECK-NEXT: sizeof=80, dsize=80, align=8
Eli Friedman227e4832011-10-21 22:49:56 +0000167// CHECK-NEXT: nvsize=64, nvalign=8
Eli Friedman9bc2c6e2011-10-21 23:03:08 +0000168
169// CHECK: %class.A = type { %class.B, i32, i8 }
170
John McCall9da23522011-11-08 04:01:03 +0000171// CHECK: %class.C = type { %class.D, %class.B, i32*, double, i32, double, i32, [4 x i8], %class.A }
172// CHECK: %class.C.base = type { %class.D, %class.B, i32*, double, i32, double, i32 }
Eli Friedman9bc2c6e2011-10-21 23:03:08 +0000173
Eli Friedman2fe36362011-09-27 19:12:27 +0000174// CHECK: 0 | struct BaseStruct
175// CHECK-NEXT: 0 | double v0
176// CHECK-NEXT: 8 | float v1
177// CHECK-NEXT: 16 | class C fg
178// CHECK-NEXT: 16 | class D (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000179// CHECK-NEXT: 16 | (D vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000180// CHECK-NEXT: 24 | double a
181// CHECK-NEXT: 32 | class B (base)
Eli Friedman227e4832011-10-21 22:49:56 +0000182// CHECK-NEXT: 32 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000183// CHECK-NEXT: 36 | int b_field
184// CHECK-NEXT: 40 | (C vbtable pointer)
185// CHECK-NEXT: 48 | double c1_field
186// CHECK-NEXT: 56 | int c2_field
187// CHECK-NEXT: 64 | double c3_field
188// CHECK-NEXT: 72 | int c4_field
189// CHECK-NEXT: 80 | class A (virtual base)
190// CHECK-NEXT: 80 | class B (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000191// CHECK-NEXT: 80 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000192// CHECK-NEXT: 84 | int b_field
193// CHECK-NEXT: 88 | int a_field
194// CHECK-NEXT: 92 | char one
195
196// CHECK-NEXT: sizeof=80, dsize=80, align=8
Eli Friedman227e4832011-10-21 22:49:56 +0000197// CHECK-NEXT: nvsize=64, nvalign=8
Eli Friedman2fe36362011-09-27 19:12:27 +0000198
199// CHECK: sizeof=96, dsize=96, align=8
200// CHECK-NEXT: nvsize=96, nvalign=8
201
Eli Friedman9bc2c6e2011-10-21 23:03:08 +0000202// CHECK: %struct.BaseStruct = type { double, float, %class.C }
203
Eli Friedman2fe36362011-09-27 19:12:27 +0000204// CHECK: 0 | struct DerivedStruct
205// CHECK-NEXT: 0 | struct BaseStruct (base)
206// CHECK-NEXT: 0 | double v0
207// CHECK-NEXT: 8 | float v1
208// CHECK-NEXT: 16 | class C fg
209// CHECK-NEXT: 16 | class D (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000210// CHECK-NEXT: 16 | (D vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000211// CHECK-NEXT: 24 | double a
212// CHECK-NEXT: 32 | class B (base)
Eli Friedman227e4832011-10-21 22:49:56 +0000213// CHECK-NEXT: 32 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000214// CHECK-NEXT: 36 | int b_field
215// CHECK-NEXT: 40 | (C vbtable pointer)
216// CHECK-NEXT: 48 | double c1_field
217// CHECK-NEXT: 56 | int c2_field
218// CHECK-NEXT: 64 | double c3_field
219// CHECK-NEXT: 72 | int c4_field
220// CHECK-NEXT: 80 | class A (virtual base)
221// CHECK-NEXT: 80 | class B (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000222// CHECK-NEXT: 80 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000223// CHECK-NEXT: 84 | int b_field
224// CHECK-NEXT: 88 | int a_field
225// CHECK-NEXT: 92 | char one
226// CHECK-NEXT: sizeof=80, dsize=80, align=8
Eli Friedman227e4832011-10-21 22:49:56 +0000227// CHECK-NEXT: nvsize=64, nvalign=8
Eli Friedman2fe36362011-09-27 19:12:27 +0000228
229// CHECK: 96 | int x
230// CHECK-NEXT: sizeof=104, dsize=104, align=8
231// CHECK-NEXT: nvsize=104, nvalign=8
Eli Friedman97c0aef2011-10-18 00:55:28 +0000232
Eli Friedman9bc2c6e2011-10-21 23:03:08 +0000233// CHECK: %struct.DerivedStruct = type { %struct.BaseStruct, i32 }
234
Eli Friedman97c0aef2011-10-18 00:55:28 +0000235// CHECK: 0 | struct G
236// CHECK-NEXT: 0 | int g_field
237// CHECK-NEXT: sizeof=4, dsize=4, align=4
238// CHECK-NEXT: nvsize=4, nvalign=4
239
Eli Friedman97c0aef2011-10-18 00:55:28 +0000240// CHECK: 0 | struct H
Eli Friedman97c0aef2011-10-18 00:55:28 +0000241// CHECK-NEXT: 0 | struct G (base)
242// CHECK-NEXT: 0 | int g_field
Eli Friedman227e4832011-10-21 22:49:56 +0000243// CHECK-NEXT: 4 | (H vbtable pointer)
Eli Friedman97c0aef2011-10-18 00:55:28 +0000244// CHECK-NEXT: 8 | class D (virtual base)
Eli Friedman227e4832011-10-21 22:49:56 +0000245// CHECK-NEXT: 8 | (D vftable pointer)
Eli Friedman97c0aef2011-10-18 00:55:28 +0000246// CHECK-NEXT: 16 | double a
247// CHECK-NEXT: sizeof=24, dsize=24, align=8
Eli Friedman227e4832011-10-21 22:49:56 +0000248// CHECK-NEXT: nvsize=8, nvalign=4
249
John McCall9da23522011-11-08 04:01:03 +0000250// CHECK: %struct.H = type { %struct.G, i32*, %class.D }
Eli Friedman9bc2c6e2011-10-21 23:03:08 +0000251
Eli Friedman227e4832011-10-21 22:49:56 +0000252// CHECK: 0 | struct I
253// CHECK-NEXT: 0 | (I vftable pointer)
254// CHECK-NEXT: 8 | (I vbtable pointer)
255// CHECK-NEXT: 16 | double q
256// CHECK-NEXT: 24 | class D (virtual base)
257// CHECK-NEXT: 24 | (D vftable pointer)
258// CHECK-NEXT: 32 | double a
259// CHECK-NEXT: sizeof=40, dsize=40, align=8
Eli Friedman97c0aef2011-10-18 00:55:28 +0000260// CHECK-NEXT: nvsize=24, nvalign=8
Eli Friedman9bc2c6e2011-10-21 23:03:08 +0000261
John McCall9da23522011-11-08 04:01:03 +0000262// CHECK: %struct.I = type { i32 (...)**, [4 x i8], i32*, double, %class.D }
263// CHECK: %struct.I.base = type { i32 (...)**, [4 x i8], i32*, double }
264
265// CHECK: 0 | struct L
266// CHECK-NEXT: 0 | int l
267// CHECK-NEXT: sizeof=4, dsize=4, align=4
268// CHECK-NEXT: nvsize=4, nvalign=4
269
270// CHECK: 0 | struct K
271// CHECK-NEXT: 0 | int k
272// CHECK-NEXT: sizeof=4, dsize=4, align=4
273// CHECK-NEXT: nvsize=4, nvalign=4
274
275// CHECK: 0 | struct M
276// CHECK-NEXT: 0 | (M vbtable pointer)
277// CHECK-NEXT: 4 | int m
278// CHECK-NEXT: 8 | struct K (virtual base)
279// CHECK-NEXT: 8 | int k
280// CHECK-NEXT: sizeof=12, dsize=12, align=4
281
282//CHECK: %struct.M = type { i32*, i32, %struct.K }
283//CHECK: %struct.M.base = type { i32*, i32 }
284
285// CHECK: 0 | struct N
286// CHECK-NEXT: 4 | struct L (base)
287// CHECK-NEXT: 4 | int l
288// CHECK-NEXT: 8 | struct M (base)
289// CHECK-NEXT: 8 | (M vbtable pointer)
290// CHECK-NEXT: 12 | int m
291// CHECK-NEXT: 0 | (N vftable pointer)
292// CHECK-NEXT: 16 | struct K (virtual base)
293// CHECK-NEXT: 16 | int k
294// CHECK-NEXT: sizeof=20, dsize=20, align=4
295// CHECK-NEXT: nvsize=16, nvalign=4
296
297//CHECK: %struct.N = type { i32 (...)**, %struct.L, %struct.M.base, %struct.K }
298
299// FIXME: MSVC place struct H at offset 8.
300// CHECK: 0 | struct O
301// CHECK-NEXT: 4 | struct H (base)
302// CHECK-NEXT: 4 | struct G (base)
303// CHECK-NEXT: 4 | int g_field
304// CHECK-NEXT: 8 | (H vbtable pointer)
305// CHECK-NEXT: 12 | struct G (base)
306// CHECK-NEXT: 12 | int g_field
307// CHECK-NEXT: 0 | (O vftable pointer)
308// CHECK-NEXT: 16 | class D (virtual base)
309// CHECK-NEXT: 16 | (D vftable pointer)
310// CHECK-NEXT: 24 | double a
311// CHECK-NEXT: sizeof=32, dsize=32, align=8
312// CHECK-NEXT: nvsize=16, nvalign=4
313
314//CHECK: %struct.O = type { i32 (...)**, %struct.H.base, %struct.G, %class.D }
315//CHECK: %struct.O.base = type { i32 (...)**, %struct.H.base, %struct.G }
316
317// CHECK: 0 | struct P
318// CHECK-NEXT: 0 | struct M (base)
319// CHECK-NEXT: 0 | (M vbtable pointer)
320// CHECK-NEXT: 4 | int m
321// CHECK-NEXT: 8 | int p
322// CHECK-NEXT: 12 | struct K (virtual base)
323// CHECK-NEXT: 12 | int k
324// CHECK-NEXT: 16 | struct L (virtual base)
325// CHECK-NEXT: 16 | int l
326// CHECK-NEXT: sizeof=20, dsize=20, align=4
327// CHECK-NEXT: nvsize=12, nvalign=4
328
329//CHECK: %struct.P = type { %struct.M.base, i32, %struct.K, %struct.L }
Eli Friedman901dd662011-12-01 00:37:01 +0000330
331// CHECK: 0 | struct R (empty)
332// CHECK-NEXT: sizeof=1, dsize=0, align=1
333// CHECK-NEXT: nvsize=0, nvalign=1
334
335//CHECK: %struct.R = type { i8 }