microsoft-abi-vtables-multiple-nonvirtual-inheritance-no-thunks.cpp
7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// RUN: %clang_cc1 %s -fno-rtti -triple=i386-pc-win32 -emit-llvm -o %t.ll -fdump-vtable-layouts >%t
// RUN: FileCheck %s < %t
// RUN: FileCheck --check-prefix=MANGLING %s < %t.ll
namespace test1 {
struct A {
virtual void f();
};
struct B {
virtual void g();
// Add an extra virtual method so it's easier to check for the absence of thunks.
virtual void h();
};
struct X : A, B {
// CHECK-LABEL: VFTable for 'test1::A' in 'test1::X' (1 entry)
// CHECK-NEXT: 0 | void test1::X::f()
// CHECK-LABEL: VFTable for 'test1::B' in 'test1::X' (2 entries)
// CHECK-NEXT: 0 | void test1::B::g()
// CHECK-NEXT: 1 | void test1::B::h()
// CHECK-LABEL: VFTable indices for 'test1::X' (1 entry)
// CHECK-NEXT: 0 | void test1::X::f()
// MANGLING-DAG: @"??_7X@test1@@6BA@1@@"
// MANGLING-DAG: @"??_7X@test1@@6BB@1@@"
// Overrides only the left child's method (A::f), needs no thunks.
virtual void f();
} x;
void build_vftable(X *obj) { obj->f(); }
}
namespace test2 {
struct A {
virtual void f();
};
struct B {
virtual void g();
virtual void h();
};
struct X : A, B {
// CHECK-LABEL: VFTable for 'test2::A' in 'test2::X' (1 entry)
// CHECK-NEXT: 0 | void test2::A::f()
// CHECK-LABEL: VFTable for 'test2::B' in 'test2::X' (2 entries)
// CHECK-NEXT: 0 | void test2::X::g()
// CHECK-NEXT: 1 | void test2::B::h()
// CHECK-LABEL: VFTable indices for 'test2::X' (1 entry).
// CHECK-NEXT: via vfptr at offset 4
// CHECK-NEXT: 0 | void test2::X::g()
// Overrides only the right child's method (B::g), needs this adjustment but
// not thunks.
virtual void g();
};
void build_vftable(X *obj) { obj->g(); }
}
namespace test3 {
struct A {
virtual void f();
};
struct B {
virtual void g();
virtual void h();
};
struct X : A, B {
// CHECK-LABEL: VFTable for 'test3::A' in 'test3::X' (2 entries)
// CHECK-NEXT: 0 | void test3::A::f()
// CHECK-NEXT: 1 | void test3::X::i()
// CHECK-LABEL: VFTable for 'test3::B' in 'test3::X' (2 entries)
// CHECK-NEXT: 0 | void test3::B::g()
// CHECK-NEXT: 1 | void test3::B::h()
// CHECK-LABEL: VFTable indices for 'test3::X' (1 entry).
// CHECK-NEXT: 1 | void test3::X::i()
// Only adds a new method.
virtual void i();
};
void build_vftable(X *obj) { obj->i(); }
}
namespace test4 {
struct A {
virtual void f();
};
struct Empty { }; // Doesn't have a vftable!
// Only the right base has a vftable, so it's laid out before the left one!
struct X : Empty, A {
// CHECK-LABEL: VFTable for 'test4::A' in 'test4::X' (1 entry)
// CHECK-NEXT: 0 | void test4::X::f()
// CHECK-LABEL: VFTable indices for 'test4::X' (1 entry).
// CHECK-NEXT: 0 | void test4::X::f()
// MANGLING-DAG: @"??_7X@test4@@6B@"
virtual void f();
} x;
void build_vftable(X *obj) { obj->f(); }
}
namespace test5 {
struct A {
virtual void f();
};
struct B {
virtual void g();
virtual void h();
};
struct C : A, B {
virtual void f();
};
struct X : C {
// CHECK-LABEL: VFTable for 'test5::A' in 'test5::C' in 'test5::X' (1 entry).
// CHECK-NEXT: 0 | void test5::X::f()
// CHECK-LABEL: VFTable for 'test5::B' in 'test5::C' in 'test5::X' (2 entries).
// CHECK-NEXT: 0 | void test5::B::g()
// CHECK-NEXT: 1 | void test5::B::h()
// CHECK-LABEL: VFTable indices for 'test5::X' (1 entry).
// CHECK-NEXT: 0 | void test5::X::f()
// MANGLING-DAG: @"??_7X@test5@@6BA@1@@"
// MANGLING-DAG: @"??_7X@test5@@6BB@1@@"
// Overrides both C::f and A::f.
virtual void f();
} x;
void build_vftable(X *obj) { obj->f(); }
}
namespace test6 {
struct A {
virtual void f();
};
struct B {
virtual void g();
virtual void h();
};
struct C : A, B {
virtual void g();
};
struct X : C {
// CHECK-LABEL: VFTable for 'test6::A' in 'test6::C' in 'test6::X' (1 entry).
// CHECK-NEXT: 0 | void test6::A::f()
// CHECK-LABEL: VFTable for 'test6::B' in 'test6::C' in 'test6::X' (2 entries).
// CHECK-NEXT: 0 | void test6::X::g()
// CHECK-NEXT: 1 | void test6::B::h()
// CHECK-LABEL: VFTable indices for 'test6::X' (1 entry).
// CHECK-NEXT: via vfptr at offset 4
// CHECK-NEXT: 0 | void test6::X::g()
// Overrides both C::g and B::g.
virtual void g();
};
void build_vftable(X *obj) { obj->g(); }
}
namespace test7 {
struct A {
virtual void f();
};
struct B {
virtual void g();
virtual void h();
};
struct C : A, B {
// Only adds a new method.
virtual void i();
};
struct X : C {
// CHECK-LABEL: VFTable for 'test7::A' in 'test7::C' in 'test7::X' (2 entries).
// CHECK-NEXT: 0 | void test7::A::f()
// CHECK-NEXT: 1 | void test7::C::i()
// CHECK-LABEL: VFTable for 'test7::B' in 'test7::C' in 'test7::X' (2 entries).
// CHECK-NEXT: 0 | void test7::X::g()
// CHECK-NEXT: 1 | void test7::B::h()
// CHECK-LABEL: VFTable indices for 'test7::X' (1 entry).
// CHECK-NEXT: via vfptr at offset 4
// CHECK-NEXT: 0 | void test7::X::g()
// Overrides grandparent's B::g.
virtual void g();
};
void build_vftable(X *obj) { obj->g(); }
}
namespace test8 {
struct A {
virtual void f();
};
struct B : A {
virtual void g();
};
// There are two 'A' subobjects in this class.
struct X : A, B {
// CHECK-LABEL: VFTable for 'test8::A' in 'test8::X' (2 entries).
// CHECK-NEXT: 0 | void test8::A::f()
// CHECK-NEXT: 1 | void test8::X::h()
// CHECK-LABEL: VFTable for 'test8::A' in 'test8::B' in 'test8::X' (2 entries).
// CHECK-NEXT: 0 | void test8::A::f()
// CHECK-NEXT: 1 | void test8::B::g()
// CHECK-LABEL: VFTable indices for 'test8::X' (1 entry).
// CHECK-NEXT: 1 | void test8::X::h()
// MANGLING-DAG: @"??_7X@test8@@6BA@1@@"
// MANGLING-DAG: @"??_7X@test8@@6BB@1@@"
virtual void h();
} x;
void build_vftable(X *obj) { obj->h(); }
}
namespace test9 {
struct A {
virtual void f();
};
struct B {
virtual void g();
virtual void h();
};
struct C : A, B {
// Overrides only the left child's method (A::f).
virtual void f();
};
struct D : A, B {
// Overrides only the right child's method (B::g).
virtual void g();
};
// 2-level structure with repeating subobject types, but no thunks needed.
struct X : C, D {
// CHECK-LABEL: VFTable for 'test9::A' in 'test9::C' in 'test9::X' (2 entries)
// CHECK-NEXT: 0 | void test9::C::f()
// CHECK-NEXT: 1 | void test9::X::z()
// CHECK-LABEL: VFTable for 'test9::B' in 'test9::C' in 'test9::X' (2 entries)
// CHECK-NEXT: 0 | void test9::B::g()
// CHECK-NEXT: 1 | void test9::B::h()
// CHECK-LABEL: VFTable for 'test9::A' in 'test9::D' in 'test9::X' (1 entry)
// CHECK-NEXT: 0 | void test9::A::f()
// CHECK-LABEL: VFTable for 'test9::B' in 'test9::D' in 'test9::X' (2 entries)
// CHECK-NEXT: 0 | void test9::D::g()
// CHECK-NEXT: 1 | void test9::B::h()
// CHECK-LABEL: VFTable indices for 'test9::X' (1 entry).
// CHECK-NEXT: 1 | void test9::X::z()
// MANGLING-DAG: @"??_7X@test9@@6BA@1@C@1@@"
// MANGLING-DAG: @"??_7X@test9@@6BA@1@D@1@@"
// MANGLING-DAG: @"??_7X@test9@@6BB@1@C@1@@"
// MANGLING-DAG: @"??_7X@test9@@6BB@1@D@1@@"
virtual void z();
} x;
void build_vftable(test9::X *obj) { obj->z(); }
}