blob: 9a0cd459a3348fc27a8ea087741d8b559a0eb324 [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
Eli Friedman2fe36362011-09-27 19:12:27 +000070#pragma pack(pop)
71
72// This needs only for building layouts.
73// Without this clang doesn`t dump record layouts.
74int main() {
75 // This avoid "Can't yet mangle constructors!" for MS ABI.
76 C* c;
77 c->foo();
78 DerivedStruct* v;
Eli Friedman97c0aef2011-10-18 00:55:28 +000079 H* g;
Eli Friedman2fe36362011-09-27 19:12:27 +000080 BaseStruct* u;
Eli Friedman227e4832011-10-21 22:49:56 +000081 I* i;
Eli Friedman2fe36362011-09-27 19:12:27 +000082 return 0;
83}
84
85// CHECK: 0 | class D
Eli Friedman227e4832011-10-21 22:49:56 +000086// CHECK-NEXT: 0 | (D vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +000087// CHECK-NEXT: 8 | double a
88
89// CHECK-NEXT: sizeof=16, dsize=16, align=8
90// CHECK-NEXT: nvsize=16, nvalign=8
91
92// CHECK: 0 | class B
Eli Friedman227e4832011-10-21 22:49:56 +000093// CHECK-NEXT: 0 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +000094// CHECK-NEXT: 4 | int b_field
95
96// CHECK-NEXT: sizeof=8, dsize=8, align=4
97// CHECK-NEXT: nvsize=8, nvalign=4
98
99// CHECK: 0 | class A
100// CHECK-NEXT: 0 | class B (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000101// CHECK-NEXT: 0 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000102// CHECK-NEXT: 4 | int b_field
103// CHECK-NEXT: 8 | int a_field
104// CHECK-NEXT: 12 | char one
105
106// CHECK-NEXT: sizeof=16, dsize=16, align=4
107// CHECK-NEXT: nvsize=16, nvalign=4
108
109// CHECK: 0 | class C
110// CHECK-NEXT: 0 | class D (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000111// CHECK-NEXT: 0 | (D vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000112// CHECK-NEXT: 8 | double a
113// CHECK-NEXT: 16 | class B (base)
Eli Friedman227e4832011-10-21 22:49:56 +0000114// CHECK-NEXT: 16 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000115// CHECK-NEXT: 20 | int b_field
116// CHECK-NEXT: 24 | (C vbtable pointer)
117// CHECK-NEXT: 32 | double c1_field
118// CHECK-NEXT: 40 | int c2_field
119// CHECK-NEXT: 48 | double c3_field
120// CHECK-NEXT: 56 | int c4_field
121// CHECK-NEXT: 64 | class A (virtual base)
122// CHECK-NEXT: 64 | class B (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000123// CHECK-NEXT: 64 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000124// CHECK-NEXT: 68 | int b_field
125// CHECK-NEXT: 72 | int a_field
126// CHECK-NEXT: 76 | char one
127
128// CHECK-NEXT: sizeof=80, dsize=80, align=8
Eli Friedman227e4832011-10-21 22:49:56 +0000129// CHECK-NEXT: nvsize=64, nvalign=8
Eli Friedman2fe36362011-09-27 19:12:27 +0000130
131// CHECK: 0 | struct BaseStruct
132// CHECK-NEXT: 0 | double v0
133// CHECK-NEXT: 8 | float v1
134// CHECK-NEXT: 16 | class C fg
135// CHECK-NEXT: 16 | class D (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000136// CHECK-NEXT: 16 | (D vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000137// CHECK-NEXT: 24 | double a
138// CHECK-NEXT: 32 | class B (base)
Eli Friedman227e4832011-10-21 22:49:56 +0000139// CHECK-NEXT: 32 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000140// CHECK-NEXT: 36 | int b_field
141// CHECK-NEXT: 40 | (C vbtable pointer)
142// CHECK-NEXT: 48 | double c1_field
143// CHECK-NEXT: 56 | int c2_field
144// CHECK-NEXT: 64 | double c3_field
145// CHECK-NEXT: 72 | int c4_field
146// CHECK-NEXT: 80 | class A (virtual base)
147// CHECK-NEXT: 80 | class B (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000148// CHECK-NEXT: 80 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000149// CHECK-NEXT: 84 | int b_field
150// CHECK-NEXT: 88 | int a_field
151// CHECK-NEXT: 92 | char one
152
153// CHECK-NEXT: sizeof=80, dsize=80, align=8
Eli Friedman227e4832011-10-21 22:49:56 +0000154// CHECK-NEXT: nvsize=64, nvalign=8
Eli Friedman2fe36362011-09-27 19:12:27 +0000155
156// CHECK: sizeof=96, dsize=96, align=8
157// CHECK-NEXT: nvsize=96, nvalign=8
158
159// CHECK: 0 | struct DerivedStruct
160// CHECK-NEXT: 0 | struct BaseStruct (base)
161// CHECK-NEXT: 0 | double v0
162// CHECK-NEXT: 8 | float v1
163// CHECK-NEXT: 16 | class C fg
164// CHECK-NEXT: 16 | class D (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000165// CHECK-NEXT: 16 | (D vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000166// CHECK-NEXT: 24 | double a
167// CHECK-NEXT: 32 | class B (base)
Eli Friedman227e4832011-10-21 22:49:56 +0000168// CHECK-NEXT: 32 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000169// CHECK-NEXT: 36 | int b_field
170// CHECK-NEXT: 40 | (C vbtable pointer)
171// CHECK-NEXT: 48 | double c1_field
172// CHECK-NEXT: 56 | int c2_field
173// CHECK-NEXT: 64 | double c3_field
174// CHECK-NEXT: 72 | int c4_field
175// CHECK-NEXT: 80 | class A (virtual base)
176// CHECK-NEXT: 80 | class B (primary base)
Eli Friedman227e4832011-10-21 22:49:56 +0000177// CHECK-NEXT: 80 | (B vftable pointer)
Eli Friedman2fe36362011-09-27 19:12:27 +0000178// CHECK-NEXT: 84 | int b_field
179// CHECK-NEXT: 88 | int a_field
180// CHECK-NEXT: 92 | char one
181// CHECK-NEXT: sizeof=80, dsize=80, align=8
Eli Friedman227e4832011-10-21 22:49:56 +0000182// CHECK-NEXT: nvsize=64, nvalign=8
Eli Friedman2fe36362011-09-27 19:12:27 +0000183
184// CHECK: 96 | int x
185// CHECK-NEXT: sizeof=104, dsize=104, align=8
186// CHECK-NEXT: nvsize=104, nvalign=8
Eli Friedman97c0aef2011-10-18 00:55:28 +0000187
188// CHECK: 0 | struct G
189// CHECK-NEXT: 0 | int g_field
190// CHECK-NEXT: sizeof=4, dsize=4, align=4
191// CHECK-NEXT: nvsize=4, nvalign=4
192
Eli Friedman97c0aef2011-10-18 00:55:28 +0000193// CHECK: 0 | struct H
Eli Friedman97c0aef2011-10-18 00:55:28 +0000194// CHECK-NEXT: 0 | struct G (base)
195// CHECK-NEXT: 0 | int g_field
Eli Friedman227e4832011-10-21 22:49:56 +0000196// CHECK-NEXT: 4 | (H vbtable pointer)
Eli Friedman97c0aef2011-10-18 00:55:28 +0000197// CHECK-NEXT: 8 | class D (virtual base)
Eli Friedman227e4832011-10-21 22:49:56 +0000198// CHECK-NEXT: 8 | (D vftable pointer)
Eli Friedman97c0aef2011-10-18 00:55:28 +0000199// CHECK-NEXT: 16 | double a
200// CHECK-NEXT: sizeof=24, dsize=24, align=8
Eli Friedman227e4832011-10-21 22:49:56 +0000201// CHECK-NEXT: nvsize=8, nvalign=4
202
203// CHECK: 0 | struct I
204// CHECK-NEXT: 0 | (I vftable pointer)
205// CHECK-NEXT: 8 | (I vbtable pointer)
206// CHECK-NEXT: 16 | double q
207// CHECK-NEXT: 24 | class D (virtual base)
208// CHECK-NEXT: 24 | (D vftable pointer)
209// CHECK-NEXT: 32 | double a
210// CHECK-NEXT: sizeof=40, dsize=40, align=8
Eli Friedman97c0aef2011-10-18 00:55:28 +0000211// CHECK-NEXT: nvsize=24, nvalign=8