blob: 60b46fec39b38d58eaf6b35a2a53729b5a7ffaba [file] [log] [blame]
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm-only -fdump-vtable-layouts > %t 2>&1
2// RUN: FileCheck --check-prefix=CHECK-1 %s < %t
3// RUN: FileCheck --check-prefix=CHECK-2 %s < %t
4// RUN: FileCheck --check-prefix=CHECK-3 %s < %t
5// RUN: FileCheck --check-prefix=CHECK-4 %s < %t
6// RUN: FileCheck --check-prefix=CHECK-5 %s < %t
7// RUN: FileCheck --check-prefix=CHECK-6 %s < %t
8// RUN: FileCheck --check-prefix=CHECK-7 %s < %t
9// RUN: FileCheck --check-prefix=CHECK-8 %s < %t
10// RUN: FileCheck --check-prefix=CHECK-9 %s < %t
11// RUN: FileCheck --check-prefix=CHECK-10 %s < %t
12// RUN: FileCheck --check-prefix=CHECK-11 %s < %t
13// RUN: FileCheck --check-prefix=CHECK-12 %s < %t
14// RUN: FileCheck --check-prefix=CHECK-13 %s < %t
15// RUN: FileCheck --check-prefix=CHECK-14 %s < %t
16// RUN: FileCheck --check-prefix=CHECK-15 %s < %t
17// RUN: FileCheck --check-prefix=CHECK-16 %s < %t
18// RUN: FileCheck --check-prefix=CHECK-17 %s < %t
19// RUN: FileCheck --check-prefix=CHECK-18 %s < %t
20// RUN: FileCheck --check-prefix=CHECK-19 %s < %t
21// RUN: FileCheck --check-prefix=CHECK-20 %s < %t
22// RUN: FileCheck --check-prefix=CHECK-21 %s < %t
23// RUN: FileCheck --check-prefix=CHECK-22 %s < %t
24// RUN: FileCheck --check-prefix=CHECK-23 %s < %t
25// RUN: FileCheck --check-prefix=CHECK-24 %s < %t
26// RUN: FileCheck --check-prefix=CHECK-25 %s < %t
27// RUN: FileCheck --check-prefix=CHECK-26 %s < %t
28// RUN: FileCheck --check-prefix=CHECK-27 %s < %t
29// RUN: FileCheck --check-prefix=CHECK-28 %s < %t
30// RUN: FileCheck --check-prefix=CHECK-29 %s < %t
31// RUN: FileCheck --check-prefix=CHECK-30 %s < %t
32// RUN: FileCheck --check-prefix=CHECK-31 %s < %t
33// RUN: FileCheck --check-prefix=CHECK-32 %s < %t
34// RUN: FileCheck --check-prefix=CHECK-33 %s < %t
35// RUN: FileCheck --check-prefix=CHECK-34 %s < %t
36// RUN: FileCheck --check-prefix=CHECK-35 %s < %t
37// RUN: FileCheck --check-prefix=CHECK-36 %s < %t
38// RUN: FileCheck --check-prefix=CHECK-37 %s < %t
39// RUN: FileCheck --check-prefix=CHECK-38 %s < %t
40// RUN: FileCheck --check-prefix=CHECK-39 %s < %t
41// RUN: FileCheck --check-prefix=CHECK-40 %s < %t
42// RUN: FileCheck --check-prefix=CHECK-41 %s < %t
43// RUN: FileCheck --check-prefix=CHECK-42 %s < %t
Anders Carlsson824d7ea2010-02-11 08:02:13 +000044
Anders Carlsson49bac9a2010-02-13 23:40:17 +000045// For now, just verify this doesn't crash.
46namespace test0 {
47 struct Obj {};
48
49 struct Base { virtual const Obj *foo() = 0; };
50 struct Derived : Base { virtual Obj *foo() { return new Obj(); } };
51
52 void test(Derived *D) { D->foo(); }
53}
54
55namespace Test1 {
Douglas Gregor6fb745b2010-05-13 16:44:06 +000056// CHECK-1: Vtable for 'Test1::A' (3 entries).
57// CHECK-1-NEXT: 0 | offset_to_top (0)
58// CHECK-1-NEXT: 1 | Test1::A RTTI
59// CHECK-1-NEXT: -- (Test1::A, 0) vtable address --
60// CHECK-1-NEXT: 2 | void Test1::A::f()
Anders Carlsson824d7ea2010-02-11 08:02:13 +000061struct A {
62 virtual void f();
63};
Anders Carlsson824d7ea2010-02-11 08:02:13 +000064void A::f() { }
Anders Carlsson57071e22010-02-12 05:25:12 +000065
Anders Carlsson824d7ea2010-02-11 08:02:13 +000066}
67
Anders Carlsson848fa642010-02-11 18:20:28 +000068namespace Test2 {
69
70// This is a smoke test of the vtable dumper.
Douglas Gregor6fb745b2010-05-13 16:44:06 +000071// CHECK-2: Vtable for 'Test2::A' (9 entries).
72// CHECK-2-NEXT: 0 | offset_to_top (0)
73// CHECK-2-NEXT: 1 | Test2::A RTTI
74// CHECK-2-NEXT: -- (Test2::A, 0) vtable address --
75// CHECK-2-NEXT: 2 | void Test2::A::f()
76// CHECK-2-NEXT: 3 | void Test2::A::f() const
77// CHECK-2-NEXT: 4 | Test2::A *Test2::A::g(int)
78// CHECK-2-NEXT: 5 | Test2::A::~A() [complete]
79// CHECK-2-NEXT: 6 | Test2::A::~A() [deleting]
80// CHECK-2-NEXT: 7 | void Test2::A::h()
81// CHECK-2-NEXT: 8 | Test2::A &Test2::A::operator=(Test2::A const &)
Anders Carlsson848fa642010-02-11 18:20:28 +000082struct A {
83 virtual void f();
84 virtual void f() const;
85
86 virtual A* g(int a);
87 virtual ~A();
88 virtual void h();
Anders Carlssonbac72712010-02-11 18:21:49 +000089 virtual A& operator=(const A&);
Anders Carlsson848fa642010-02-11 18:20:28 +000090};
Anders Carlsson848fa642010-02-11 18:20:28 +000091void A::f() { }
92
Anders Carlsson98241422010-02-12 02:38:13 +000093// Another simple vtable dumper test.
Anders Carlsson57071e22010-02-12 05:25:12 +000094
Douglas Gregor6fb745b2010-05-13 16:44:06 +000095// CHECK-3: Vtable for 'Test2::B' (6 entries).
96// CHECK-3-NEXT: 0 | offset_to_top (0)
97// CHECK-3-NEXT: 1 | Test2::B RTTI
98// CHECK-3-NEXT: -- (Test2::B, 0) vtable address --
99// CHECK-3-NEXT: 2 | void Test2::B::f()
100// CHECK-3-NEXT: 3 | void Test2::B::g() [pure]
101// CHECK-3-NEXT: 4 | Test2::B::~B() [complete] [pure]
102// CHECK-3-NEXT: 5 | Test2::B::~B() [deleting] [pure]
Anders Carlsson98241422010-02-12 02:38:13 +0000103struct B {
104 virtual void f();
105 virtual void g() = 0;
106 virtual ~B() = 0;
107};
Anders Carlsson98241422010-02-12 02:38:13 +0000108void B::f() { }
109
Anders Carlsson848fa642010-02-11 18:20:28 +0000110}
Anders Carlsson57071e22010-02-12 05:25:12 +0000111
112namespace Test3 {
113
114// If a function in a derived class overrides a function in a primary base,
115// then the function should not have an entry in the derived class (unless the return
116// value requires adjusting).
117
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000118// CHECK-4: Vtable for 'Test3::A' (3 entries).
119// CHECK-4-NEXT: 0 | offset_to_top (0)
120// CHECK-4-NEXT: 1 | Test3::A RTTI
121// CHECK-4-NEXT: -- (Test3::A, 0) vtable address --
122// CHECK-4-NEXT: 2 | void Test3::A::f()
Anders Carlsson57071e22010-02-12 05:25:12 +0000123struct A {
124 virtual void f();
125};
126void A::f() { }
127
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000128// CHECK-5: Vtable for 'Test3::B' (4 entries).
129// CHECK-5-NEXT: 0 | offset_to_top (0)
130// CHECK-5-NEXT: 1 | Test3::B RTTI
131// CHECK-5-NEXT: -- (Test3::A, 0) vtable address --
132// CHECK-5-NEXT: -- (Test3::B, 0) vtable address --
133// CHECK-5-NEXT: 2 | void Test3::B::f()
134// CHECK-5-NEXT: 3 | void Test3::B::g()
Anders Carlsson57071e22010-02-12 05:25:12 +0000135struct B : A {
136 virtual void f();
137 virtual void g();
138};
139void B::f() { }
140
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000141// CHECK-6: Vtable for 'Test3::C' (5 entries).
142// CHECK-6-NEXT: 0 | offset_to_top (0)
143// CHECK-6-NEXT: 1 | Test3::C RTTI
144// CHECK-6-NEXT: -- (Test3::A, 0) vtable address --
145// CHECK-6-NEXT: -- (Test3::C, 0) vtable address --
146// CHECK-6-NEXT: 2 | void Test3::A::f()
147// CHECK-6-NEXT: 3 | void Test3::C::g()
148// CHECK-6-NEXT: 4 | void Test3::C::h()
Anders Carlsson57071e22010-02-12 05:25:12 +0000149struct C : A {
150 virtual void g();
151 virtual void h();
152};
153void C::g() { }
154
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000155// CHECK-7: Vtable for 'Test3::D' (5 entries).
156// CHECK-7-NEXT: 0 | offset_to_top (0)
157// CHECK-7-NEXT: 1 | Test3::D RTTI
158// CHECK-7-NEXT: -- (Test3::A, 0) vtable address --
159// CHECK-7-NEXT: -- (Test3::B, 0) vtable address --
160// CHECK-7-NEXT: -- (Test3::D, 0) vtable address --
161// CHECK-7-NEXT: 2 | void Test3::D::f()
162// CHECK-7-NEXT: 3 | void Test3::D::g()
163// CHECK-7-NEXT: 4 | void Test3::D::h()
Anders Carlsson57071e22010-02-12 05:25:12 +0000164struct D : B {
165 virtual void f();
166 virtual void g();
167 virtual void h();
168};
169
170void D::f() { }
171}
John McCall96058952010-02-12 06:15:07 +0000172
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000173namespace Test4 {
174
Anders Carlsson60db0ee2010-02-13 21:07:32 +0000175// Test non-virtual result adjustments.
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000176
177struct R1 { int r1; };
178struct R2 { int r2; };
179struct R3 : R1, R2 { int r3; };
180
181struct A {
182 virtual R2 *f();
183};
184
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000185// CHECK-8: Vtable for 'Test4::B' (4 entries).
186// CHECK-8-NEXT: 0 | offset_to_top (0)
187// CHECK-8-NEXT: 1 | Test4::B RTTI
188// CHECK-8-NEXT: -- (Test4::A, 0) vtable address --
189// CHECK-8-NEXT: -- (Test4::B, 0) vtable address --
190// CHECK-8-NEXT: 2 | Test4::R3 *Test4::B::f()
191// CHECK-8-NEXT: [return adjustment: 4 non-virtual]
192// CHECK-8-NEXT: 3 | Test4::R3 *Test4::B::f()
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000193
194struct B : A {
195 virtual R3 *f();
196};
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000197R3 *B::f() { return 0; }
Anders Carlsson60db0ee2010-02-13 21:07:32 +0000198
199// Test virtual result adjustments.
200struct V1 { int v1; };
201struct V2 : virtual V1 { int v1; };
202
203struct C {
204 virtual V1 *f();
205};
206
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000207// CHECK-9: Vtable for 'Test4::D' (4 entries).
208// CHECK-9-NEXT: 0 | offset_to_top (0)
209// CHECK-9-NEXT: 1 | Test4::D RTTI
210// CHECK-9-NEXT: -- (Test4::C, 0) vtable address --
211// CHECK-9-NEXT: -- (Test4::D, 0) vtable address --
212// CHECK-9-NEXT: 2 | Test4::V2 *Test4::D::f()
213// CHECK-9-NEXT: [return adjustment: 0 non-virtual, -24 vbase offset offset]
214// CHECK-9-NEXT: 3 | Test4::V2 *Test4::D::f()
Anders Carlsson60db0ee2010-02-13 21:07:32 +0000215struct D : C {
216 virtual V2 *f();
217};
218V2 *D::f() { return 0; };
219
220// Virtual result adjustments with an additional non-virtual adjustment.
221struct V3 : virtual R3 { int r3; };
222
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000223// CHECK-10: Vtable for 'Test4::E' (4 entries).
224// CHECK-10-NEXT: 0 | offset_to_top (0)
225// CHECK-10-NEXT: 1 | Test4::E RTTI
226// CHECK-10-NEXT: -- (Test4::A, 0) vtable address --
227// CHECK-10-NEXT: -- (Test4::E, 0) vtable address --
228// CHECK-10-NEXT: 2 | Test4::V3 *Test4::E::f()
229// CHECK-10-NEXT: [return adjustment: 4 non-virtual, -24 vbase offset offset]
230// CHECK-10-NEXT: 3 | Test4::V3 *Test4::E::f()
Anders Carlsson60db0ee2010-02-13 21:07:32 +0000231
232struct E : A {
233 virtual V3 *f();
234};
235V3 *E::f() { return 0;}
236
Anders Carlsson1d05be52010-02-13 21:16:54 +0000237// Test that a pure virtual member doesn't get a thunk.
238
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000239// CHECK-11: Vtable for 'Test4::F' (5 entries).
240// CHECK-11-NEXT: 0 | offset_to_top (0)
241// CHECK-11-NEXT: 1 | Test4::F RTTI
242// CHECK-11-NEXT: -- (Test4::A, 0) vtable address --
243// CHECK-11-NEXT: -- (Test4::F, 0) vtable address --
244// CHECK-11-NEXT: 2 | Test4::R3 *Test4::F::f() [pure]
245// CHECK-11-NEXT: 3 | void Test4::F::g()
246// CHECK-11-NEXT: 4 | Test4::R3 *Test4::F::f() [pure]
Anders Carlsson1d05be52010-02-13 21:16:54 +0000247struct F : A {
248 virtual void g();
249 virtual R3 *f() = 0;
250};
Anders Carlsson1d05be52010-02-13 21:16:54 +0000251void F::g() { }
252
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000253}
254
Anders Carlsson76f1aa72010-02-13 22:05:23 +0000255namespace Test5 {
256
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000257// Simple secondary vtables without 'this' pointer adjustments.
Anders Carlsson76f1aa72010-02-13 22:05:23 +0000258struct A {
259 virtual void f();
260 virtual void g();
261 int a;
262};
263
264struct B1 : A {
265 virtual void f();
266 int b1;
267};
268
269struct B2 : A {
270 virtual void g();
271 int b2;
272};
273
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000274// CHECK-12: Vtable for 'Test5::C' (9 entries).
275// CHECK-12-NEXT: 0 | offset_to_top (0)
276// CHECK-12-NEXT: 1 | Test5::C RTTI
277// CHECK-12-NEXT: -- (Test5::A, 0) vtable address --
278// CHECK-12-NEXT: -- (Test5::B1, 0) vtable address --
279// CHECK-12-NEXT: -- (Test5::C, 0) vtable address --
280// CHECK-12-NEXT: 2 | void Test5::B1::f()
281// CHECK-12-NEXT: 3 | void Test5::A::g()
282// CHECK-12-NEXT: 4 | void Test5::C::h()
283// CHECK-12-NEXT: 5 | offset_to_top (-16)
284// CHECK-12-NEXT: 6 | Test5::C RTTI
285// CHECK-12-NEXT: -- (Test5::A, 16) vtable address --
286// CHECK-12-NEXT: -- (Test5::B2, 16) vtable address --
287// CHECK-12-NEXT: 7 | void Test5::A::f()
288// CHECK-12-NEXT: 8 | void Test5::B2::g()
Anders Carlsson76f1aa72010-02-13 22:05:23 +0000289struct C : B1, B2 {
290 virtual void h();
291};
292void C::h() { }
293}
294
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000295namespace Test6 {
John McCall96058952010-02-12 06:15:07 +0000296
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000297// Simple non-virtual 'this' pointer adjustments.
298struct A1 {
299 virtual void f();
300 int a;
301};
John McCall96058952010-02-12 06:15:07 +0000302
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000303struct A2 {
304 virtual void f();
305 int a;
306};
307
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000308// CHECK-13: Vtable for 'Test6::C' (6 entries).
309// CHECK-13-NEXT: 0 | offset_to_top (0)
310// CHECK-13-NEXT: 1 | Test6::C RTTI
311// CHECK-13-NEXT: -- (Test6::A1, 0) vtable address --
312// CHECK-13-NEXT: -- (Test6::C, 0) vtable address --
313// CHECK-13-NEXT: 2 | void Test6::C::f()
314// CHECK-13-NEXT: 3 | offset_to_top (-16)
315// CHECK-13-NEXT: 4 | Test6::C RTTI
316// CHECK-13-NEXT: -- (Test6::A2, 16) vtable address --
317// CHECK-13-NEXT: 5 | void Test6::C::f()
318// CHECK-13-NEXT: [this adjustment: -16 non-virtual]
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000319struct C : A1, A2 {
320 virtual void f();
321};
322void C::f() { }
323
Anders Carlssone67dc302010-02-14 00:16:19 +0000324}
325
326namespace Test7 {
327
328// Test that the D::f overrider for A::f have different 'this' pointer
329// adjustments in the two A base subobjects.
330
331struct A {
332 virtual void f();
333 int a;
334};
335
336struct B1 : A { };
337struct B2 : A { };
338
339struct C { virtual void c(); };
340
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000341// CHECK-14: Vtable for 'Test7::D' (10 entries).
342// CHECK-14-NEXT: 0 | offset_to_top (0)
343// CHECK-14-NEXT: 1 | Test7::D RTTI
344// CHECK-14-NEXT: -- (Test7::C, 0) vtable address --
345// CHECK-14-NEXT: -- (Test7::D, 0) vtable address --
346// CHECK-14-NEXT: 2 | void Test7::C::c()
347// CHECK-14-NEXT: 3 | void Test7::D::f()
348// CHECK-14-NEXT: 4 | offset_to_top (-8)
349// CHECK-14-NEXT: 5 | Test7::D RTTI
350// CHECK-14-NEXT: -- (Test7::A, 8) vtable address --
351// CHECK-14-NEXT: -- (Test7::B1, 8) vtable address --
352// CHECK-14-NEXT: 6 | void Test7::D::f()
353// CHECK-14-NEXT: [this adjustment: -8 non-virtual]
354// CHECK-14-NEXT: 7 | offset_to_top (-24)
355// CHECK-14-NEXT: 8 | Test7::D RTTI
356// CHECK-14-NEXT: -- (Test7::A, 24) vtable address --
357// CHECK-14-NEXT: -- (Test7::B2, 24) vtable address --
358// CHECK-14-NEXT: 9 | void Test7::D::f()
359// CHECK-14-NEXT: [this adjustment: -24 non-virtual]
Anders Carlssone67dc302010-02-14 00:16:19 +0000360struct D : C, B1, B2 {
361 virtual void f();
362};
363void D::f() { }
364
365}
Anders Carlssonb828afa2010-02-14 17:05:59 +0000366
367namespace Test8 {
368
369// Test that we don't try to layout vtables for classes that don't have
370// virtual bases or virtual member functions.
371
372struct A { };
373
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000374// CHECK-15: Vtable for 'Test8::B' (3 entries).
375// CHECK-15-NEXT: 0 | offset_to_top (0)
376// CHECK-15-NEXT: 1 | Test8::B RTTI
377// CHECK-15-NEXT: -- (Test8::B, 0) vtable address --
378// CHECK-15-NEXT: 2 | void Test8::B::f()
Anders Carlssonb828afa2010-02-14 17:05:59 +0000379struct B : A {
380 virtual void f();
381};
382void B::f() { }
383
384}
Anders Carlsson852213e2010-02-16 04:59:55 +0000385
386namespace Test9 {
387
388// Simple test of vbase offsets.
389
390struct A1 { int a1; };
391struct A2 { int a2; };
392
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000393// CHECK-16: Vtable for 'Test9::B' (5 entries).
394// CHECK-16-NEXT: 0 | vbase_offset (16)
395// CHECK-16-NEXT: 1 | vbase_offset (12)
396// CHECK-16-NEXT: 2 | offset_to_top (0)
397// CHECK-16-NEXT: 3 | Test9::B RTTI
398// CHECK-16-NEXT: -- (Test9::B, 0) vtable address --
399// CHECK-16-NEXT: 4 | void Test9::B::f()
Anders Carlsson852213e2010-02-16 04:59:55 +0000400struct B : virtual A1, virtual A2 {
401 int b;
402
403 virtual void f();
404};
405
406
407void B::f() { }
408
409}
Anders Carlssonc7b63162010-02-16 16:02:57 +0000410
411namespace Test10 {
412
413// Test for a bug where we would not emit secondary vtables for bases
414// of a primary base.
415struct A1 { virtual void a1(); };
416struct A2 { virtual void a2(); };
417
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000418// CHECK-17: Vtable for 'Test10::C' (7 entries).
419// CHECK-17-NEXT: 0 | offset_to_top (0)
420// CHECK-17-NEXT: 1 | Test10::C RTTI
421// CHECK-17-NEXT: -- (Test10::A1, 0) vtable address --
422// CHECK-17-NEXT: -- (Test10::B, 0) vtable address --
423// CHECK-17-NEXT: -- (Test10::C, 0) vtable address --
424// CHECK-17-NEXT: 2 | void Test10::A1::a1()
425// CHECK-17-NEXT: 3 | void Test10::C::f()
426// CHECK-17-NEXT: 4 | offset_to_top (-8)
427// CHECK-17-NEXT: 5 | Test10::C RTTI
428// CHECK-17-NEXT: -- (Test10::A2, 8) vtable address --
429// CHECK-17-NEXT: 6 | void Test10::A2::a2()
Anders Carlssonc7b63162010-02-16 16:02:57 +0000430struct B : A1, A2 {
431 int b;
432};
433
434struct C : B {
435 virtual void f();
436};
437void C::f() { }
438
439}
Anders Carlsson69dc04e2010-02-16 16:49:35 +0000440
441namespace Test11 {
442
443// Very simple test of vtables for virtual bases.
444struct A1 { int a; };
445struct A2 { int b; };
446
447struct B : A1, virtual A2 {
448 int b;
449};
450
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000451// CHECK-18: Vtable for 'Test11::C' (8 entries).
452// CHECK-18-NEXT: 0 | vbase_offset (24)
453// CHECK-18-NEXT: 1 | vbase_offset (8)
454// CHECK-18-NEXT: 2 | offset_to_top (0)
455// CHECK-18-NEXT: 3 | Test11::C RTTI
456// CHECK-18-NEXT: -- (Test11::C, 0) vtable address --
457// CHECK-18-NEXT: 4 | void Test11::C::f()
458// CHECK-18-NEXT: 5 | vbase_offset (16)
459// CHECK-18-NEXT: 6 | offset_to_top (-8)
460// CHECK-18-NEXT: 7 | Test11::C RTTI
Anders Carlsson69dc04e2010-02-16 16:49:35 +0000461struct C : virtual B {
462 virtual void f();
463};
464void C::f() { }
465
466}
Anders Carlsson92f54322010-02-23 03:26:17 +0000467
468namespace Test12 {
469
470// Test that the right vcall offsets are generated in the right order.
471
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000472// CHECK-19: Vtable for 'Test12::B' (19 entries).
473// CHECK-19-NEXT: 0 | vbase_offset (8)
474// CHECK-19-NEXT: 1 | offset_to_top (0)
475// CHECK-19-NEXT: 2 | Test12::B RTTI
476// CHECK-19-NEXT: -- (Test12::B, 0) vtable address --
477// CHECK-19-NEXT: 3 | void Test12::B::f()
478// CHECK-19-NEXT: 4 | void Test12::B::a()
479// CHECK-19-NEXT: 5 | vcall_offset (32)
480// CHECK-19-NEXT: 6 | vcall_offset (16)
481// CHECK-19-NEXT: 7 | vcall_offset (-8)
482// CHECK-19-NEXT: 8 | vcall_offset (0)
483// CHECK-19-NEXT: 9 | offset_to_top (-8)
484// CHECK-19-NEXT: 10 | Test12::B RTTI
485// CHECK-19-NEXT: -- (Test12::A, 8) vtable address --
486// CHECK-19-NEXT: -- (Test12::A1, 8) vtable address --
487// CHECK-19-NEXT: 11 | void Test12::A1::a1()
488// CHECK-19-NEXT: 12 | void Test12::B::a()
489// CHECK-19-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
490// CHECK-19-NEXT: 13 | offset_to_top (-24)
491// CHECK-19-NEXT: 14 | Test12::B RTTI
492// CHECK-19-NEXT: -- (Test12::A2, 24) vtable address --
493// CHECK-19-NEXT: 15 | void Test12::A2::a2()
494// CHECK-19-NEXT: 16 | offset_to_top (-40)
495// CHECK-19-NEXT: 17 | Test12::B RTTI
496// CHECK-19-NEXT: -- (Test12::A3, 40) vtable address --
497// CHECK-19-NEXT: 18 | void Test12::A3::a3()
Anders Carlsson92f54322010-02-23 03:26:17 +0000498struct A1 {
499 virtual void a1();
500 int a;
501};
502
503struct A2 {
504 virtual void a2();
505 int a;
506};
507
508struct A3 {
509 virtual void a3();
510 int a;
511};
512
513struct A : A1, A2, A3 {
514 virtual void a();
515 int i;
516};
517
518struct B : virtual A {
519 virtual void f();
520
521 virtual void a();
522};
523void B::f() { }
524
525}
Anders Carlssonaf280c02010-02-23 03:48:14 +0000526
527namespace Test13 {
528
529// Test that we don't try to emit a vtable for 'A' twice.
530struct A {
531 virtual void f();
532};
533
534struct B : virtual A {
535 virtual void f();
536};
537
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000538// CHECK-20: Vtable for 'Test13::C' (6 entries).
539// CHECK-20-NEXT: 0 | vbase_offset (0)
540// CHECK-20-NEXT: 1 | vbase_offset (0)
541// CHECK-20-NEXT: 2 | vcall_offset (0)
542// CHECK-20-NEXT: 3 | offset_to_top (0)
543// CHECK-20-NEXT: 4 | Test13::C RTTI
544// CHECK-20-NEXT: -- (Test13::A, 0) vtable address --
545// CHECK-20-NEXT: -- (Test13::B, 0) vtable address --
546// CHECK-20-NEXT: -- (Test13::C, 0) vtable address --
547// CHECK-20-NEXT: 5 | void Test13::C::f()
Anders Carlssonaf280c02010-02-23 03:48:14 +0000548struct C : virtual B, virtual A {
549 virtual void f();
550};
551void C::f() { }
552
553}
554
Anders Carlssonbf554f62010-02-25 22:18:35 +0000555namespace Test14 {
556
557// Verify that we handle A being a non-virtual base of B, which is a virtual base.
558
559struct A {
560 virtual void f();
561};
562
563struct B : A { };
564
565struct C : virtual B { };
566
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000567// CHECK-21: Vtable for 'Test14::D' (5 entries).
568// CHECK-21-NEXT: 0 | vbase_offset (0)
569// CHECK-21-NEXT: 1 | vcall_offset (0)
570// CHECK-21-NEXT: 2 | offset_to_top (0)
571// CHECK-21-NEXT: 3 | Test14::D RTTI
572// CHECK-21-NEXT: -- (Test14::A, 0) vtable address --
573// CHECK-21-NEXT: -- (Test14::B, 0) vtable address --
574// CHECK-21-NEXT: -- (Test14::C, 0) vtable address --
575// CHECK-21-NEXT: -- (Test14::D, 0) vtable address --
576// CHECK-21-NEXT: 4 | void Test14::D::f()
Anders Carlssonbf554f62010-02-25 22:18:35 +0000577struct D : C, virtual B {
578 virtual void f();
579};
580void D::f() { }
581
582}
583
Anders Carlsson08c26752010-02-27 04:05:52 +0000584namespace Test15 {
585
586// Test that we don't emit an extra vtable for B since it's a primary base of C.
587struct A { virtual void a(); };
588struct B { virtual void b(); };
589
590struct C : virtual B { };
591
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000592// CHECK-22: Vtable for 'Test15::D' (11 entries).
593// CHECK-22-NEXT: 0 | vbase_offset (8)
594// CHECK-22-NEXT: 1 | vbase_offset (8)
595// CHECK-22-NEXT: 2 | offset_to_top (0)
596// CHECK-22-NEXT: 3 | Test15::D RTTI
597// CHECK-22-NEXT: -- (Test15::A, 0) vtable address --
598// CHECK-22-NEXT: -- (Test15::D, 0) vtable address --
599// CHECK-22-NEXT: 4 | void Test15::A::a()
600// CHECK-22-NEXT: 5 | void Test15::D::f()
601// CHECK-22-NEXT: 6 | vbase_offset (0)
602// CHECK-22-NEXT: 7 | vcall_offset (0)
603// CHECK-22-NEXT: 8 | offset_to_top (-8)
604// CHECK-22-NEXT: 9 | Test15::D RTTI
605// CHECK-22-NEXT: -- (Test15::B, 8) vtable address --
606// CHECK-22-NEXT: -- (Test15::C, 8) vtable address --
607// CHECK-22-NEXT: 10 | void Test15::B::b()
Anders Carlsson08c26752010-02-27 04:05:52 +0000608struct D : A, virtual B, virtual C {
609 virtual void f();
610};
611void D::f() { }
612
613}
Anders Carlsson55609692010-02-27 04:12:52 +0000614
615namespace Test16 {
616
617// Test that destructors share vcall offsets.
618
619struct A { virtual ~A(); };
620struct B { virtual ~B(); };
621
622struct C : A, B { virtual ~C(); };
623
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000624// CHECK-23: Vtable for 'Test16::D' (15 entries).
625// CHECK-23-NEXT: 0 | vbase_offset (8)
626// CHECK-23-NEXT: 1 | offset_to_top (0)
627// CHECK-23-NEXT: 2 | Test16::D RTTI
628// CHECK-23-NEXT: -- (Test16::D, 0) vtable address --
629// CHECK-23-NEXT: 3 | void Test16::D::f()
630// CHECK-23-NEXT: 4 | Test16::D::~D() [complete]
631// CHECK-23-NEXT: 5 | Test16::D::~D() [deleting]
632// CHECK-23-NEXT: 6 | vcall_offset (-8)
633// CHECK-23-NEXT: 7 | offset_to_top (-8)
634// CHECK-23-NEXT: 8 | Test16::D RTTI
635// CHECK-23-NEXT: -- (Test16::A, 8) vtable address --
636// CHECK-23-NEXT: -- (Test16::C, 8) vtable address --
637// CHECK-23-NEXT: 9 | Test16::D::~D() [complete]
638// CHECK-23-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
639// CHECK-23-NEXT: 10 | Test16::D::~D() [deleting]
640// CHECK-23-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
641// CHECK-23-NEXT: 11 | offset_to_top (-16)
642// CHECK-23-NEXT: 12 | Test16::D RTTI
643// CHECK-23-NEXT: -- (Test16::B, 16) vtable address --
644// CHECK-23-NEXT: 13 | Test16::D::~D() [complete]
645// CHECK-23-NEXT: [this adjustment: -8 non-virtual, -24 vcall offset offset]
646// CHECK-23-NEXT: 14 | Test16::D::~D() [deleting]
647// CHECK-23-NEXT: [this adjustment: -8 non-virtual, -24 vcall offset offset]
Anders Carlsson55609692010-02-27 04:12:52 +0000648struct D : virtual C {
649 virtual void f();
650};
651void D::f() { }
652
653}
Anders Carlssonc784ba22010-02-27 06:38:03 +0000654
655namespace Test17 {
656
657// Test that we don't mark E::f in the C-in-E vtable as unused.
658struct A { virtual void f(); };
659struct B : virtual A { virtual void f(); };
660struct C : virtual A { virtual void f(); };
661struct D : virtual B, virtual C { virtual void f(); };
662
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000663// CHECK-24: Vtable for 'Test17::E' (13 entries).
664// CHECK-24-NEXT: 0 | vbase_offset (0)
665// CHECK-24-NEXT: 1 | vbase_offset (8)
666// CHECK-24-NEXT: 2 | vbase_offset (0)
667// CHECK-24-NEXT: 3 | vbase_offset (0)
668// CHECK-24-NEXT: 4 | vcall_offset (0)
669// CHECK-24-NEXT: 5 | offset_to_top (0)
670// CHECK-24-NEXT: 6 | Test17::E RTTI
671// CHECK-24-NEXT: -- (Test17::A, 0) vtable address --
672// CHECK-24-NEXT: -- (Test17::B, 0) vtable address --
673// CHECK-24-NEXT: -- (Test17::D, 0) vtable address --
674// CHECK-24-NEXT: -- (Test17::E, 0) vtable address --
675// CHECK-24-NEXT: 7 | void Test17::E::f()
676// CHECK-24-NEXT: 8 | vbase_offset (-8)
677// CHECK-24-NEXT: 9 | vcall_offset (-8)
678// CHECK-24-NEXT: 10 | offset_to_top (-8)
679// CHECK-24-NEXT: 11 | Test17::E RTTI
680// CHECK-24-NEXT: -- (Test17::C, 8) vtable address --
681// CHECK-24-NEXT: 12 | void Test17::E::f()
682// CHECK-24-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
Anders Carlssonc784ba22010-02-27 06:38:03 +0000683class E : virtual D {
684 virtual void f();
685};
686void E::f() {}
687
688}
Anders Carlsson2ef9d6b2010-02-27 16:52:49 +0000689
690namespace Test18 {
691
692// Test that we compute the right 'this' adjustment offsets.
693
694struct A {
695 virtual void f();
696 virtual void g();
697};
698
699struct B : virtual A {
700 virtual void f();
701};
702
703struct C : A, B {
704 virtual void g();
705};
706
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000707// CHECK-25: Vtable for 'Test18::D' (24 entries).
708// CHECK-25-NEXT: 0 | vbase_offset (8)
709// CHECK-25-NEXT: 1 | vbase_offset (0)
710// CHECK-25-NEXT: 2 | vbase_offset (0)
711// CHECK-25-NEXT: 3 | vcall_offset (8)
712// CHECK-25-NEXT: 4 | vcall_offset (0)
713// CHECK-25-NEXT: 5 | offset_to_top (0)
714// CHECK-25-NEXT: 6 | Test18::D RTTI
715// CHECK-25-NEXT: -- (Test18::A, 0) vtable address --
716// CHECK-25-NEXT: -- (Test18::B, 0) vtable address --
717// CHECK-25-NEXT: -- (Test18::D, 0) vtable address --
718// CHECK-25-NEXT: 7 | void Test18::D::f()
719// CHECK-25-NEXT: 8 | void Test18::C::g()
720// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
721// CHECK-25-NEXT: 9 | void Test18::D::h()
722// CHECK-25-NEXT: 10 | vcall_offset (0)
723// CHECK-25-NEXT: 11 | vcall_offset (-8)
724// CHECK-25-NEXT: 12 | vbase_offset (-8)
725// CHECK-25-NEXT: 13 | offset_to_top (-8)
726// CHECK-25-NEXT: 14 | Test18::D RTTI
727// CHECK-25-NEXT: -- (Test18::A, 8) vtable address --
728// CHECK-25-NEXT: -- (Test18::C, 8) vtable address --
729// CHECK-25-NEXT: 15 | void Test18::D::f()
730// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
731// CHECK-25-NEXT: 16 | void Test18::C::g()
732// CHECK-25-NEXT: 17 | vbase_offset (-16)
733// CHECK-25-NEXT: 18 | vcall_offset (-8)
734// CHECK-25-NEXT: 19 | vcall_offset (-16)
735// CHECK-25-NEXT: 20 | offset_to_top (-16)
736// CHECK-25-NEXT: 21 | Test18::D RTTI
737// CHECK-25-NEXT: -- (Test18::B, 16) vtable address --
738// CHECK-25-NEXT: 22 | void Test18::D::f()
739// CHECK-25-NEXT: [this adjustment: -8 non-virtual, -32 vcall offset offset]
740// CHECK-25-NEXT: 23 | [unused] void Test18::C::g()
Anders Carlsson2bc1d3a2010-03-10 21:25:37 +0000741
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000742// CHECK-25: Construction vtable for ('Test18::B', 0) in 'Test18::D' (7 entries).
743// CHECK-25-NEXT: 0 | vbase_offset (0)
744// CHECK-25-NEXT: 1 | vcall_offset (0)
745// CHECK-25-NEXT: 2 | vcall_offset (0)
746// CHECK-25-NEXT: 3 | offset_to_top (0)
747// CHECK-25-NEXT: 4 | Test18::B RTTI
748// CHECK-25-NEXT: -- (Test18::A, 0) vtable address --
749// CHECK-25-NEXT: -- (Test18::B, 0) vtable address --
750// CHECK-25-NEXT: 5 | void Test18::B::f()
751// CHECK-25-NEXT: 6 | void Test18::A::g()
Anders Carlsson2bc1d3a2010-03-10 21:25:37 +0000752
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000753// CHECK-25: Construction vtable for ('Test18::C', 8) in 'Test18::D' (20 entries).
754// CHECK-25-NEXT: 0 | vcall_offset (0)
755// CHECK-25-NEXT: 1 | vcall_offset (0)
756// CHECK-25-NEXT: 2 | vbase_offset (-8)
757// CHECK-25-NEXT: 3 | offset_to_top (0)
758// CHECK-25-NEXT: 4 | Test18::C RTTI
759// CHECK-25-NEXT: -- (Test18::A, 8) vtable address --
760// CHECK-25-NEXT: -- (Test18::C, 8) vtable address --
761// CHECK-25-NEXT: 5 | void Test18::A::f()
762// CHECK-25-NEXT: 6 | void Test18::C::g()
763// CHECK-25-NEXT: 7 | vbase_offset (-16)
764// CHECK-25-NEXT: 8 | vcall_offset (-8)
765// CHECK-25-NEXT: 9 | vcall_offset (0)
766// CHECK-25-NEXT: 10 | offset_to_top (-8)
767// CHECK-25-NEXT: 11 | Test18::C RTTI
768// CHECK-25-NEXT: -- (Test18::B, 16) vtable address --
769// CHECK-25-NEXT: 12 | void Test18::B::f()
770// CHECK-25-NEXT: 13 | [unused] void Test18::C::g()
771// CHECK-25-NEXT: 14 | vcall_offset (8)
772// CHECK-25-NEXT: 15 | vcall_offset (16)
773// CHECK-25-NEXT: 16 | offset_to_top (8)
774// CHECK-25-NEXT: 17 | Test18::C RTTI
775// CHECK-25-NEXT: -- (Test18::A, 0) vtable address --
776// CHECK-25-NEXT: 18 | void Test18::B::f()
777// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
778// CHECK-25-NEXT: 19 | void Test18::C::g()
779// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
Anders Carlsson2bc1d3a2010-03-10 21:25:37 +0000780
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000781// CHECK-25: Construction vtable for ('Test18::B', 16) in 'Test18::D' (13 entries).
782// CHECK-25-NEXT: 0 | vbase_offset (-16)
783// CHECK-25-NEXT: 1 | vcall_offset (-16)
784// CHECK-25-NEXT: 2 | vcall_offset (0)
785// CHECK-25-NEXT: 3 | offset_to_top (0)
786// CHECK-25-NEXT: 4 | Test18::B RTTI
787// CHECK-25-NEXT: -- (Test18::B, 16) vtable address --
788// CHECK-25-NEXT: 5 | void Test18::B::f()
789// CHECK-25-NEXT: 6 | [unused] void Test18::A::g()
790// CHECK-25-NEXT: 7 | vcall_offset (0)
791// CHECK-25-NEXT: 8 | vcall_offset (16)
792// CHECK-25-NEXT: 9 | offset_to_top (16)
793// CHECK-25-NEXT: 10 | Test18::B RTTI
794// CHECK-25-NEXT: -- (Test18::A, 0) vtable address --
795// CHECK-25-NEXT: 11 | void Test18::B::f()
796// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
797// CHECK-25-NEXT: 12 | void Test18::A::g()
Anders Carlsson2ef9d6b2010-02-27 16:52:49 +0000798struct D : virtual B, virtual C, virtual A
799{
800 virtual void f();
801 virtual void h();
802};
803void D::f() {}
804
Anders Carlsson35044752010-02-27 16:55:58 +0000805}
806
807namespace Test19 {
808
809// Another 'this' adjustment test.
810
811struct A {
812 int a;
813
814 virtual void f();
815};
816
817struct B : A {
818 int b;
819
820 virtual void g();
821};
822
823struct C {
824 virtual void c();
825};
826
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000827// CHECK-26: Vtable for 'Test19::D' (13 entries).
828// CHECK-26-NEXT: 0 | vbase_offset (24)
829// CHECK-26-NEXT: 1 | offset_to_top (0)
830// CHECK-26-NEXT: 2 | Test19::D RTTI
831// CHECK-26-NEXT: -- (Test19::C, 0) vtable address --
832// CHECK-26-NEXT: -- (Test19::D, 0) vtable address --
833// CHECK-26-NEXT: 3 | void Test19::C::c()
834// CHECK-26-NEXT: 4 | void Test19::D::f()
835// CHECK-26-NEXT: 5 | offset_to_top (-8)
836// CHECK-26-NEXT: 6 | Test19::D RTTI
837// CHECK-26-NEXT: -- (Test19::A, 8) vtable address --
838// CHECK-26-NEXT: -- (Test19::B, 8) vtable address --
839// CHECK-26-NEXT: 7 | void Test19::D::f()
840// CHECK-26-NEXT: [this adjustment: -8 non-virtual]
841// CHECK-26-NEXT: 8 | void Test19::B::g()
842// CHECK-26-NEXT: 9 | vcall_offset (-24)
843// CHECK-26-NEXT: 10 | offset_to_top (-24)
844// CHECK-26-NEXT: 11 | Test19::D RTTI
845// CHECK-26-NEXT: -- (Test19::A, 24) vtable address --
846// CHECK-26-NEXT: 12 | void Test19::D::f()
847// CHECK-26-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
Anders Carlsson35044752010-02-27 16:55:58 +0000848struct D : C, B, virtual A {
849 virtual void f();
850};
851void D::f() { }
852
Anders Carlsson8bc68f72010-02-27 18:16:50 +0000853}
854
855namespace Test20 {
856
857// pure virtual member functions should never have 'this' adjustments.
858
859struct A {
860 virtual void f() = 0;
861 virtual void g();
862};
863
864struct B : A { };
865
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000866// CHECK-27: Vtable for 'Test20::C' (9 entries).
867// CHECK-27-NEXT: 0 | offset_to_top (0)
868// CHECK-27-NEXT: 1 | Test20::C RTTI
869// CHECK-27-NEXT: -- (Test20::A, 0) vtable address --
870// CHECK-27-NEXT: -- (Test20::C, 0) vtable address --
871// CHECK-27-NEXT: 2 | void Test20::C::f() [pure]
872// CHECK-27-NEXT: 3 | void Test20::A::g()
873// CHECK-27-NEXT: 4 | void Test20::C::h()
874// CHECK-27-NEXT: 5 | offset_to_top (-8)
875// CHECK-27-NEXT: 6 | Test20::C RTTI
876// CHECK-27-NEXT: -- (Test20::A, 8) vtable address --
877// CHECK-27-NEXT: -- (Test20::B, 8) vtable address --
878// CHECK-27-NEXT: 7 | void Test20::C::f() [pure]
879// CHECK-27-NEXT: 8 | void Test20::A::g()
Anders Carlsson8bc68f72010-02-27 18:16:50 +0000880struct C : A, B {
881 virtual void f() = 0;
882 virtual void h();
883};
884void C::h() { }
885
886}
Anders Carlsson6a8c5b22010-02-27 19:21:58 +0000887
888namespace Test21 {
889
890// Test that we get vbase offsets right in secondary vtables.
891struct A {
892 virtual void f();
893};
894
895struct B : virtual A { };
896class C : virtual B { };
897class D : virtual C { };
898
899class E : virtual C { };
900
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000901// CHECK-28: Vtable for 'Test21::F' (16 entries).
902// CHECK-28-NEXT: 0 | vbase_offset (8)
903// CHECK-28-NEXT: 1 | vbase_offset (0)
904// CHECK-28-NEXT: 2 | vbase_offset (0)
905// CHECK-28-NEXT: 3 | vbase_offset (0)
906// CHECK-28-NEXT: 4 | vbase_offset (0)
907// CHECK-28-NEXT: 5 | vcall_offset (0)
908// CHECK-28-NEXT: 6 | offset_to_top (0)
909// CHECK-28-NEXT: 7 | Test21::F RTTI
910// CHECK-28-NEXT: -- (Test21::A, 0) vtable address --
911// CHECK-28-NEXT: -- (Test21::B, 0) vtable address --
912// CHECK-28-NEXT: -- (Test21::C, 0) vtable address --
913// CHECK-28-NEXT: -- (Test21::D, 0) vtable address --
914// CHECK-28-NEXT: -- (Test21::F, 0) vtable address --
915// CHECK-28-NEXT: 8 | void Test21::F::f()
916// CHECK-28-NEXT: 9 | vbase_offset (-8)
917// CHECK-28-NEXT: 10 | vbase_offset (-8)
918// CHECK-28-NEXT: 11 | vbase_offset (-8)
919// CHECK-28-NEXT: 12 | vcall_offset (-8)
920// CHECK-28-NEXT: 13 | offset_to_top (-8)
921// CHECK-28-NEXT: 14 | Test21::F RTTI
922// CHECK-28-NEXT: -- (Test21::E, 8) vtable address --
923// CHECK-28-NEXT: 15 | [unused] void Test21::F::f()
Anders Carlsson127e4672010-03-11 06:44:31 +0000924//
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000925// CHECK-28: Virtual base offset offsets for 'Test21::F' (5 entries).
926// CHECK-28-NEXT: Test21::A | -32
927// CHECK-28-NEXT: Test21::B | -40
928// CHECK-28-NEXT: Test21::C | -48
929// CHECK-28-NEXT: Test21::D | -56
930// CHECK-28-NEXT: Test21::E | -64
Anders Carlsson6a8c5b22010-02-27 19:21:58 +0000931class F : virtual D, virtual E {
932 virtual void f();
933};
934void F::f() { }
935
936}
Anders Carlsson0041a642010-02-27 21:09:00 +0000937
938namespace Test22 {
939
940// Very simple construction vtable test.
941struct V1 {
942 int v1;
943};
944
945struct V2 : virtual V1 {
946 int v2;
947};
948
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000949// CHECK-29: Vtable for 'Test22::C' (8 entries).
950// CHECK-29-NEXT: 0 | vbase_offset (16)
951// CHECK-29-NEXT: 1 | vbase_offset (12)
952// CHECK-29-NEXT: 2 | offset_to_top (0)
953// CHECK-29-NEXT: 3 | Test22::C RTTI
954// CHECK-29-NEXT: -- (Test22::C, 0) vtable address --
955// CHECK-29-NEXT: 4 | void Test22::C::f()
956// CHECK-29-NEXT: 5 | vbase_offset (-4)
957// CHECK-29-NEXT: 6 | offset_to_top (-16)
958// CHECK-29-NEXT: 7 | Test22::C RTTI
959// CHECK-29-NEXT: -- (Test22::V2, 16) vtable address --
Anders Carlsson0041a642010-02-27 21:09:00 +0000960
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000961// CHECK-29: Construction vtable for ('Test22::V2', 16) in 'Test22::C' (3 entries).
962// CHECK-29-NEXT: 0 | vbase_offset (-4)
963// CHECK-29-NEXT: 1 | offset_to_top (0)
964// CHECK-29-NEXT: 2 | Test22::V2 RTTI
Anders Carlsson0041a642010-02-27 21:09:00 +0000965
966struct C : virtual V1, virtual V2 {
967 int c;
968 virtual void f();
969};
970void C::f() { }
971
972}
Anders Carlsson530c40c2010-02-28 01:43:58 +0000973
974namespace Test23 {
975
976struct A {
977 int a;
978};
979
980struct B : virtual A {
981 int b;
982};
983
984struct C : A, virtual B {
985 int c;
986};
987
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000988// CHECK-30: Vtable for 'Test23::D' (7 entries).
989// CHECK-30-NEXT: 0 | vbase_offset (20)
990// CHECK-30-NEXT: 1 | vbase_offset (24)
991// CHECK-30-NEXT: 2 | offset_to_top (0)
992// CHECK-30-NEXT: 3 | Test23::D RTTI
993// CHECK-30-NEXT: -- (Test23::C, 0) vtable address --
994// CHECK-30-NEXT: -- (Test23::D, 0) vtable address --
995// CHECK-30-NEXT: 4 | vbase_offset (-4)
996// CHECK-30-NEXT: 5 | offset_to_top (-24)
997// CHECK-30-NEXT: 6 | Test23::D RTTI
998// CHECK-30-NEXT: -- (Test23::B, 24) vtable address --
Anders Carlsson530c40c2010-02-28 01:43:58 +0000999
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001000// CHECK-30: Construction vtable for ('Test23::C', 0) in 'Test23::D' (7 entries).
1001// CHECK-30-NEXT: 0 | vbase_offset (20)
1002// CHECK-30-NEXT: 1 | vbase_offset (24)
1003// CHECK-30-NEXT: 2 | offset_to_top (0)
1004// CHECK-30-NEXT: 3 | Test23::C RTTI
1005// CHECK-30-NEXT: -- (Test23::C, 0) vtable address --
1006// CHECK-30-NEXT: 4 | vbase_offset (-4)
1007// CHECK-30-NEXT: 5 | offset_to_top (-24)
1008// CHECK-30-NEXT: 6 | Test23::C RTTI
1009// CHECK-30-NEXT: -- (Test23::B, 24) vtable address --
Anders Carlsson530c40c2010-02-28 01:43:58 +00001010
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001011// CHECK-30: Construction vtable for ('Test23::B', 24) in 'Test23::D' (3 entries).
1012// CHECK-30-NEXT: 0 | vbase_offset (-4)
1013// CHECK-30-NEXT: 1 | offset_to_top (0)
1014// CHECK-30-NEXT: 2 | Test23::B RTTI
1015// CHECK-30-NEXT: -- (Test23::B, 24) vtable address --
Anders Carlsson530c40c2010-02-28 01:43:58 +00001016
1017struct D : virtual A, virtual B, C {
1018 int d;
1019
1020 void f();
1021};
1022void D::f() { }
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001023 D d;
Anders Carlsson530c40c2010-02-28 01:43:58 +00001024}
Anders Carlsson293126b2010-02-28 17:59:36 +00001025
1026namespace Test24 {
1027
1028// Another construction vtable test.
1029
Anders Carlsson0378bf02010-02-28 18:08:38 +00001030struct A {
1031 virtual void f();
1032};
1033
1034struct B : virtual A { };
1035struct C : virtual A { };
1036
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001037// CHECK-31: Vtable for 'Test24::D' (10 entries).
1038// CHECK-31-NEXT: 0 | vbase_offset (0)
1039// CHECK-31-NEXT: 1 | vcall_offset (0)
1040// CHECK-31-NEXT: 2 | offset_to_top (0)
1041// CHECK-31-NEXT: 3 | Test24::D RTTI
1042// CHECK-31-NEXT: -- (Test24::A, 0) vtable address --
1043// CHECK-31-NEXT: -- (Test24::B, 0) vtable address --
1044// CHECK-31-NEXT: -- (Test24::D, 0) vtable address --
1045// CHECK-31-NEXT: 4 | void Test24::D::f()
1046// CHECK-31-NEXT: 5 | vbase_offset (-8)
1047// CHECK-31-NEXT: 6 | vcall_offset (-8)
1048// CHECK-31-NEXT: 7 | offset_to_top (-8)
1049// CHECK-31-NEXT: 8 | Test24::D RTTI
1050// CHECK-31-NEXT: -- (Test24::C, 8) vtable address --
1051// CHECK-31-NEXT: 9 | [unused] void Test24::D::f()
Anders Carlsson293126b2010-02-28 17:59:36 +00001052
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001053// CHECK-31: Construction vtable for ('Test24::B', 0) in 'Test24::D' (5 entries).
1054// CHECK-31-NEXT: 0 | vbase_offset (0)
1055// CHECK-31-NEXT: 1 | vcall_offset (0)
1056// CHECK-31-NEXT: 2 | offset_to_top (0)
1057// CHECK-31-NEXT: 3 | Test24::B RTTI
1058// CHECK-31-NEXT: -- (Test24::A, 0) vtable address --
1059// CHECK-31-NEXT: -- (Test24::B, 0) vtable address --
1060// CHECK-31-NEXT: 4 | void Test24::A::f()
Anders Carlsson293126b2010-02-28 17:59:36 +00001061
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001062// CHECK-31: Construction vtable for ('Test24::C', 8) in 'Test24::D' (9 entries).
1063// CHECK-31-NEXT: 0 | vbase_offset (-8)
1064// CHECK-31-NEXT: 1 | vcall_offset (-8)
1065// CHECK-31-NEXT: 2 | offset_to_top (0)
1066// CHECK-31-NEXT: 3 | Test24::C RTTI
1067// CHECK-31-NEXT: -- (Test24::C, 8) vtable address --
1068// CHECK-31-NEXT: 4 | [unused] void Test24::A::f()
1069// CHECK-31-NEXT: 5 | vcall_offset (0)
1070// CHECK-31-NEXT: 6 | offset_to_top (8)
1071// CHECK-31-NEXT: 7 | Test24::C RTTI
1072// CHECK-31-NEXT: -- (Test24::A, 0) vtable address --
1073// CHECK-31-NEXT: 8 | void Test24::A::f()
Anders Carlsson293126b2010-02-28 17:59:36 +00001074struct D : B, C {
1075 virtual void f();
1076};
1077void D::f() { }
Anders Carlssondad0f992010-02-28 18:37:33 +00001078
Anders Carlsson293126b2010-02-28 17:59:36 +00001079}
Anders Carlssonce57dd52010-03-03 04:58:02 +00001080
1081namespace Test25 {
1082
1083// This mainly tests that we don't assert on this class hierarchy.
1084
1085struct V {
1086 virtual void f();
1087};
1088
1089struct A : virtual V { };
1090struct B : virtual V { };
1091
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001092// CHECK-32: Vtable for 'Test25::C' (11 entries).
1093// CHECK-32-NEXT: 0 | vbase_offset (0)
1094// CHECK-32-NEXT: 1 | vcall_offset (0)
1095// CHECK-32-NEXT: 2 | offset_to_top (0)
1096// CHECK-32-NEXT: 3 | Test25::C RTTI
1097// CHECK-32-NEXT: -- (Test25::A, 0) vtable address --
1098// CHECK-32-NEXT: -- (Test25::C, 0) vtable address --
1099// CHECK-32-NEXT: -- (Test25::V, 0) vtable address --
1100// CHECK-32-NEXT: 4 | void Test25::V::f()
1101// CHECK-32-NEXT: 5 | void Test25::C::g()
1102// CHECK-32-NEXT: 6 | vbase_offset (-8)
1103// CHECK-32-NEXT: 7 | vcall_offset (-8)
1104// CHECK-32-NEXT: 8 | offset_to_top (-8)
1105// CHECK-32-NEXT: 9 | Test25::C RTTI
1106// CHECK-32-NEXT: -- (Test25::B, 8) vtable address --
1107// CHECK-32-NEXT: 10 | [unused] void Test25::V::f()
Anders Carlssonce57dd52010-03-03 04:58:02 +00001108
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001109// CHECK-32: Construction vtable for ('Test25::A', 0) in 'Test25::C' (5 entries).
1110// CHECK-32-NEXT: 0 | vbase_offset (0)
1111// CHECK-32-NEXT: 1 | vcall_offset (0)
1112// CHECK-32-NEXT: 2 | offset_to_top (0)
1113// CHECK-32-NEXT: 3 | Test25::A RTTI
1114// CHECK-32-NEXT: -- (Test25::A, 0) vtable address --
1115// CHECK-32-NEXT: -- (Test25::V, 0) vtable address --
1116// CHECK-32-NEXT: 4 | void Test25::V::f()
Anders Carlssonce57dd52010-03-03 04:58:02 +00001117
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001118// CHECK-32: Construction vtable for ('Test25::B', 8) in 'Test25::C' (9 entries).
1119// CHECK-32-NEXT: 0 | vbase_offset (-8)
1120// CHECK-32-NEXT: 1 | vcall_offset (-8)
1121// CHECK-32-NEXT: 2 | offset_to_top (0)
1122// CHECK-32-NEXT: 3 | Test25::B RTTI
1123// CHECK-32-NEXT: -- (Test25::B, 8) vtable address --
1124// CHECK-32-NEXT: 4 | [unused] void Test25::V::f()
1125// CHECK-32-NEXT: 5 | vcall_offset (0)
1126// CHECK-32-NEXT: 6 | offset_to_top (8)
1127// CHECK-32-NEXT: 7 | Test25::B RTTI
1128// CHECK-32-NEXT: -- (Test25::V, 0) vtable address --
1129// CHECK-32-NEXT: 8 | void Test25::V::f()
Anders Carlssonce57dd52010-03-03 04:58:02 +00001130struct C : A, virtual V, B {
1131 virtual void g();
1132};
1133void C::g() { }
1134
1135}
Anders Carlsson60396612010-03-10 06:51:42 +00001136
1137namespace Test26 {
1138
1139// Test that we generate the right number of entries in the C-in-D construction vtable, and that
1140// we don't mark A::a as unused.
1141
1142struct A {
1143 virtual void a();
1144};
1145
1146struct B {
1147 virtual void c();
1148};
1149
1150struct C : virtual A {
1151 virtual void b();
1152};
1153
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001154// CHECK-33: Vtable for 'Test26::D' (15 entries).
1155// CHECK-33-NEXT: 0 | vbase_offset (8)
1156// CHECK-33-NEXT: 1 | vbase_offset (8)
1157// CHECK-33-NEXT: 2 | vbase_offset (0)
1158// CHECK-33-NEXT: 3 | vcall_offset (0)
1159// CHECK-33-NEXT: 4 | offset_to_top (0)
1160// CHECK-33-NEXT: 5 | Test26::D RTTI
1161// CHECK-33-NEXT: -- (Test26::B, 0) vtable address --
1162// CHECK-33-NEXT: -- (Test26::D, 0) vtable address --
1163// CHECK-33-NEXT: 6 | void Test26::B::c()
1164// CHECK-33-NEXT: 7 | void Test26::D::d()
1165// CHECK-33-NEXT: 8 | vcall_offset (0)
1166// CHECK-33-NEXT: 9 | vbase_offset (0)
1167// CHECK-33-NEXT: 10 | vcall_offset (0)
1168// CHECK-33-NEXT: 11 | offset_to_top (-8)
1169// CHECK-33-NEXT: 12 | Test26::D RTTI
1170// CHECK-33-NEXT: -- (Test26::A, 8) vtable address --
1171// CHECK-33-NEXT: -- (Test26::C, 8) vtable address --
1172// CHECK-33-NEXT: 13 | void Test26::A::a()
1173// CHECK-33-NEXT: 14 | void Test26::C::b()
Anders Carlsson60396612010-03-10 06:51:42 +00001174
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001175// CHECK-33: Construction vtable for ('Test26::C', 8) in 'Test26::D' (7 entries).
1176// CHECK-33-NEXT: 0 | vcall_offset (0)
1177// CHECK-33-NEXT: 1 | vbase_offset (0)
1178// CHECK-33-NEXT: 2 | vcall_offset (0)
1179// CHECK-33-NEXT: 3 | offset_to_top (0)
1180// CHECK-33-NEXT: 4 | Test26::C RTTI
1181// CHECK-33-NEXT: -- (Test26::A, 8) vtable address --
1182// CHECK-33-NEXT: -- (Test26::C, 8) vtable address --
1183// CHECK-33-NEXT: 5 | void Test26::A::a()
1184// CHECK-33-NEXT: 6 | void Test26::C::b()
Anders Carlsson60396612010-03-10 06:51:42 +00001185class D : virtual B, virtual C {
1186 virtual void d();
1187};
1188void D::d() { }
1189
Anders Carlssone35b7682010-03-10 06:51:56 +00001190}
Anders Carlssonf2c98ce2010-03-10 19:15:26 +00001191
1192namespace Test27 {
1193
1194// Test that we don't generate a secondary vtable for C in the D-in-E vtable, since
1195// C doesn't have any virtual bases.
1196
1197struct A {
1198 virtual void a();
1199};
1200
1201struct B {
1202 virtual void b();
1203};
1204
1205struct C {
1206 virtual void c();
1207};
1208
1209struct D : A, virtual B, C {
1210 virtual void d();
1211};
1212
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001213// CHECK-34: Vtable for 'Test27::E' (13 entries).
1214// CHECK-34-NEXT: 0 | vbase_offset (16)
1215// CHECK-34-NEXT: 1 | offset_to_top (0)
1216// CHECK-34-NEXT: 2 | Test27::E RTTI
1217// CHECK-34-NEXT: -- (Test27::A, 0) vtable address --
1218// CHECK-34-NEXT: -- (Test27::D, 0) vtable address --
1219// CHECK-34-NEXT: -- (Test27::E, 0) vtable address --
1220// CHECK-34-NEXT: 3 | void Test27::A::a()
1221// CHECK-34-NEXT: 4 | void Test27::D::d()
1222// CHECK-34-NEXT: 5 | void Test27::E::e()
1223// CHECK-34-NEXT: 6 | offset_to_top (-8)
1224// CHECK-34-NEXT: 7 | Test27::E RTTI
1225// CHECK-34-NEXT: -- (Test27::C, 8) vtable address --
1226// CHECK-34-NEXT: 8 | void Test27::C::c()
1227// CHECK-34-NEXT: 9 | vcall_offset (0)
1228// CHECK-34-NEXT: 10 | offset_to_top (-16)
1229// CHECK-34-NEXT: 11 | Test27::E RTTI
1230// CHECK-34-NEXT: -- (Test27::B, 16) vtable address --
1231// CHECK-34-NEXT: 12 | void Test27::B::b()
Anders Carlssonf2c98ce2010-03-10 19:15:26 +00001232
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001233// CHECK-34: Construction vtable for ('Test27::D', 0) in 'Test27::E' (9 entries).
1234// CHECK-34-NEXT: 0 | vbase_offset (16)
1235// CHECK-34-NEXT: 1 | offset_to_top (0)
1236// CHECK-34-NEXT: 2 | Test27::D RTTI
1237// CHECK-34-NEXT: -- (Test27::A, 0) vtable address --
1238// CHECK-34-NEXT: -- (Test27::D, 0) vtable address --
1239// CHECK-34-NEXT: 3 | void Test27::A::a()
1240// CHECK-34-NEXT: 4 | void Test27::D::d()
1241// CHECK-34-NEXT: 5 | vcall_offset (0)
1242// CHECK-34-NEXT: 6 | offset_to_top (-16)
1243// CHECK-34-NEXT: 7 | Test27::D RTTI
1244// CHECK-34-NEXT: -- (Test27::B, 16) vtable address --
1245// CHECK-34-NEXT: 8 | void Test27::B::b()
Anders Carlssonf2c98ce2010-03-10 19:15:26 +00001246struct E : D {
1247 virtual void e();
1248};
1249void E::e() { }
Anders Carlssona96a2e92010-03-10 19:39:11 +00001250
1251}
1252
1253namespace Test28 {
1254
1255// Check that we do include the vtable for B in the D-in-E construction vtable, since
1256// B is a base class of a virtual base (C).
1257
1258struct A {
1259 virtual void a();
1260};
1261
1262struct B {
1263 virtual void b();
1264};
1265
1266struct C : A, B {
1267 virtual void c();
1268};
1269
1270struct D : virtual C {
1271};
1272
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001273// CHECK-35: Vtable for 'Test28::E' (14 entries).
1274// CHECK-35-NEXT: 0 | vbase_offset (8)
1275// CHECK-35-NEXT: 1 | offset_to_top (0)
1276// CHECK-35-NEXT: 2 | Test28::E RTTI
1277// CHECK-35-NEXT: -- (Test28::D, 0) vtable address --
1278// CHECK-35-NEXT: -- (Test28::E, 0) vtable address --
1279// CHECK-35-NEXT: 3 | void Test28::E::e()
1280// CHECK-35-NEXT: 4 | vcall_offset (8)
1281// CHECK-35-NEXT: 5 | vcall_offset (0)
1282// CHECK-35-NEXT: 6 | vcall_offset (0)
1283// CHECK-35-NEXT: 7 | offset_to_top (-8)
1284// CHECK-35-NEXT: 8 | Test28::E RTTI
1285// CHECK-35-NEXT: -- (Test28::A, 8) vtable address --
1286// CHECK-35-NEXT: -- (Test28::C, 8) vtable address --
1287// CHECK-35-NEXT: 9 | void Test28::A::a()
1288// CHECK-35-NEXT: 10 | void Test28::C::c()
1289// CHECK-35-NEXT: 11 | offset_to_top (-16)
1290// CHECK-35-NEXT: 12 | Test28::E RTTI
1291// CHECK-35-NEXT: -- (Test28::B, 16) vtable address --
1292// CHECK-35-NEXT: 13 | void Test28::B::b()
Anders Carlssona96a2e92010-03-10 19:39:11 +00001293
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001294// CHECK-35: Construction vtable for ('Test28::D', 0) in 'Test28::E' (13 entries).
1295// CHECK-35-NEXT: 0 | vbase_offset (8)
1296// CHECK-35-NEXT: 1 | offset_to_top (0)
1297// CHECK-35-NEXT: 2 | Test28::D RTTI
1298// CHECK-35-NEXT: -- (Test28::D, 0) vtable address --
1299// CHECK-35-NEXT: 3 | vcall_offset (8)
1300// CHECK-35-NEXT: 4 | vcall_offset (0)
1301// CHECK-35-NEXT: 5 | vcall_offset (0)
1302// CHECK-35-NEXT: 6 | offset_to_top (-8)
1303// CHECK-35-NEXT: 7 | Test28::D RTTI
1304// CHECK-35-NEXT: -- (Test28::A, 8) vtable address --
1305// CHECK-35-NEXT: -- (Test28::C, 8) vtable address --
1306// CHECK-35-NEXT: 8 | void Test28::A::a()
1307// CHECK-35-NEXT: 9 | void Test28::C::c()
1308// CHECK-35-NEXT: 10 | offset_to_top (-16)
1309// CHECK-35-NEXT: 11 | Test28::D RTTI
1310// CHECK-35-NEXT: -- (Test28::B, 16) vtable address --
1311// CHECK-35-NEXT: 12 | void Test28::B::b()
Anders Carlssona96a2e92010-03-10 19:39:11 +00001312struct E : D {
1313 virtual void e();
1314};
1315void E::e() { }
1316
Anders Carlssonf2c98ce2010-03-10 19:15:26 +00001317}
Anders Carlssonadb507d2010-03-29 15:08:41 +00001318
1319namespace Test29 {
1320
1321// Test that the covariant return thunk for B::f will have a virtual 'this' adjustment,
1322// matching gcc.
1323
1324struct V1 { };
1325struct V2 : virtual V1 { };
1326
1327struct A {
1328 virtual V1 *f();
1329};
1330
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001331// CHECK-36: Vtable for 'Test29::B' (6 entries).
1332// CHECK-36-NEXT: 0 | vbase_offset (0)
1333// CHECK-36-NEXT: 1 | vcall_offset (0)
1334// CHECK-36-NEXT: 2 | offset_to_top (0)
1335// CHECK-36-NEXT: 3 | Test29::B RTTI
1336// CHECK-36-NEXT: -- (Test29::A, 0) vtable address --
1337// CHECK-36-NEXT: -- (Test29::B, 0) vtable address --
1338// CHECK-36-NEXT: 4 | Test29::V2 *Test29::B::f()
1339// CHECK-36-NEXT: [return adjustment: 0 non-virtual, -24 vbase offset offset]
1340// CHECK-36-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
1341// CHECK-36-NEXT: 5 | Test29::V2 *Test29::B::f()
Anders Carlssonadb507d2010-03-29 15:08:41 +00001342struct B : virtual A {
1343 virtual V2 *f();
1344};
1345V2 *B::f() { return 0; }
1346
1347}
Anders Carlssonbdda6c12010-04-10 18:42:27 +00001348
1349namespace Test30 {
1350
1351// Test that we don't assert when generating a vtable for F.
1352struct A { };
1353
1354struct B : virtual A {
1355 int i;
1356};
1357
1358struct C {
1359 virtual void f();
1360};
1361
1362struct D : virtual C, B { };
1363struct E : virtual D { };
1364
1365struct F : E {
1366 virtual void f();
1367};
1368void F::f() { }
1369
1370}
Anders Carlssonf622b452010-04-10 20:39:29 +00001371
1372namespace Test31 {
1373
1374// Test that we don't add D::f twice to the primary vtable.
1375struct A {
1376 int a;
1377};
1378
1379struct B {
1380 virtual void f();
1381};
1382
1383struct C : A, virtual B {
1384 virtual void f();
1385};
1386
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001387// CHECK-37: Vtable for 'Test31::D' (11 entries).
1388// CHECK-37-NEXT: 0 | vbase_offset (0)
1389// CHECK-37-NEXT: 1 | vbase_offset (8)
1390// CHECK-37-NEXT: 2 | vcall_offset (0)
1391// CHECK-37-NEXT: 3 | offset_to_top (0)
1392// CHECK-37-NEXT: 4 | Test31::D RTTI
1393// CHECK-37-NEXT: -- (Test31::B, 0) vtable address --
1394// CHECK-37-NEXT: -- (Test31::D, 0) vtable address --
1395// CHECK-37-NEXT: 5 | void Test31::D::f()
1396// CHECK-37-NEXT: 6 | vbase_offset (-8)
1397// CHECK-37-NEXT: 7 | vcall_offset (-8)
1398// CHECK-37-NEXT: 8 | offset_to_top (-8)
1399// CHECK-37-NEXT: 9 | Test31::D RTTI
1400// CHECK-37-NEXT: -- (Test31::C, 8) vtable address --
1401// CHECK-37-NEXT: 10 | void Test31::D::f()
1402// CHECK-37-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
Anders Carlssonf622b452010-04-10 20:39:29 +00001403struct D : virtual C {
1404 virtual void f();
1405};
1406void D::f() { }
1407
1408}
Anders Carlsson573021f2010-04-10 21:35:33 +00001409
1410namespace Test32 {
1411
1412// Check that we correctly lay out the virtual bases of 'Test32::D'.
1413
1414struct A {
1415 virtual void f();
1416};
1417
1418struct B : virtual A { };
1419struct C : A, virtual B { };
1420struct D : virtual B { };
1421
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001422// CHECK-38: Virtual base offset offsets for 'Test32::E' (3 entries).
1423// CHECK-38-NEXT: Test32::A | -32
1424// CHECK-38-NEXT: Test32::B | -24
1425// CHECK-38-NEXT: Test32::D | -40
Anders Carlsson573021f2010-04-10 21:35:33 +00001426struct E : C, virtual D {
1427 virtual void f();
1428};
1429void E::f() { }
1430
1431}
Anders Carlssonaf6ddf22010-04-11 20:04:11 +00001432
1433namespace Test33 {
1434
1435// Test that we don't emit too many vcall offsets in 'Test32::F'.
1436
1437struct A {
1438 virtual void a();
1439};
1440
1441struct B {
1442 virtual void b();
1443};
1444
1445struct C : virtual A, virtual B {
1446 virtual void c();
1447};
1448
1449struct D : virtual C { };
1450
1451struct E : A, D {
1452 virtual void e();
1453};
1454
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001455// CHECK-39: Vtable for 'Test33::F' (30 entries).
1456// CHECK-39-NEXT: 0 | vbase_offset (24)
1457// CHECK-39-NEXT: 1 | vbase_offset (16)
1458// CHECK-39-NEXT: 2 | vbase_offset (16)
1459// CHECK-39-NEXT: 3 | vbase_offset (8)
1460// CHECK-39-NEXT: 4 | offset_to_top (0)
1461// CHECK-39-NEXT: 5 | Test33::F RTTI
1462// CHECK-39-NEXT: -- (Test33::A, 0) vtable address --
1463// CHECK-39-NEXT: -- (Test33::F, 0) vtable address --
1464// CHECK-39-NEXT: 6 | void Test33::A::a()
1465// CHECK-39-NEXT: 7 | void Test33::F::f()
1466// CHECK-39-NEXT: 8 | vcall_offset (0)
1467// CHECK-39-NEXT: 9 | vcall_offset (0)
1468// CHECK-39-NEXT: 10 | vbase_offset (16)
1469// CHECK-39-NEXT: 11 | vbase_offset (8)
1470// CHECK-39-NEXT: 12 | vbase_offset (8)
1471// CHECK-39-NEXT: 13 | offset_to_top (-8)
1472// CHECK-39-NEXT: 14 | Test33::F RTTI
1473// CHECK-39-NEXT: -- (Test33::A, 8) vtable address --
1474// CHECK-39-NEXT: -- (Test33::E, 8) vtable address --
1475// CHECK-39-NEXT: 15 | void Test33::A::a()
1476// CHECK-39-NEXT: 16 | void Test33::E::e()
1477// CHECK-39-NEXT: 17 | vbase_offset (0)
1478// CHECK-39-NEXT: 18 | vcall_offset (0)
1479// CHECK-39-NEXT: 19 | vbase_offset (8)
1480// CHECK-39-NEXT: 20 | vbase_offset (0)
1481// CHECK-39-NEXT: 21 | vcall_offset (0)
1482// CHECK-39-NEXT: 22 | offset_to_top (-16)
1483// CHECK-39-NEXT: 23 | Test33::F RTTI
1484// CHECK-39-NEXT: -- (Test33::A, 16) vtable address --
1485// CHECK-39-NEXT: -- (Test33::C, 16) vtable address --
1486// CHECK-39-NEXT: -- (Test33::D, 16) vtable address --
1487// CHECK-39-NEXT: 24 | void Test33::A::a()
1488// CHECK-39-NEXT: 25 | void Test33::C::c()
1489// CHECK-39-NEXT: 26 | vcall_offset (0)
1490// CHECK-39-NEXT: 27 | offset_to_top (-24)
1491// CHECK-39-NEXT: 28 | Test33::F RTTI
1492// CHECK-39-NEXT: -- (Test33::B, 24) vtable address --
1493// CHECK-39-NEXT: 29 | void Test33::B::b()
Anders Carlssonaf6ddf22010-04-11 20:04:11 +00001494struct F : virtual E, A {
1495 virtual void f();
1496};
1497void F::f() { }
1498
1499}
Anders Carlsson73e6fa02010-04-11 22:20:36 +00001500
1501namespace Test34 {
1502
Nick Lewycky69c05d52010-04-12 05:32:01 +00001503// Test that we lay out the construction vtable for 'Test34::E' in 'Test34::F' correctly.
Anders Carlsson73e6fa02010-04-11 22:20:36 +00001504
1505struct A {
1506 virtual void a();
1507};
1508struct B : virtual A { };
1509
1510struct C : B, A {
1511 virtual void c();
1512};
1513
1514struct D : A, C { };
1515
1516struct E : virtual D {
1517 virtual void e();
1518};
1519
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001520// CHECK-40: Construction vtable for ('Test34::E', 0) in 'Test34::F' (22 entries).
1521// CHECK-40-NEXT: 0 | vbase_offset (0)
1522// CHECK-40-NEXT: 1 | vbase_offset (8)
1523// CHECK-40-NEXT: 2 | vcall_offset (0)
1524// CHECK-40-NEXT: 3 | offset_to_top (0)
1525// CHECK-40-NEXT: 4 | Test34::E RTTI
1526// CHECK-40-NEXT: -- (Test34::A, 0) vtable address --
1527// CHECK-40-NEXT: -- (Test34::E, 0) vtable address --
1528// CHECK-40-NEXT: 5 | void Test34::A::a()
1529// CHECK-40-NEXT: 6 | void Test34::E::e()
1530// CHECK-40-NEXT: 7 | vcall_offset (8)
1531// CHECK-40-NEXT: 8 | vcall_offset (0)
1532// CHECK-40-NEXT: 9 | vbase_offset (-8)
1533// CHECK-40-NEXT: 10 | offset_to_top (-8)
1534// CHECK-40-NEXT: 11 | Test34::E RTTI
1535// CHECK-40-NEXT: -- (Test34::A, 8) vtable address --
1536// CHECK-40-NEXT: -- (Test34::D, 8) vtable address --
1537// CHECK-40-NEXT: 12 | void Test34::A::a()
1538// CHECK-40-NEXT: 13 | vbase_offset (-16)
1539// CHECK-40-NEXT: 14 | vcall_offset (-16)
1540// CHECK-40-NEXT: 15 | offset_to_top (-16)
1541// CHECK-40-NEXT: 16 | Test34::E RTTI
1542// CHECK-40-NEXT: -- (Test34::B, 16) vtable address --
1543// CHECK-40-NEXT: -- (Test34::C, 16) vtable address --
1544// CHECK-40-NEXT: 17 | [unused] void Test34::A::a()
1545// CHECK-40-NEXT: 18 | void Test34::C::c()
1546// CHECK-40-NEXT: 19 | offset_to_top (-24)
1547// CHECK-40-NEXT: 20 | Test34::E RTTI
1548// CHECK-40-NEXT: -- (Test34::A, 24) vtable address --
1549// CHECK-40-NEXT: 21 | void Test34::A::a()
Anders Carlsson73e6fa02010-04-11 22:20:36 +00001550struct F : E {
1551 virtual void f();
1552};
1553void F::f() { }
1554
1555}
Anders Carlsson97913572010-04-15 16:12:58 +00001556
1557namespace Test35 {
1558
1559// Test that we lay out the virtual bases of 'Test35::H' in the correct order.
1560
1561struct A {
1562 virtual void a();
1563
1564 int i;
1565};
1566
1567struct B : virtual A {
1568 virtual void b();
1569};
1570
1571struct C {
1572 virtual void c();
1573};
1574
1575struct D : C, virtual B {
1576 virtual void d();
1577};
1578
1579struct E : D {
1580 virtual void e();
1581
1582 bool b;
1583};
1584
1585struct F : virtual D { };
1586struct G : virtual E { };
1587
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001588// CHECK-41: Vtable for 'Test35::H' (32 entries).
1589// CHECK-41-NEXT: 0 | vbase_offset (32)
1590// CHECK-41-NEXT: 1 | vbase_offset (0)
1591// CHECK-41-NEXT: 2 | vcall_offset (0)
1592// CHECK-41-NEXT: 3 | vcall_offset (0)
1593// CHECK-41-NEXT: 4 | vbase_offset (16)
1594// CHECK-41-NEXT: 5 | vbase_offset (8)
1595// CHECK-41-NEXT: 6 | offset_to_top (0)
1596// CHECK-41-NEXT: 7 | Test35::H RTTI
1597// CHECK-41-NEXT: -- (Test35::C, 0) vtable address --
1598// CHECK-41-NEXT: -- (Test35::D, 0) vtable address --
1599// CHECK-41-NEXT: -- (Test35::F, 0) vtable address --
1600// CHECK-41-NEXT: -- (Test35::H, 0) vtable address --
1601// CHECK-41-NEXT: 8 | void Test35::C::c()
1602// CHECK-41-NEXT: 9 | void Test35::D::d()
1603// CHECK-41-NEXT: 10 | void Test35::H::h()
1604// CHECK-41-NEXT: 11 | vbase_offset (0)
1605// CHECK-41-NEXT: 12 | vbase_offset (24)
1606// CHECK-41-NEXT: 13 | vcall_offset (0)
1607// CHECK-41-NEXT: 14 | vbase_offset (8)
1608// CHECK-41-NEXT: 15 | offset_to_top (-8)
1609// CHECK-41-NEXT: 16 | Test35::H RTTI
1610// CHECK-41-NEXT: -- (Test35::B, 8) vtable address --
1611// CHECK-41-NEXT: -- (Test35::G, 8) vtable address --
1612// CHECK-41-NEXT: 17 | void Test35::B::b()
1613// CHECK-41-NEXT: 18 | vcall_offset (0)
1614// CHECK-41-NEXT: 19 | offset_to_top (-16)
1615// CHECK-41-NEXT: 20 | Test35::H RTTI
1616// CHECK-41-NEXT: -- (Test35::A, 16) vtable address --
1617// CHECK-41-NEXT: 21 | void Test35::A::a()
1618// CHECK-41-NEXT: 22 | vcall_offset (0)
1619// CHECK-41-NEXT: 23 | vcall_offset (0)
1620// CHECK-41-NEXT: 24 | vcall_offset (0)
1621// CHECK-41-NEXT: 25 | vbase_offset (-16)
1622// CHECK-41-NEXT: 26 | vbase_offset (-24)
1623// CHECK-41-NEXT: 27 | offset_to_top (-32)
1624// CHECK-41-NEXT: 28 | Test35::H RTTI
1625// CHECK-41-NEXT: -- (Test35::C, 32) vtable address --
1626// CHECK-41-NEXT: -- (Test35::D, 32) vtable address --
1627// CHECK-41-NEXT: -- (Test35::E, 32) vtable address --
1628// CHECK-41-NEXT: 29 | void Test35::C::c()
1629// CHECK-41-NEXT: 30 | void Test35::D::d()
1630// CHECK-41-NEXT: 31 | void Test35::E::e()
Anders Carlsson97913572010-04-15 16:12:58 +00001631
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001632// CHECK-41: Virtual base offset offsets for 'Test35::H' (4 entries).
1633// CHECK-41-NEXT: Test35::A | -32
1634// CHECK-41-NEXT: Test35::B | -24
1635// CHECK-41-NEXT: Test35::D | -56
1636// CHECK-41-NEXT: Test35::E | -64
Anders Carlsson97913572010-04-15 16:12:58 +00001637struct H : F, G {
1638 virtual void h();
1639};
1640void H::h() { }
1641
1642}
Anders Carlssonfbf05612010-04-17 17:24:33 +00001643
1644namespace Test36 {
1645
1646// Test that we don't mark B::f as unused in the vtable for D.
1647
1648struct A {
1649 virtual void f();
1650};
1651
1652struct B : virtual A { };
1653
1654struct C : virtual A {
1655 virtual void f();
1656};
1657
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001658// CHECK-42: Vtable for 'Test36::D' (12 entries).
1659// CHECK-42-NEXT: 0 | vbase_offset (8)
1660// CHECK-42-NEXT: 1 | vbase_offset (8)
1661// CHECK-42-NEXT: 2 | vcall_offset (0)
1662// CHECK-42-NEXT: 3 | offset_to_top (0)
1663// CHECK-42-NEXT: 4 | Test36::D RTTI
1664// CHECK-42-NEXT: -- (Test36::C, 0) vtable address --
1665// CHECK-42-NEXT: -- (Test36::D, 0) vtable address --
1666// CHECK-42-NEXT: 5 | void Test36::C::f()
1667// CHECK-42-NEXT: 6 | void Test36::D::g()
1668// CHECK-42-NEXT: 7 | vbase_offset (0)
1669// CHECK-42-NEXT: 8 | vcall_offset (-8)
1670// CHECK-42-NEXT: 9 | offset_to_top (-8)
1671// CHECK-42-NEXT: 10 | Test36::D RTTI
1672// CHECK-42-NEXT: -- (Test36::A, 8) vtable address --
1673// CHECK-42-NEXT: -- (Test36::B, 8) vtable address --
1674// CHECK-42-NEXT: 11 | void Test36::C::f()
1675// CHECK-42-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
Anders Carlssonfbf05612010-04-17 17:24:33 +00001676struct D : virtual B, C {
1677 virtual void g();
1678};
1679void D::g() { }
1680
1681}