microsoft-abi-vtables-multiple-nonvirtual-inheritance-return-adjustment.cpp
10.1 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
// 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 g();
// Add an extra virtual method so it's easier to check for the absence of thunks.
virtual void h();
};
struct B {
virtual void g();
};
// Overrides a method of two bases at the same time, thus needing thunks.
struct C : A, B {
virtual void g();
};
struct D {
virtual B* foo();
virtual void z();
};
struct X : D {
// CHECK-LABEL: VFTable for 'test1::D' in 'test1::X' (3 entries).
// CHECK-NEXT: 0 | test1::C *test1::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test1::B *'): 4 non-virtual]
// CHECK-NEXT: 1 | void test1::D::z()
// CHECK-NEXT: 2 | test1::C *test1::X::foo()
// CHECK-LABEL: Thunks for 'test1::C *test1::X::foo()' (1 entry).
// CHECK-NEXT: 0 | [return adjustment (to type 'struct test1::B *'): 4 non-virtual]
// CHECK-LABEL: VFTable indices for 'test1::X' (1 entry).
// CHECK-NEXT: 2 | test1::C *test1::X::foo()
// MANGLING-DAG: @"??_7X@test1@@6B@"
virtual C* foo();
} x;
void build_vftable(X *obj) { obj->foo(); }
}
namespace test2 {
struct A {
virtual void g();
virtual void h();
};
struct B {
virtual void g();
};
struct C : A, B {
virtual void g();
};
struct D {
virtual B* foo();
virtual void z();
};
struct E : D {
virtual C* foo();
};
struct F : C { };
struct X : E {
virtual F* foo();
// CHECK-LABEL: VFTable for 'test2::D' in 'test2::E' in 'test2::X' (4 entries).
// CHECK-NEXT: 0 | test2::F *test2::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test2::B *'): 4 non-virtual]
// CHECK-NEXT: 1 | void test2::D::z()
// CHECK-NEXT: 2 | test2::F *test2::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test2::C *'): 0 non-virtual]
// CHECK-NEXT: 3 | test2::F *test2::X::foo()
// CHECK-LABEL: Thunks for 'test2::F *test2::X::foo()' (2 entries).
// CHECK-NEXT: 0 | [return adjustment (to type 'struct test2::C *'): 0 non-virtual]
// CHECK-NEXT: 1 | [return adjustment (to type 'struct test2::B *'): 4 non-virtual]
// CHECK-LABEL: VFTable indices for 'test2::X' (1 entry).
// CHECK-NEXT: 3 | test2::F *test2::X::foo()
};
void build_vftable(X *obj) { obj->foo(); }
}
namespace test3 {
struct A {
virtual void g();
virtual void h();
};
struct B {
virtual void g();
};
struct C : A, B {
virtual void g();
};
struct D {
virtual B* foo();
virtual void z();
};
struct E : D {
virtual C* foo();
};
struct F : A, C { };
struct X : E {
// CHECK-LABEL: VFTable for 'test3::D' in 'test3::E' in 'test3::X' (4 entries).
// CHECK-NEXT: 0 | test3::F *test3::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test3::B *'): 8 non-virtual]
// CHECK-NEXT: 1 | void test3::D::z()
// CHECK-NEXT: 2 | test3::F *test3::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test3::C *'): 4 non-virtual]
// CHECK-NEXT: 3 | test3::F *test3::X::foo()
// CHECK-LABEL: Thunks for 'test3::F *test3::X::foo()' (2 entries).
// CHECK-NEXT: 0 | [return adjustment (to type 'struct test3::C *'): 4 non-virtual]
// CHECK-NEXT: 1 | [return adjustment (to type 'struct test3::B *'): 8 non-virtual]
// CHECK-LABEL: VFTable indices for 'test3::X' (1 entry).
// CHECK-NEXT: 3 | test3::F *test3::X::foo()
virtual F* foo();
};
void build_vftable(X *obj) { obj->foo(); }
}
namespace test4 {
struct A {
virtual void g();
virtual void h();
};
struct B {
virtual void g();
};
struct C : A, B {
virtual void g();
};
struct D {
virtual B* foo();
virtual void z();
};
struct E : D {
virtual C* foo();
};
struct F : A, C { };
struct X : D, E {
// CHECK-LABEL: VFTable for 'test4::D' in 'test4::X' (3 entries).
// CHECK-NEXT: 0 | test4::F *test4::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test4::B *'): 8 non-virtual]
// CHECK-NEXT: 1 | void test4::D::z()
// CHECK-NEXT: 2 | test4::F *test4::X::foo()
// CHECK-LABEL: Thunks for 'test4::F *test4::X::foo()' (1 entry).
// CHECK-NEXT: 0 | [return adjustment (to type 'struct test4::B *'): 8 non-virtual]
// CHECK-LABEL: VFTable for 'test4::D' in 'test4::E' in 'test4::X' (4 entries).
// CHECK-NEXT: 0 | test4::F *test4::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test4::B *'): 8 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
// CHECK-NEXT: 1 | void test4::D::z()
// CHECK-NEXT: 2 | test4::F *test4::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test4::C *'): 4 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
// CHECK-NEXT: 3 | test4::F *test4::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test4::F *'): 0 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
// CHECK-LABEL: Thunks for 'test4::F *test4::X::foo()' (3 entries).
// CHECK-NEXT: 0 | [return adjustment (to type 'struct test4::F *'): 0 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
// CHECK-NEXT: 1 | [return adjustment (to type 'struct test4::C *'): 4 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
// CHECK-NEXT: 2 | [return adjustment (to type 'struct test4::B *'): 8 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
// CHECK-LABEL: VFTable indices for 'test4::X' (1 entry).
// CHECK-NEXT: 2 | test4::F *test4::X::foo()
virtual F* foo();
};
void build_vftable(X *obj) { obj->foo(); }
}
namespace test5 {
struct A {
virtual void g();
virtual void h();
};
struct B {
virtual void g();
};
struct C : A, B {
virtual void g();
};
struct D {
virtual B* foo();
virtual void z();
};
struct X : A, D {
// CHECK-LABEL: VFTable for 'test5::A' in 'test5::X' (2 entries).
// CHECK-NEXT: 0 | void test5::A::g()
// CHECK-NEXT: 1 | void test5::A::h()
// CHECK-LABEL: VFTable for 'test5::D' in 'test5::X' (3 entries).
// CHECK-NEXT: 0 | test5::C *test5::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test5::B *'): 4 non-virtual]
// CHECK-NEXT: 1 | void test5::D::z()
// CHECK-NEXT: 2 | test5::C *test5::X::foo()
// CHECK-LABEL: Thunks for 'test5::C *test5::X::foo()' (1 entry).
// CHECK-NEXT: 0 | [return adjustment (to type 'struct test5::B *'): 4 non-virtual]
// CHECK-LABEL: VFTable indices for 'test5::X' (1 entry).
// CHECK-NEXT: via vfptr at offset 4
// CHECK-NEXT: 2 | test5::C *test5::X::foo()
virtual C* foo();
};
void build_vftable(X *obj) { obj->foo(); }
}
namespace test6 {
struct A {
virtual void g();
virtual void h();
};
struct B {
virtual void g();
};
struct C : A, B {
virtual void g();
};
struct D {
virtual B* foo();
virtual void z();
};
struct E : A, D {
virtual C* foo();
};
struct F : A, C { };
struct X : E {
// CHECK-LABEL: VFTable for 'test6::A' in 'test6::E' in 'test6::X' (2 entries).
// CHECK-NEXT: 0 | void test6::A::g()
// CHECK-NEXT: 1 | void test6::A::h()
// CHECK-LABEL: VFTable for 'test6::D' in 'test6::E' in 'test6::X' (4 entries).
// CHECK-NEXT: 0 | test6::F *test6::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test6::B *'): 8 non-virtual]
// CHECK-NEXT: 1 | void test6::D::z()
// CHECK-NEXT: 2 | test6::F *test6::X::foo()
// CHECK-NEXT: [return adjustment (to type 'struct test6::C *'): 4 non-virtual]
// CHECK-NEXT: 3 | test6::F *test6::X::foo()
// CHECK-LABEL: Thunks for 'test6::F *test6::X::foo()' (2 entries).
// CHECK-NEXT: 0 | [return adjustment (to type 'struct test6::C *'): 4 non-virtual]
// CHECK-NEXT: 1 | [return adjustment (to type 'struct test6::B *'): 8 non-virtual]
// CHECK-LABEL: VFTable indices for 'test6::X' (1 entry).
// CHECK-NEXT: -- accessible via vfptr at offset 4 --
// CHECK-NEXT: 3 | test6::F *test6::X::foo()
virtual F* foo();
};
void build_vftable(X *obj) { obj->foo(); }
}
namespace test7 {
struct A {
virtual A *f() = 0;
};
struct B {
virtual void g();
};
struct C : B, A {
virtual void g();
virtual C *f() = 0;
// CHECK-LABEL: VFTable for 'test7::B' in 'test7::C' (1 entry).
// CHECK-NEXT: 0 | void test7::C::g()
// CHECK-LABEL: VFTable for 'test7::A' in 'test7::C' (2 entries).
// CHECK-NEXT: 0 | test7::C *test7::C::f() [pure]
// CHECK-NEXT: 1 | test7::C *test7::C::f() [pure]
// No return adjusting thunks needed for pure virtual methods.
// CHECK-NOT: Thunks for 'test7::C *test7::C::f()'
};
void build_vftable(C *obj) { obj->g(); }
}
namespace pr20444 {
struct A {
virtual A* f();
};
struct B {
virtual B* f();
};
struct C : A, B {
virtual C* f();
// CHECK-LABEL: VFTable for 'pr20444::A' in 'pr20444::C' (1 entry).
// CHECK-NEXT: 0 | pr20444::C *pr20444::C::f()
// CHECK-LABEL: VFTable for 'pr20444::B' in 'pr20444::C' (2 entries).
// CHECK-NEXT: 0 | pr20444::C *pr20444::C::f()
// CHECK-NEXT: [return adjustment (to type 'struct pr20444::B *'): 4 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
// CHECK-NEXT: 1 | pr20444::C *pr20444::C::f()
// CHECK-NEXT: [return adjustment (to type 'struct pr20444::C *'): 0 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
};
void build_vftable(C *obj) { obj->f(); }
struct D : C {
virtual D* f();
// CHECK-LABEL: VFTable for 'pr20444::A' in 'pr20444::C' in 'pr20444::D' (1 entry).
// CHECK-NEXT: 0 | pr20444::D *pr20444::D::f()
// CHECK-LABEL: VFTable for 'pr20444::B' in 'pr20444::C' in 'pr20444::D' (3 entries).
// CHECK-NEXT: 0 | pr20444::D *pr20444::D::f()
// CHECK-NEXT: [return adjustment (to type 'struct pr20444::B *'): 4 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
// CHECK-NEXT: 1 | pr20444::D *pr20444::D::f()
// CHECK-NEXT: [return adjustment (to type 'struct pr20444::C *'): 0 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
// CHECK-NEXT: 2 | pr20444::D *pr20444::D::f()
// CHECK-NEXT: [return adjustment (to type 'struct pr20444::D *'): 0 non-virtual]
// CHECK-NEXT: [this adjustment: -4 non-virtual]
};
void build_vftable(D *obj) { obj->f(); }
}