blob: 1e831d2d8349a05a42cdc4fff0d1273752ad3e07 [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 Carlssonb8bced02011-04-10 18:00:32 +000044// RUN: FileCheck --check-prefix=CHECK-43 %s < %t
John McCall260a3e42012-03-21 06:57:19 +000045// RUN: FileCheck --check-prefix=CHECK-44 %s < %t
David Blaikied954ab42012-10-16 20:25:33 +000046// RUN: FileCheck --check-prefix=CHECK-45 %s < %t
Anders Carlsson824d7ea2010-02-11 08:02:13 +000047
Anders Carlsson49bac9a2010-02-13 23:40:17 +000048// For now, just verify this doesn't crash.
49namespace test0 {
50 struct Obj {};
51
52 struct Base { virtual const Obj *foo() = 0; };
53 struct Derived : Base { virtual Obj *foo() { return new Obj(); } };
54
55 void test(Derived *D) { D->foo(); }
56}
57
58namespace Test1 {
Douglas Gregor6fb745b2010-05-13 16:44:06 +000059// CHECK-1: Vtable for 'Test1::A' (3 entries).
60// CHECK-1-NEXT: 0 | offset_to_top (0)
61// CHECK-1-NEXT: 1 | Test1::A RTTI
62// CHECK-1-NEXT: -- (Test1::A, 0) vtable address --
63// CHECK-1-NEXT: 2 | void Test1::A::f()
Anders Carlsson824d7ea2010-02-11 08:02:13 +000064struct A {
65 virtual void f();
66};
Anders Carlsson824d7ea2010-02-11 08:02:13 +000067void A::f() { }
Anders Carlsson57071e22010-02-12 05:25:12 +000068
Anders Carlsson824d7ea2010-02-11 08:02:13 +000069}
70
Anders Carlsson848fa642010-02-11 18:20:28 +000071namespace Test2 {
72
73// This is a smoke test of the vtable dumper.
Douglas Gregor6fb745b2010-05-13 16:44:06 +000074// CHECK-2: Vtable for 'Test2::A' (9 entries).
75// CHECK-2-NEXT: 0 | offset_to_top (0)
76// CHECK-2-NEXT: 1 | Test2::A RTTI
77// CHECK-2-NEXT: -- (Test2::A, 0) vtable address --
78// CHECK-2-NEXT: 2 | void Test2::A::f()
79// CHECK-2-NEXT: 3 | void Test2::A::f() const
80// CHECK-2-NEXT: 4 | Test2::A *Test2::A::g(int)
81// CHECK-2-NEXT: 5 | Test2::A::~A() [complete]
82// CHECK-2-NEXT: 6 | Test2::A::~A() [deleting]
83// CHECK-2-NEXT: 7 | void Test2::A::h()
Chris Lattner0c42bb62010-09-05 00:17:29 +000084// CHECK-2-NEXT: 8 | Test2::A &Test2::A::operator=(const Test2::A &)
Anders Carlsson848fa642010-02-11 18:20:28 +000085struct A {
86 virtual void f();
87 virtual void f() const;
88
89 virtual A* g(int a);
90 virtual ~A();
91 virtual void h();
Anders Carlssonbac72712010-02-11 18:21:49 +000092 virtual A& operator=(const A&);
Anders Carlsson848fa642010-02-11 18:20:28 +000093};
Anders Carlsson848fa642010-02-11 18:20:28 +000094void A::f() { }
95
Anders Carlsson98241422010-02-12 02:38:13 +000096// Another simple vtable dumper test.
Anders Carlsson57071e22010-02-12 05:25:12 +000097
Douglas Gregor6fb745b2010-05-13 16:44:06 +000098// CHECK-3: Vtable for 'Test2::B' (6 entries).
99// CHECK-3-NEXT: 0 | offset_to_top (0)
100// CHECK-3-NEXT: 1 | Test2::B RTTI
101// CHECK-3-NEXT: -- (Test2::B, 0) vtable address --
102// CHECK-3-NEXT: 2 | void Test2::B::f()
103// CHECK-3-NEXT: 3 | void Test2::B::g() [pure]
104// CHECK-3-NEXT: 4 | Test2::B::~B() [complete] [pure]
105// CHECK-3-NEXT: 5 | Test2::B::~B() [deleting] [pure]
Anders Carlsson98241422010-02-12 02:38:13 +0000106struct B {
107 virtual void f();
108 virtual void g() = 0;
109 virtual ~B() = 0;
110};
Anders Carlsson98241422010-02-12 02:38:13 +0000111void B::f() { }
112
Anders Carlsson848fa642010-02-11 18:20:28 +0000113}
Anders Carlsson57071e22010-02-12 05:25:12 +0000114
115namespace Test3 {
116
117// If a function in a derived class overrides a function in a primary base,
118// then the function should not have an entry in the derived class (unless the return
119// value requires adjusting).
120
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000121// CHECK-4: Vtable for 'Test3::A' (3 entries).
122// CHECK-4-NEXT: 0 | offset_to_top (0)
123// CHECK-4-NEXT: 1 | Test3::A RTTI
124// CHECK-4-NEXT: -- (Test3::A, 0) vtable address --
125// CHECK-4-NEXT: 2 | void Test3::A::f()
Anders Carlsson57071e22010-02-12 05:25:12 +0000126struct A {
127 virtual void f();
128};
129void A::f() { }
130
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000131// CHECK-5: Vtable for 'Test3::B' (4 entries).
132// CHECK-5-NEXT: 0 | offset_to_top (0)
133// CHECK-5-NEXT: 1 | Test3::B RTTI
134// CHECK-5-NEXT: -- (Test3::A, 0) vtable address --
135// CHECK-5-NEXT: -- (Test3::B, 0) vtable address --
136// CHECK-5-NEXT: 2 | void Test3::B::f()
137// CHECK-5-NEXT: 3 | void Test3::B::g()
Anders Carlsson57071e22010-02-12 05:25:12 +0000138struct B : A {
139 virtual void f();
140 virtual void g();
141};
142void B::f() { }
143
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000144// CHECK-6: Vtable for 'Test3::C' (5 entries).
145// CHECK-6-NEXT: 0 | offset_to_top (0)
146// CHECK-6-NEXT: 1 | Test3::C RTTI
147// CHECK-6-NEXT: -- (Test3::A, 0) vtable address --
148// CHECK-6-NEXT: -- (Test3::C, 0) vtable address --
149// CHECK-6-NEXT: 2 | void Test3::A::f()
150// CHECK-6-NEXT: 3 | void Test3::C::g()
151// CHECK-6-NEXT: 4 | void Test3::C::h()
Anders Carlsson57071e22010-02-12 05:25:12 +0000152struct C : A {
153 virtual void g();
154 virtual void h();
155};
156void C::g() { }
157
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000158// CHECK-7: Vtable for 'Test3::D' (5 entries).
159// CHECK-7-NEXT: 0 | offset_to_top (0)
160// CHECK-7-NEXT: 1 | Test3::D RTTI
161// CHECK-7-NEXT: -- (Test3::A, 0) vtable address --
162// CHECK-7-NEXT: -- (Test3::B, 0) vtable address --
163// CHECK-7-NEXT: -- (Test3::D, 0) vtable address --
164// CHECK-7-NEXT: 2 | void Test3::D::f()
165// CHECK-7-NEXT: 3 | void Test3::D::g()
166// CHECK-7-NEXT: 4 | void Test3::D::h()
Anders Carlsson57071e22010-02-12 05:25:12 +0000167struct D : B {
168 virtual void f();
169 virtual void g();
170 virtual void h();
171};
172
173void D::f() { }
174}
John McCall96058952010-02-12 06:15:07 +0000175
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000176namespace Test4 {
177
Anders Carlsson60db0ee2010-02-13 21:07:32 +0000178// Test non-virtual result adjustments.
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000179
180struct R1 { int r1; };
181struct R2 { int r2; };
182struct R3 : R1, R2 { int r3; };
183
184struct A {
185 virtual R2 *f();
186};
187
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000188// CHECK-8: Vtable for 'Test4::B' (4 entries).
189// CHECK-8-NEXT: 0 | offset_to_top (0)
190// CHECK-8-NEXT: 1 | Test4::B RTTI
191// CHECK-8-NEXT: -- (Test4::A, 0) vtable address --
192// CHECK-8-NEXT: -- (Test4::B, 0) vtable address --
193// CHECK-8-NEXT: 2 | Test4::R3 *Test4::B::f()
194// CHECK-8-NEXT: [return adjustment: 4 non-virtual]
195// CHECK-8-NEXT: 3 | Test4::R3 *Test4::B::f()
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000196
197struct B : A {
198 virtual R3 *f();
199};
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000200R3 *B::f() { return 0; }
Anders Carlsson60db0ee2010-02-13 21:07:32 +0000201
202// Test virtual result adjustments.
203struct V1 { int v1; };
204struct V2 : virtual V1 { int v1; };
205
206struct C {
207 virtual V1 *f();
208};
209
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000210// CHECK-9: Vtable for 'Test4::D' (4 entries).
211// CHECK-9-NEXT: 0 | offset_to_top (0)
212// CHECK-9-NEXT: 1 | Test4::D RTTI
213// CHECK-9-NEXT: -- (Test4::C, 0) vtable address --
214// CHECK-9-NEXT: -- (Test4::D, 0) vtable address --
215// CHECK-9-NEXT: 2 | Test4::V2 *Test4::D::f()
216// CHECK-9-NEXT: [return adjustment: 0 non-virtual, -24 vbase offset offset]
217// CHECK-9-NEXT: 3 | Test4::V2 *Test4::D::f()
Anders Carlsson60db0ee2010-02-13 21:07:32 +0000218struct D : C {
219 virtual V2 *f();
220};
221V2 *D::f() { return 0; };
222
223// Virtual result adjustments with an additional non-virtual adjustment.
224struct V3 : virtual R3 { int r3; };
225
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000226// CHECK-10: Vtable for 'Test4::E' (4 entries).
227// CHECK-10-NEXT: 0 | offset_to_top (0)
228// CHECK-10-NEXT: 1 | Test4::E RTTI
229// CHECK-10-NEXT: -- (Test4::A, 0) vtable address --
230// CHECK-10-NEXT: -- (Test4::E, 0) vtable address --
231// CHECK-10-NEXT: 2 | Test4::V3 *Test4::E::f()
232// CHECK-10-NEXT: [return adjustment: 4 non-virtual, -24 vbase offset offset]
233// CHECK-10-NEXT: 3 | Test4::V3 *Test4::E::f()
Anders Carlsson60db0ee2010-02-13 21:07:32 +0000234
235struct E : A {
236 virtual V3 *f();
237};
238V3 *E::f() { return 0;}
239
Anders Carlsson1d05be52010-02-13 21:16:54 +0000240// Test that a pure virtual member doesn't get a thunk.
241
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000242// CHECK-11: Vtable for 'Test4::F' (5 entries).
243// CHECK-11-NEXT: 0 | offset_to_top (0)
244// CHECK-11-NEXT: 1 | Test4::F RTTI
245// CHECK-11-NEXT: -- (Test4::A, 0) vtable address --
246// CHECK-11-NEXT: -- (Test4::F, 0) vtable address --
247// CHECK-11-NEXT: 2 | Test4::R3 *Test4::F::f() [pure]
248// CHECK-11-NEXT: 3 | void Test4::F::g()
249// CHECK-11-NEXT: 4 | Test4::R3 *Test4::F::f() [pure]
Anders Carlsson1d05be52010-02-13 21:16:54 +0000250struct F : A {
251 virtual void g();
252 virtual R3 *f() = 0;
253};
Anders Carlsson1d05be52010-02-13 21:16:54 +0000254void F::g() { }
255
Anders Carlsson7dbf47a2010-02-13 20:11:51 +0000256}
257
Anders Carlsson76f1aa72010-02-13 22:05:23 +0000258namespace Test5 {
259
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000260// Simple secondary vtables without 'this' pointer adjustments.
Anders Carlsson76f1aa72010-02-13 22:05:23 +0000261struct A {
262 virtual void f();
263 virtual void g();
264 int a;
265};
266
267struct B1 : A {
268 virtual void f();
269 int b1;
270};
271
272struct B2 : A {
273 virtual void g();
274 int b2;
275};
276
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000277// CHECK-12: Vtable for 'Test5::C' (9 entries).
278// CHECK-12-NEXT: 0 | offset_to_top (0)
279// CHECK-12-NEXT: 1 | Test5::C RTTI
280// CHECK-12-NEXT: -- (Test5::A, 0) vtable address --
281// CHECK-12-NEXT: -- (Test5::B1, 0) vtable address --
282// CHECK-12-NEXT: -- (Test5::C, 0) vtable address --
283// CHECK-12-NEXT: 2 | void Test5::B1::f()
284// CHECK-12-NEXT: 3 | void Test5::A::g()
285// CHECK-12-NEXT: 4 | void Test5::C::h()
286// CHECK-12-NEXT: 5 | offset_to_top (-16)
287// CHECK-12-NEXT: 6 | Test5::C RTTI
288// CHECK-12-NEXT: -- (Test5::A, 16) vtable address --
289// CHECK-12-NEXT: -- (Test5::B2, 16) vtable address --
290// CHECK-12-NEXT: 7 | void Test5::A::f()
291// CHECK-12-NEXT: 8 | void Test5::B2::g()
Anders Carlsson76f1aa72010-02-13 22:05:23 +0000292struct C : B1, B2 {
293 virtual void h();
294};
295void C::h() { }
296}
297
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000298namespace Test6 {
John McCall96058952010-02-12 06:15:07 +0000299
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000300// Simple non-virtual 'this' pointer adjustments.
301struct A1 {
302 virtual void f();
303 int a;
304};
John McCall96058952010-02-12 06:15:07 +0000305
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000306struct A2 {
307 virtual void f();
308 int a;
309};
310
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000311// CHECK-13: Vtable for 'Test6::C' (6 entries).
312// CHECK-13-NEXT: 0 | offset_to_top (0)
313// CHECK-13-NEXT: 1 | Test6::C RTTI
314// CHECK-13-NEXT: -- (Test6::A1, 0) vtable address --
315// CHECK-13-NEXT: -- (Test6::C, 0) vtable address --
316// CHECK-13-NEXT: 2 | void Test6::C::f()
317// CHECK-13-NEXT: 3 | offset_to_top (-16)
318// CHECK-13-NEXT: 4 | Test6::C RTTI
319// CHECK-13-NEXT: -- (Test6::A2, 16) vtable address --
320// CHECK-13-NEXT: 5 | void Test6::C::f()
321// CHECK-13-NEXT: [this adjustment: -16 non-virtual]
Anders Carlsson49bac9a2010-02-13 23:40:17 +0000322struct C : A1, A2 {
323 virtual void f();
324};
325void C::f() { }
326
Anders Carlssone67dc302010-02-14 00:16:19 +0000327}
328
329namespace Test7 {
330
331// Test that the D::f overrider for A::f have different 'this' pointer
332// adjustments in the two A base subobjects.
333
334struct A {
335 virtual void f();
336 int a;
337};
338
339struct B1 : A { };
340struct B2 : A { };
341
342struct C { virtual void c(); };
343
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000344// CHECK-14: Vtable for 'Test7::D' (10 entries).
345// CHECK-14-NEXT: 0 | offset_to_top (0)
346// CHECK-14-NEXT: 1 | Test7::D RTTI
347// CHECK-14-NEXT: -- (Test7::C, 0) vtable address --
348// CHECK-14-NEXT: -- (Test7::D, 0) vtable address --
349// CHECK-14-NEXT: 2 | void Test7::C::c()
350// CHECK-14-NEXT: 3 | void Test7::D::f()
351// CHECK-14-NEXT: 4 | offset_to_top (-8)
352// CHECK-14-NEXT: 5 | Test7::D RTTI
353// CHECK-14-NEXT: -- (Test7::A, 8) vtable address --
354// CHECK-14-NEXT: -- (Test7::B1, 8) vtable address --
355// CHECK-14-NEXT: 6 | void Test7::D::f()
356// CHECK-14-NEXT: [this adjustment: -8 non-virtual]
357// CHECK-14-NEXT: 7 | offset_to_top (-24)
358// CHECK-14-NEXT: 8 | Test7::D RTTI
359// CHECK-14-NEXT: -- (Test7::A, 24) vtable address --
360// CHECK-14-NEXT: -- (Test7::B2, 24) vtable address --
361// CHECK-14-NEXT: 9 | void Test7::D::f()
362// CHECK-14-NEXT: [this adjustment: -24 non-virtual]
Anders Carlssone67dc302010-02-14 00:16:19 +0000363struct D : C, B1, B2 {
364 virtual void f();
365};
366void D::f() { }
367
368}
Anders Carlssonb828afa2010-02-14 17:05:59 +0000369
370namespace Test8 {
371
372// Test that we don't try to layout vtables for classes that don't have
373// virtual bases or virtual member functions.
374
375struct A { };
376
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000377// CHECK-15: Vtable for 'Test8::B' (3 entries).
378// CHECK-15-NEXT: 0 | offset_to_top (0)
379// CHECK-15-NEXT: 1 | Test8::B RTTI
380// CHECK-15-NEXT: -- (Test8::B, 0) vtable address --
381// CHECK-15-NEXT: 2 | void Test8::B::f()
Anders Carlssonb828afa2010-02-14 17:05:59 +0000382struct B : A {
383 virtual void f();
384};
385void B::f() { }
386
387}
Anders Carlsson852213e2010-02-16 04:59:55 +0000388
389namespace Test9 {
390
391// Simple test of vbase offsets.
392
393struct A1 { int a1; };
394struct A2 { int a2; };
395
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000396// CHECK-16: Vtable for 'Test9::B' (5 entries).
397// CHECK-16-NEXT: 0 | vbase_offset (16)
398// CHECK-16-NEXT: 1 | vbase_offset (12)
399// CHECK-16-NEXT: 2 | offset_to_top (0)
400// CHECK-16-NEXT: 3 | Test9::B RTTI
401// CHECK-16-NEXT: -- (Test9::B, 0) vtable address --
402// CHECK-16-NEXT: 4 | void Test9::B::f()
Anders Carlsson852213e2010-02-16 04:59:55 +0000403struct B : virtual A1, virtual A2 {
404 int b;
405
406 virtual void f();
407};
408
409
410void B::f() { }
411
412}
Anders Carlssonc7b63162010-02-16 16:02:57 +0000413
414namespace Test10 {
415
416// Test for a bug where we would not emit secondary vtables for bases
417// of a primary base.
418struct A1 { virtual void a1(); };
419struct A2 { virtual void a2(); };
420
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000421// CHECK-17: Vtable for 'Test10::C' (7 entries).
422// CHECK-17-NEXT: 0 | offset_to_top (0)
423// CHECK-17-NEXT: 1 | Test10::C RTTI
424// CHECK-17-NEXT: -- (Test10::A1, 0) vtable address --
425// CHECK-17-NEXT: -- (Test10::B, 0) vtable address --
426// CHECK-17-NEXT: -- (Test10::C, 0) vtable address --
427// CHECK-17-NEXT: 2 | void Test10::A1::a1()
428// CHECK-17-NEXT: 3 | void Test10::C::f()
429// CHECK-17-NEXT: 4 | offset_to_top (-8)
430// CHECK-17-NEXT: 5 | Test10::C RTTI
431// CHECK-17-NEXT: -- (Test10::A2, 8) vtable address --
432// CHECK-17-NEXT: 6 | void Test10::A2::a2()
Anders Carlssonc7b63162010-02-16 16:02:57 +0000433struct B : A1, A2 {
434 int b;
435};
436
437struct C : B {
438 virtual void f();
439};
440void C::f() { }
441
442}
Anders Carlsson69dc04e2010-02-16 16:49:35 +0000443
444namespace Test11 {
445
446// Very simple test of vtables for virtual bases.
447struct A1 { int a; };
448struct A2 { int b; };
449
450struct B : A1, virtual A2 {
451 int b;
452};
453
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000454// CHECK-18: Vtable for 'Test11::C' (8 entries).
455// CHECK-18-NEXT: 0 | vbase_offset (24)
456// CHECK-18-NEXT: 1 | vbase_offset (8)
457// CHECK-18-NEXT: 2 | offset_to_top (0)
458// CHECK-18-NEXT: 3 | Test11::C RTTI
459// CHECK-18-NEXT: -- (Test11::C, 0) vtable address --
460// CHECK-18-NEXT: 4 | void Test11::C::f()
461// CHECK-18-NEXT: 5 | vbase_offset (16)
462// CHECK-18-NEXT: 6 | offset_to_top (-8)
463// CHECK-18-NEXT: 7 | Test11::C RTTI
Anders Carlsson69dc04e2010-02-16 16:49:35 +0000464struct C : virtual B {
465 virtual void f();
466};
467void C::f() { }
468
469}
Anders Carlsson92f54322010-02-23 03:26:17 +0000470
471namespace Test12 {
472
473// Test that the right vcall offsets are generated in the right order.
474
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000475// CHECK-19: Vtable for 'Test12::B' (19 entries).
476// CHECK-19-NEXT: 0 | vbase_offset (8)
477// CHECK-19-NEXT: 1 | offset_to_top (0)
478// CHECK-19-NEXT: 2 | Test12::B RTTI
479// CHECK-19-NEXT: -- (Test12::B, 0) vtable address --
480// CHECK-19-NEXT: 3 | void Test12::B::f()
481// CHECK-19-NEXT: 4 | void Test12::B::a()
482// CHECK-19-NEXT: 5 | vcall_offset (32)
483// CHECK-19-NEXT: 6 | vcall_offset (16)
484// CHECK-19-NEXT: 7 | vcall_offset (-8)
485// CHECK-19-NEXT: 8 | vcall_offset (0)
486// CHECK-19-NEXT: 9 | offset_to_top (-8)
487// CHECK-19-NEXT: 10 | Test12::B RTTI
488// CHECK-19-NEXT: -- (Test12::A, 8) vtable address --
489// CHECK-19-NEXT: -- (Test12::A1, 8) vtable address --
490// CHECK-19-NEXT: 11 | void Test12::A1::a1()
491// CHECK-19-NEXT: 12 | void Test12::B::a()
492// CHECK-19-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
493// CHECK-19-NEXT: 13 | offset_to_top (-24)
494// CHECK-19-NEXT: 14 | Test12::B RTTI
495// CHECK-19-NEXT: -- (Test12::A2, 24) vtable address --
496// CHECK-19-NEXT: 15 | void Test12::A2::a2()
497// CHECK-19-NEXT: 16 | offset_to_top (-40)
498// CHECK-19-NEXT: 17 | Test12::B RTTI
499// CHECK-19-NEXT: -- (Test12::A3, 40) vtable address --
500// CHECK-19-NEXT: 18 | void Test12::A3::a3()
Anders Carlsson92f54322010-02-23 03:26:17 +0000501struct A1 {
502 virtual void a1();
503 int a;
504};
505
506struct A2 {
507 virtual void a2();
508 int a;
509};
510
511struct A3 {
512 virtual void a3();
513 int a;
514};
515
516struct A : A1, A2, A3 {
517 virtual void a();
518 int i;
519};
520
521struct B : virtual A {
522 virtual void f();
523
524 virtual void a();
525};
526void B::f() { }
527
528}
Anders Carlssonaf280c02010-02-23 03:48:14 +0000529
530namespace Test13 {
531
532// Test that we don't try to emit a vtable for 'A' twice.
533struct A {
534 virtual void f();
535};
536
537struct B : virtual A {
538 virtual void f();
539};
540
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000541// CHECK-20: Vtable for 'Test13::C' (6 entries).
542// CHECK-20-NEXT: 0 | vbase_offset (0)
543// CHECK-20-NEXT: 1 | vbase_offset (0)
544// CHECK-20-NEXT: 2 | vcall_offset (0)
545// CHECK-20-NEXT: 3 | offset_to_top (0)
546// CHECK-20-NEXT: 4 | Test13::C RTTI
547// CHECK-20-NEXT: -- (Test13::A, 0) vtable address --
548// CHECK-20-NEXT: -- (Test13::B, 0) vtable address --
549// CHECK-20-NEXT: -- (Test13::C, 0) vtable address --
550// CHECK-20-NEXT: 5 | void Test13::C::f()
Anders Carlssonaf280c02010-02-23 03:48:14 +0000551struct C : virtual B, virtual A {
552 virtual void f();
553};
554void C::f() { }
555
556}
557
Anders Carlssonbf554f62010-02-25 22:18:35 +0000558namespace Test14 {
559
560// Verify that we handle A being a non-virtual base of B, which is a virtual base.
561
562struct A {
563 virtual void f();
564};
565
566struct B : A { };
567
568struct C : virtual B { };
569
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000570// CHECK-21: Vtable for 'Test14::D' (5 entries).
571// CHECK-21-NEXT: 0 | vbase_offset (0)
572// CHECK-21-NEXT: 1 | vcall_offset (0)
573// CHECK-21-NEXT: 2 | offset_to_top (0)
574// CHECK-21-NEXT: 3 | Test14::D RTTI
575// CHECK-21-NEXT: -- (Test14::A, 0) vtable address --
576// CHECK-21-NEXT: -- (Test14::B, 0) vtable address --
577// CHECK-21-NEXT: -- (Test14::C, 0) vtable address --
578// CHECK-21-NEXT: -- (Test14::D, 0) vtable address --
579// CHECK-21-NEXT: 4 | void Test14::D::f()
Anders Carlssonbf554f62010-02-25 22:18:35 +0000580struct D : C, virtual B {
581 virtual void f();
582};
583void D::f() { }
584
585}
586
Anders Carlsson08c26752010-02-27 04:05:52 +0000587namespace Test15 {
588
589// Test that we don't emit an extra vtable for B since it's a primary base of C.
590struct A { virtual void a(); };
591struct B { virtual void b(); };
592
593struct C : virtual B { };
594
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000595// CHECK-22: Vtable for 'Test15::D' (11 entries).
596// CHECK-22-NEXT: 0 | vbase_offset (8)
597// CHECK-22-NEXT: 1 | vbase_offset (8)
598// CHECK-22-NEXT: 2 | offset_to_top (0)
599// CHECK-22-NEXT: 3 | Test15::D RTTI
600// CHECK-22-NEXT: -- (Test15::A, 0) vtable address --
601// CHECK-22-NEXT: -- (Test15::D, 0) vtable address --
602// CHECK-22-NEXT: 4 | void Test15::A::a()
603// CHECK-22-NEXT: 5 | void Test15::D::f()
604// CHECK-22-NEXT: 6 | vbase_offset (0)
605// CHECK-22-NEXT: 7 | vcall_offset (0)
606// CHECK-22-NEXT: 8 | offset_to_top (-8)
607// CHECK-22-NEXT: 9 | Test15::D RTTI
608// CHECK-22-NEXT: -- (Test15::B, 8) vtable address --
609// CHECK-22-NEXT: -- (Test15::C, 8) vtable address --
610// CHECK-22-NEXT: 10 | void Test15::B::b()
Anders Carlsson08c26752010-02-27 04:05:52 +0000611struct D : A, virtual B, virtual C {
612 virtual void f();
613};
614void D::f() { }
615
616}
Anders Carlsson55609692010-02-27 04:12:52 +0000617
618namespace Test16 {
619
620// Test that destructors share vcall offsets.
621
622struct A { virtual ~A(); };
623struct B { virtual ~B(); };
624
625struct C : A, B { virtual ~C(); };
626
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000627// CHECK-23: Vtable for 'Test16::D' (15 entries).
628// CHECK-23-NEXT: 0 | vbase_offset (8)
629// CHECK-23-NEXT: 1 | offset_to_top (0)
630// CHECK-23-NEXT: 2 | Test16::D RTTI
631// CHECK-23-NEXT: -- (Test16::D, 0) vtable address --
632// CHECK-23-NEXT: 3 | void Test16::D::f()
633// CHECK-23-NEXT: 4 | Test16::D::~D() [complete]
634// CHECK-23-NEXT: 5 | Test16::D::~D() [deleting]
635// CHECK-23-NEXT: 6 | vcall_offset (-8)
636// CHECK-23-NEXT: 7 | offset_to_top (-8)
637// CHECK-23-NEXT: 8 | Test16::D RTTI
638// CHECK-23-NEXT: -- (Test16::A, 8) vtable address --
639// CHECK-23-NEXT: -- (Test16::C, 8) vtable address --
640// CHECK-23-NEXT: 9 | Test16::D::~D() [complete]
641// CHECK-23-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
642// CHECK-23-NEXT: 10 | Test16::D::~D() [deleting]
643// CHECK-23-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
644// CHECK-23-NEXT: 11 | offset_to_top (-16)
645// CHECK-23-NEXT: 12 | Test16::D RTTI
646// CHECK-23-NEXT: -- (Test16::B, 16) vtable address --
647// CHECK-23-NEXT: 13 | Test16::D::~D() [complete]
648// CHECK-23-NEXT: [this adjustment: -8 non-virtual, -24 vcall offset offset]
649// CHECK-23-NEXT: 14 | Test16::D::~D() [deleting]
650// CHECK-23-NEXT: [this adjustment: -8 non-virtual, -24 vcall offset offset]
Anders Carlsson55609692010-02-27 04:12:52 +0000651struct D : virtual C {
652 virtual void f();
653};
654void D::f() { }
655
656}
Anders Carlssonc784ba22010-02-27 06:38:03 +0000657
658namespace Test17 {
659
660// Test that we don't mark E::f in the C-in-E vtable as unused.
661struct A { virtual void f(); };
662struct B : virtual A { virtual void f(); };
663struct C : virtual A { virtual void f(); };
664struct D : virtual B, virtual C { virtual void f(); };
665
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000666// CHECK-24: Vtable for 'Test17::E' (13 entries).
667// CHECK-24-NEXT: 0 | vbase_offset (0)
668// CHECK-24-NEXT: 1 | vbase_offset (8)
669// CHECK-24-NEXT: 2 | vbase_offset (0)
670// CHECK-24-NEXT: 3 | vbase_offset (0)
671// CHECK-24-NEXT: 4 | vcall_offset (0)
672// CHECK-24-NEXT: 5 | offset_to_top (0)
673// CHECK-24-NEXT: 6 | Test17::E RTTI
674// CHECK-24-NEXT: -- (Test17::A, 0) vtable address --
675// CHECK-24-NEXT: -- (Test17::B, 0) vtable address --
676// CHECK-24-NEXT: -- (Test17::D, 0) vtable address --
677// CHECK-24-NEXT: -- (Test17::E, 0) vtable address --
678// CHECK-24-NEXT: 7 | void Test17::E::f()
679// CHECK-24-NEXT: 8 | vbase_offset (-8)
680// CHECK-24-NEXT: 9 | vcall_offset (-8)
681// CHECK-24-NEXT: 10 | offset_to_top (-8)
682// CHECK-24-NEXT: 11 | Test17::E RTTI
683// CHECK-24-NEXT: -- (Test17::C, 8) vtable address --
684// CHECK-24-NEXT: 12 | void Test17::E::f()
685// CHECK-24-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
Anders Carlssonc784ba22010-02-27 06:38:03 +0000686class E : virtual D {
687 virtual void f();
688};
689void E::f() {}
690
691}
Anders Carlsson2ef9d6b2010-02-27 16:52:49 +0000692
693namespace Test18 {
694
695// Test that we compute the right 'this' adjustment offsets.
696
697struct A {
698 virtual void f();
699 virtual void g();
700};
701
702struct B : virtual A {
703 virtual void f();
704};
705
706struct C : A, B {
707 virtual void g();
708};
709
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000710// CHECK-25: Vtable for 'Test18::D' (24 entries).
711// CHECK-25-NEXT: 0 | vbase_offset (8)
712// CHECK-25-NEXT: 1 | vbase_offset (0)
713// CHECK-25-NEXT: 2 | vbase_offset (0)
714// CHECK-25-NEXT: 3 | vcall_offset (8)
715// CHECK-25-NEXT: 4 | vcall_offset (0)
716// CHECK-25-NEXT: 5 | offset_to_top (0)
717// CHECK-25-NEXT: 6 | Test18::D RTTI
718// CHECK-25-NEXT: -- (Test18::A, 0) vtable address --
719// CHECK-25-NEXT: -- (Test18::B, 0) vtable address --
720// CHECK-25-NEXT: -- (Test18::D, 0) vtable address --
721// CHECK-25-NEXT: 7 | void Test18::D::f()
722// CHECK-25-NEXT: 8 | void Test18::C::g()
723// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
724// CHECK-25-NEXT: 9 | void Test18::D::h()
725// CHECK-25-NEXT: 10 | vcall_offset (0)
726// CHECK-25-NEXT: 11 | vcall_offset (-8)
727// CHECK-25-NEXT: 12 | vbase_offset (-8)
728// CHECK-25-NEXT: 13 | offset_to_top (-8)
729// CHECK-25-NEXT: 14 | Test18::D RTTI
730// CHECK-25-NEXT: -- (Test18::A, 8) vtable address --
731// CHECK-25-NEXT: -- (Test18::C, 8) vtable address --
732// CHECK-25-NEXT: 15 | void Test18::D::f()
733// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
734// CHECK-25-NEXT: 16 | void Test18::C::g()
735// CHECK-25-NEXT: 17 | vbase_offset (-16)
736// CHECK-25-NEXT: 18 | vcall_offset (-8)
737// CHECK-25-NEXT: 19 | vcall_offset (-16)
738// CHECK-25-NEXT: 20 | offset_to_top (-16)
739// CHECK-25-NEXT: 21 | Test18::D RTTI
740// CHECK-25-NEXT: -- (Test18::B, 16) vtable address --
741// CHECK-25-NEXT: 22 | void Test18::D::f()
742// CHECK-25-NEXT: [this adjustment: -8 non-virtual, -32 vcall offset offset]
743// CHECK-25-NEXT: 23 | [unused] void Test18::C::g()
Anders Carlsson2bc1d3a2010-03-10 21:25:37 +0000744
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000745// CHECK-25: Construction vtable for ('Test18::B', 0) in 'Test18::D' (7 entries).
746// CHECK-25-NEXT: 0 | vbase_offset (0)
747// CHECK-25-NEXT: 1 | vcall_offset (0)
748// CHECK-25-NEXT: 2 | vcall_offset (0)
749// CHECK-25-NEXT: 3 | offset_to_top (0)
750// CHECK-25-NEXT: 4 | Test18::B RTTI
751// CHECK-25-NEXT: -- (Test18::A, 0) vtable address --
752// CHECK-25-NEXT: -- (Test18::B, 0) vtable address --
753// CHECK-25-NEXT: 5 | void Test18::B::f()
754// CHECK-25-NEXT: 6 | void Test18::A::g()
Anders Carlsson2bc1d3a2010-03-10 21:25:37 +0000755
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000756// CHECK-25: Construction vtable for ('Test18::C', 8) in 'Test18::D' (20 entries).
757// CHECK-25-NEXT: 0 | vcall_offset (0)
758// CHECK-25-NEXT: 1 | vcall_offset (0)
759// CHECK-25-NEXT: 2 | vbase_offset (-8)
760// CHECK-25-NEXT: 3 | offset_to_top (0)
761// CHECK-25-NEXT: 4 | Test18::C RTTI
762// CHECK-25-NEXT: -- (Test18::A, 8) vtable address --
763// CHECK-25-NEXT: -- (Test18::C, 8) vtable address --
764// CHECK-25-NEXT: 5 | void Test18::A::f()
765// CHECK-25-NEXT: 6 | void Test18::C::g()
766// CHECK-25-NEXT: 7 | vbase_offset (-16)
767// CHECK-25-NEXT: 8 | vcall_offset (-8)
768// CHECK-25-NEXT: 9 | vcall_offset (0)
769// CHECK-25-NEXT: 10 | offset_to_top (-8)
770// CHECK-25-NEXT: 11 | Test18::C RTTI
771// CHECK-25-NEXT: -- (Test18::B, 16) vtable address --
772// CHECK-25-NEXT: 12 | void Test18::B::f()
773// CHECK-25-NEXT: 13 | [unused] void Test18::C::g()
774// CHECK-25-NEXT: 14 | vcall_offset (8)
775// CHECK-25-NEXT: 15 | vcall_offset (16)
776// CHECK-25-NEXT: 16 | offset_to_top (8)
777// CHECK-25-NEXT: 17 | Test18::C RTTI
778// CHECK-25-NEXT: -- (Test18::A, 0) vtable address --
779// CHECK-25-NEXT: 18 | void Test18::B::f()
780// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
781// CHECK-25-NEXT: 19 | void Test18::C::g()
782// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
Anders Carlsson2bc1d3a2010-03-10 21:25:37 +0000783
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000784// CHECK-25: Construction vtable for ('Test18::B', 16) in 'Test18::D' (13 entries).
785// CHECK-25-NEXT: 0 | vbase_offset (-16)
786// CHECK-25-NEXT: 1 | vcall_offset (-16)
787// CHECK-25-NEXT: 2 | vcall_offset (0)
788// CHECK-25-NEXT: 3 | offset_to_top (0)
789// CHECK-25-NEXT: 4 | Test18::B RTTI
790// CHECK-25-NEXT: -- (Test18::B, 16) vtable address --
791// CHECK-25-NEXT: 5 | void Test18::B::f()
792// CHECK-25-NEXT: 6 | [unused] void Test18::A::g()
793// CHECK-25-NEXT: 7 | vcall_offset (0)
794// CHECK-25-NEXT: 8 | vcall_offset (16)
795// CHECK-25-NEXT: 9 | offset_to_top (16)
796// CHECK-25-NEXT: 10 | Test18::B RTTI
797// CHECK-25-NEXT: -- (Test18::A, 0) vtable address --
798// CHECK-25-NEXT: 11 | void Test18::B::f()
799// CHECK-25-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
800// CHECK-25-NEXT: 12 | void Test18::A::g()
Anders Carlsson2ef9d6b2010-02-27 16:52:49 +0000801struct D : virtual B, virtual C, virtual A
802{
803 virtual void f();
804 virtual void h();
805};
806void D::f() {}
807
Anders Carlsson35044752010-02-27 16:55:58 +0000808}
809
810namespace Test19 {
811
812// Another 'this' adjustment test.
813
814struct A {
815 int a;
816
817 virtual void f();
818};
819
820struct B : A {
821 int b;
822
823 virtual void g();
824};
825
826struct C {
827 virtual void c();
828};
829
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000830// CHECK-26: Vtable for 'Test19::D' (13 entries).
831// CHECK-26-NEXT: 0 | vbase_offset (24)
832// CHECK-26-NEXT: 1 | offset_to_top (0)
833// CHECK-26-NEXT: 2 | Test19::D RTTI
834// CHECK-26-NEXT: -- (Test19::C, 0) vtable address --
835// CHECK-26-NEXT: -- (Test19::D, 0) vtable address --
836// CHECK-26-NEXT: 3 | void Test19::C::c()
837// CHECK-26-NEXT: 4 | void Test19::D::f()
838// CHECK-26-NEXT: 5 | offset_to_top (-8)
839// CHECK-26-NEXT: 6 | Test19::D RTTI
840// CHECK-26-NEXT: -- (Test19::A, 8) vtable address --
841// CHECK-26-NEXT: -- (Test19::B, 8) vtable address --
842// CHECK-26-NEXT: 7 | void Test19::D::f()
843// CHECK-26-NEXT: [this adjustment: -8 non-virtual]
844// CHECK-26-NEXT: 8 | void Test19::B::g()
845// CHECK-26-NEXT: 9 | vcall_offset (-24)
846// CHECK-26-NEXT: 10 | offset_to_top (-24)
847// CHECK-26-NEXT: 11 | Test19::D RTTI
848// CHECK-26-NEXT: -- (Test19::A, 24) vtable address --
849// CHECK-26-NEXT: 12 | void Test19::D::f()
850// CHECK-26-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
Anders Carlsson35044752010-02-27 16:55:58 +0000851struct D : C, B, virtual A {
852 virtual void f();
853};
854void D::f() { }
855
Anders Carlsson8bc68f72010-02-27 18:16:50 +0000856}
857
858namespace Test20 {
859
860// pure virtual member functions should never have 'this' adjustments.
861
862struct A {
863 virtual void f() = 0;
864 virtual void g();
865};
866
867struct B : A { };
868
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000869// CHECK-27: Vtable for 'Test20::C' (9 entries).
870// CHECK-27-NEXT: 0 | offset_to_top (0)
871// CHECK-27-NEXT: 1 | Test20::C RTTI
872// CHECK-27-NEXT: -- (Test20::A, 0) vtable address --
873// CHECK-27-NEXT: -- (Test20::C, 0) vtable address --
874// CHECK-27-NEXT: 2 | void Test20::C::f() [pure]
875// CHECK-27-NEXT: 3 | void Test20::A::g()
876// CHECK-27-NEXT: 4 | void Test20::C::h()
877// CHECK-27-NEXT: 5 | offset_to_top (-8)
878// CHECK-27-NEXT: 6 | Test20::C RTTI
879// CHECK-27-NEXT: -- (Test20::A, 8) vtable address --
880// CHECK-27-NEXT: -- (Test20::B, 8) vtable address --
881// CHECK-27-NEXT: 7 | void Test20::C::f() [pure]
882// CHECK-27-NEXT: 8 | void Test20::A::g()
Anders Carlsson8bc68f72010-02-27 18:16:50 +0000883struct C : A, B {
884 virtual void f() = 0;
885 virtual void h();
886};
887void C::h() { }
888
889}
Anders Carlsson6a8c5b22010-02-27 19:21:58 +0000890
891namespace Test21 {
892
893// Test that we get vbase offsets right in secondary vtables.
894struct A {
895 virtual void f();
896};
897
898struct B : virtual A { };
899class C : virtual B { };
900class D : virtual C { };
901
902class E : virtual C { };
903
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000904// CHECK-28: Vtable for 'Test21::F' (16 entries).
905// CHECK-28-NEXT: 0 | vbase_offset (8)
906// CHECK-28-NEXT: 1 | vbase_offset (0)
907// CHECK-28-NEXT: 2 | vbase_offset (0)
908// CHECK-28-NEXT: 3 | vbase_offset (0)
909// CHECK-28-NEXT: 4 | vbase_offset (0)
910// CHECK-28-NEXT: 5 | vcall_offset (0)
911// CHECK-28-NEXT: 6 | offset_to_top (0)
912// CHECK-28-NEXT: 7 | Test21::F RTTI
913// CHECK-28-NEXT: -- (Test21::A, 0) vtable address --
914// CHECK-28-NEXT: -- (Test21::B, 0) vtable address --
915// CHECK-28-NEXT: -- (Test21::C, 0) vtable address --
916// CHECK-28-NEXT: -- (Test21::D, 0) vtable address --
917// CHECK-28-NEXT: -- (Test21::F, 0) vtable address --
918// CHECK-28-NEXT: 8 | void Test21::F::f()
919// CHECK-28-NEXT: 9 | vbase_offset (-8)
920// CHECK-28-NEXT: 10 | vbase_offset (-8)
921// CHECK-28-NEXT: 11 | vbase_offset (-8)
922// CHECK-28-NEXT: 12 | vcall_offset (-8)
923// CHECK-28-NEXT: 13 | offset_to_top (-8)
924// CHECK-28-NEXT: 14 | Test21::F RTTI
925// CHECK-28-NEXT: -- (Test21::E, 8) vtable address --
926// CHECK-28-NEXT: 15 | [unused] void Test21::F::f()
Anders Carlsson127e4672010-03-11 06:44:31 +0000927//
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000928// CHECK-28: Virtual base offset offsets for 'Test21::F' (5 entries).
929// CHECK-28-NEXT: Test21::A | -32
930// CHECK-28-NEXT: Test21::B | -40
931// CHECK-28-NEXT: Test21::C | -48
932// CHECK-28-NEXT: Test21::D | -56
933// CHECK-28-NEXT: Test21::E | -64
Anders Carlsson6a8c5b22010-02-27 19:21:58 +0000934class F : virtual D, virtual E {
935 virtual void f();
936};
937void F::f() { }
938
939}
Anders Carlsson0041a642010-02-27 21:09:00 +0000940
941namespace Test22 {
942
943// Very simple construction vtable test.
944struct V1 {
945 int v1;
946};
947
948struct V2 : virtual V1 {
949 int v2;
950};
951
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000952// CHECK-29: Vtable for 'Test22::C' (8 entries).
953// CHECK-29-NEXT: 0 | vbase_offset (16)
954// CHECK-29-NEXT: 1 | vbase_offset (12)
955// CHECK-29-NEXT: 2 | offset_to_top (0)
956// CHECK-29-NEXT: 3 | Test22::C RTTI
957// CHECK-29-NEXT: -- (Test22::C, 0) vtable address --
958// CHECK-29-NEXT: 4 | void Test22::C::f()
959// CHECK-29-NEXT: 5 | vbase_offset (-4)
960// CHECK-29-NEXT: 6 | offset_to_top (-16)
961// CHECK-29-NEXT: 7 | Test22::C RTTI
962// CHECK-29-NEXT: -- (Test22::V2, 16) vtable address --
Anders Carlsson0041a642010-02-27 21:09:00 +0000963
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000964// CHECK-29: Construction vtable for ('Test22::V2', 16) in 'Test22::C' (3 entries).
965// CHECK-29-NEXT: 0 | vbase_offset (-4)
966// CHECK-29-NEXT: 1 | offset_to_top (0)
967// CHECK-29-NEXT: 2 | Test22::V2 RTTI
Anders Carlsson0041a642010-02-27 21:09:00 +0000968
969struct C : virtual V1, virtual V2 {
970 int c;
971 virtual void f();
972};
973void C::f() { }
974
975}
Anders Carlsson530c40c2010-02-28 01:43:58 +0000976
977namespace Test23 {
978
979struct A {
980 int a;
981};
982
983struct B : virtual A {
984 int b;
985};
986
987struct C : A, virtual B {
988 int c;
989};
990
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000991// CHECK-30: Vtable for 'Test23::D' (7 entries).
992// CHECK-30-NEXT: 0 | vbase_offset (20)
993// CHECK-30-NEXT: 1 | vbase_offset (24)
994// CHECK-30-NEXT: 2 | offset_to_top (0)
995// CHECK-30-NEXT: 3 | Test23::D RTTI
996// CHECK-30-NEXT: -- (Test23::C, 0) vtable address --
997// CHECK-30-NEXT: -- (Test23::D, 0) vtable address --
998// CHECK-30-NEXT: 4 | vbase_offset (-4)
999// CHECK-30-NEXT: 5 | offset_to_top (-24)
1000// CHECK-30-NEXT: 6 | Test23::D RTTI
1001// CHECK-30-NEXT: -- (Test23::B, 24) vtable address --
Anders Carlsson530c40c2010-02-28 01:43:58 +00001002
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001003// CHECK-30: Construction vtable for ('Test23::C', 0) in 'Test23::D' (7 entries).
1004// CHECK-30-NEXT: 0 | vbase_offset (20)
1005// CHECK-30-NEXT: 1 | vbase_offset (24)
1006// CHECK-30-NEXT: 2 | offset_to_top (0)
1007// CHECK-30-NEXT: 3 | Test23::C RTTI
1008// CHECK-30-NEXT: -- (Test23::C, 0) vtable address --
1009// CHECK-30-NEXT: 4 | vbase_offset (-4)
1010// CHECK-30-NEXT: 5 | offset_to_top (-24)
1011// CHECK-30-NEXT: 6 | Test23::C RTTI
1012// CHECK-30-NEXT: -- (Test23::B, 24) vtable address --
Anders Carlsson530c40c2010-02-28 01:43:58 +00001013
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001014// CHECK-30: Construction vtable for ('Test23::B', 24) in 'Test23::D' (3 entries).
1015// CHECK-30-NEXT: 0 | vbase_offset (-4)
1016// CHECK-30-NEXT: 1 | offset_to_top (0)
1017// CHECK-30-NEXT: 2 | Test23::B RTTI
1018// CHECK-30-NEXT: -- (Test23::B, 24) vtable address --
Anders Carlsson530c40c2010-02-28 01:43:58 +00001019
1020struct D : virtual A, virtual B, C {
1021 int d;
1022
1023 void f();
1024};
1025void D::f() { }
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001026 D d;
Anders Carlsson530c40c2010-02-28 01:43:58 +00001027}
Anders Carlsson293126b2010-02-28 17:59:36 +00001028
1029namespace Test24 {
1030
1031// Another construction vtable test.
1032
Anders Carlsson0378bf02010-02-28 18:08:38 +00001033struct A {
1034 virtual void f();
1035};
1036
1037struct B : virtual A { };
1038struct C : virtual A { };
1039
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001040// CHECK-31: Vtable for 'Test24::D' (10 entries).
1041// CHECK-31-NEXT: 0 | vbase_offset (0)
1042// CHECK-31-NEXT: 1 | vcall_offset (0)
1043// CHECK-31-NEXT: 2 | offset_to_top (0)
1044// CHECK-31-NEXT: 3 | Test24::D RTTI
1045// CHECK-31-NEXT: -- (Test24::A, 0) vtable address --
1046// CHECK-31-NEXT: -- (Test24::B, 0) vtable address --
1047// CHECK-31-NEXT: -- (Test24::D, 0) vtable address --
1048// CHECK-31-NEXT: 4 | void Test24::D::f()
1049// CHECK-31-NEXT: 5 | vbase_offset (-8)
1050// CHECK-31-NEXT: 6 | vcall_offset (-8)
1051// CHECK-31-NEXT: 7 | offset_to_top (-8)
1052// CHECK-31-NEXT: 8 | Test24::D RTTI
1053// CHECK-31-NEXT: -- (Test24::C, 8) vtable address --
1054// CHECK-31-NEXT: 9 | [unused] void Test24::D::f()
Anders Carlsson293126b2010-02-28 17:59:36 +00001055
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001056// CHECK-31: Construction vtable for ('Test24::B', 0) in 'Test24::D' (5 entries).
1057// CHECK-31-NEXT: 0 | vbase_offset (0)
1058// CHECK-31-NEXT: 1 | vcall_offset (0)
1059// CHECK-31-NEXT: 2 | offset_to_top (0)
1060// CHECK-31-NEXT: 3 | Test24::B RTTI
1061// CHECK-31-NEXT: -- (Test24::A, 0) vtable address --
1062// CHECK-31-NEXT: -- (Test24::B, 0) vtable address --
1063// CHECK-31-NEXT: 4 | void Test24::A::f()
Anders Carlsson293126b2010-02-28 17:59:36 +00001064
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001065// CHECK-31: Construction vtable for ('Test24::C', 8) in 'Test24::D' (9 entries).
1066// CHECK-31-NEXT: 0 | vbase_offset (-8)
1067// CHECK-31-NEXT: 1 | vcall_offset (-8)
1068// CHECK-31-NEXT: 2 | offset_to_top (0)
1069// CHECK-31-NEXT: 3 | Test24::C RTTI
1070// CHECK-31-NEXT: -- (Test24::C, 8) vtable address --
1071// CHECK-31-NEXT: 4 | [unused] void Test24::A::f()
1072// CHECK-31-NEXT: 5 | vcall_offset (0)
1073// CHECK-31-NEXT: 6 | offset_to_top (8)
1074// CHECK-31-NEXT: 7 | Test24::C RTTI
1075// CHECK-31-NEXT: -- (Test24::A, 0) vtable address --
1076// CHECK-31-NEXT: 8 | void Test24::A::f()
Anders Carlsson293126b2010-02-28 17:59:36 +00001077struct D : B, C {
1078 virtual void f();
1079};
1080void D::f() { }
Anders Carlssondad0f992010-02-28 18:37:33 +00001081
Anders Carlsson293126b2010-02-28 17:59:36 +00001082}
Anders Carlssonce57dd52010-03-03 04:58:02 +00001083
1084namespace Test25 {
1085
1086// This mainly tests that we don't assert on this class hierarchy.
1087
1088struct V {
1089 virtual void f();
1090};
1091
1092struct A : virtual V { };
1093struct B : virtual V { };
1094
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001095// CHECK-32: Vtable for 'Test25::C' (11 entries).
1096// CHECK-32-NEXT: 0 | vbase_offset (0)
1097// CHECK-32-NEXT: 1 | vcall_offset (0)
1098// CHECK-32-NEXT: 2 | offset_to_top (0)
1099// CHECK-32-NEXT: 3 | Test25::C RTTI
1100// CHECK-32-NEXT: -- (Test25::A, 0) vtable address --
1101// CHECK-32-NEXT: -- (Test25::C, 0) vtable address --
1102// CHECK-32-NEXT: -- (Test25::V, 0) vtable address --
1103// CHECK-32-NEXT: 4 | void Test25::V::f()
1104// CHECK-32-NEXT: 5 | void Test25::C::g()
1105// CHECK-32-NEXT: 6 | vbase_offset (-8)
1106// CHECK-32-NEXT: 7 | vcall_offset (-8)
1107// CHECK-32-NEXT: 8 | offset_to_top (-8)
1108// CHECK-32-NEXT: 9 | Test25::C RTTI
1109// CHECK-32-NEXT: -- (Test25::B, 8) vtable address --
1110// CHECK-32-NEXT: 10 | [unused] void Test25::V::f()
Anders Carlssonce57dd52010-03-03 04:58:02 +00001111
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001112// CHECK-32: Construction vtable for ('Test25::A', 0) in 'Test25::C' (5 entries).
1113// CHECK-32-NEXT: 0 | vbase_offset (0)
1114// CHECK-32-NEXT: 1 | vcall_offset (0)
1115// CHECK-32-NEXT: 2 | offset_to_top (0)
1116// CHECK-32-NEXT: 3 | Test25::A RTTI
1117// CHECK-32-NEXT: -- (Test25::A, 0) vtable address --
1118// CHECK-32-NEXT: -- (Test25::V, 0) vtable address --
1119// CHECK-32-NEXT: 4 | void Test25::V::f()
Anders Carlssonce57dd52010-03-03 04:58:02 +00001120
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001121// CHECK-32: Construction vtable for ('Test25::B', 8) in 'Test25::C' (9 entries).
1122// CHECK-32-NEXT: 0 | vbase_offset (-8)
1123// CHECK-32-NEXT: 1 | vcall_offset (-8)
1124// CHECK-32-NEXT: 2 | offset_to_top (0)
1125// CHECK-32-NEXT: 3 | Test25::B RTTI
1126// CHECK-32-NEXT: -- (Test25::B, 8) vtable address --
1127// CHECK-32-NEXT: 4 | [unused] void Test25::V::f()
1128// CHECK-32-NEXT: 5 | vcall_offset (0)
1129// CHECK-32-NEXT: 6 | offset_to_top (8)
1130// CHECK-32-NEXT: 7 | Test25::B RTTI
1131// CHECK-32-NEXT: -- (Test25::V, 0) vtable address --
1132// CHECK-32-NEXT: 8 | void Test25::V::f()
Anders Carlssonce57dd52010-03-03 04:58:02 +00001133struct C : A, virtual V, B {
1134 virtual void g();
1135};
1136void C::g() { }
1137
1138}
Anders Carlsson60396612010-03-10 06:51:42 +00001139
1140namespace Test26 {
1141
1142// Test that we generate the right number of entries in the C-in-D construction vtable, and that
1143// we don't mark A::a as unused.
1144
1145struct A {
1146 virtual void a();
1147};
1148
1149struct B {
1150 virtual void c();
1151};
1152
1153struct C : virtual A {
1154 virtual void b();
1155};
1156
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001157// CHECK-33: Vtable for 'Test26::D' (15 entries).
1158// CHECK-33-NEXT: 0 | vbase_offset (8)
1159// CHECK-33-NEXT: 1 | vbase_offset (8)
1160// CHECK-33-NEXT: 2 | vbase_offset (0)
1161// CHECK-33-NEXT: 3 | vcall_offset (0)
1162// CHECK-33-NEXT: 4 | offset_to_top (0)
1163// CHECK-33-NEXT: 5 | Test26::D RTTI
1164// CHECK-33-NEXT: -- (Test26::B, 0) vtable address --
1165// CHECK-33-NEXT: -- (Test26::D, 0) vtable address --
1166// CHECK-33-NEXT: 6 | void Test26::B::c()
1167// CHECK-33-NEXT: 7 | void Test26::D::d()
1168// CHECK-33-NEXT: 8 | vcall_offset (0)
1169// CHECK-33-NEXT: 9 | vbase_offset (0)
1170// CHECK-33-NEXT: 10 | vcall_offset (0)
1171// CHECK-33-NEXT: 11 | offset_to_top (-8)
1172// CHECK-33-NEXT: 12 | Test26::D RTTI
1173// CHECK-33-NEXT: -- (Test26::A, 8) vtable address --
1174// CHECK-33-NEXT: -- (Test26::C, 8) vtable address --
1175// CHECK-33-NEXT: 13 | void Test26::A::a()
1176// CHECK-33-NEXT: 14 | void Test26::C::b()
Anders Carlsson60396612010-03-10 06:51:42 +00001177
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001178// CHECK-33: Construction vtable for ('Test26::C', 8) in 'Test26::D' (7 entries).
1179// CHECK-33-NEXT: 0 | vcall_offset (0)
1180// CHECK-33-NEXT: 1 | vbase_offset (0)
1181// CHECK-33-NEXT: 2 | vcall_offset (0)
1182// CHECK-33-NEXT: 3 | offset_to_top (0)
1183// CHECK-33-NEXT: 4 | Test26::C RTTI
1184// CHECK-33-NEXT: -- (Test26::A, 8) vtable address --
1185// CHECK-33-NEXT: -- (Test26::C, 8) vtable address --
1186// CHECK-33-NEXT: 5 | void Test26::A::a()
1187// CHECK-33-NEXT: 6 | void Test26::C::b()
Anders Carlsson60396612010-03-10 06:51:42 +00001188class D : virtual B, virtual C {
1189 virtual void d();
1190};
1191void D::d() { }
1192
Anders Carlssone35b7682010-03-10 06:51:56 +00001193}
Anders Carlssonf2c98ce2010-03-10 19:15:26 +00001194
1195namespace Test27 {
1196
1197// Test that we don't generate a secondary vtable for C in the D-in-E vtable, since
1198// C doesn't have any virtual bases.
1199
1200struct A {
1201 virtual void a();
1202};
1203
1204struct B {
1205 virtual void b();
1206};
1207
1208struct C {
1209 virtual void c();
1210};
1211
1212struct D : A, virtual B, C {
1213 virtual void d();
1214};
1215
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001216// CHECK-34: Vtable for 'Test27::E' (13 entries).
1217// CHECK-34-NEXT: 0 | vbase_offset (16)
1218// CHECK-34-NEXT: 1 | offset_to_top (0)
1219// CHECK-34-NEXT: 2 | Test27::E RTTI
1220// CHECK-34-NEXT: -- (Test27::A, 0) vtable address --
1221// CHECK-34-NEXT: -- (Test27::D, 0) vtable address --
1222// CHECK-34-NEXT: -- (Test27::E, 0) vtable address --
1223// CHECK-34-NEXT: 3 | void Test27::A::a()
1224// CHECK-34-NEXT: 4 | void Test27::D::d()
1225// CHECK-34-NEXT: 5 | void Test27::E::e()
1226// CHECK-34-NEXT: 6 | offset_to_top (-8)
1227// CHECK-34-NEXT: 7 | Test27::E RTTI
1228// CHECK-34-NEXT: -- (Test27::C, 8) vtable address --
1229// CHECK-34-NEXT: 8 | void Test27::C::c()
1230// CHECK-34-NEXT: 9 | vcall_offset (0)
1231// CHECK-34-NEXT: 10 | offset_to_top (-16)
1232// CHECK-34-NEXT: 11 | Test27::E RTTI
1233// CHECK-34-NEXT: -- (Test27::B, 16) vtable address --
1234// CHECK-34-NEXT: 12 | void Test27::B::b()
Anders Carlssonf2c98ce2010-03-10 19:15:26 +00001235
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001236// CHECK-34: Construction vtable for ('Test27::D', 0) in 'Test27::E' (9 entries).
1237// CHECK-34-NEXT: 0 | vbase_offset (16)
1238// CHECK-34-NEXT: 1 | offset_to_top (0)
1239// CHECK-34-NEXT: 2 | Test27::D RTTI
1240// CHECK-34-NEXT: -- (Test27::A, 0) vtable address --
1241// CHECK-34-NEXT: -- (Test27::D, 0) vtable address --
1242// CHECK-34-NEXT: 3 | void Test27::A::a()
1243// CHECK-34-NEXT: 4 | void Test27::D::d()
1244// CHECK-34-NEXT: 5 | vcall_offset (0)
1245// CHECK-34-NEXT: 6 | offset_to_top (-16)
1246// CHECK-34-NEXT: 7 | Test27::D RTTI
1247// CHECK-34-NEXT: -- (Test27::B, 16) vtable address --
1248// CHECK-34-NEXT: 8 | void Test27::B::b()
Anders Carlssonf2c98ce2010-03-10 19:15:26 +00001249struct E : D {
1250 virtual void e();
1251};
1252void E::e() { }
Anders Carlssona96a2e92010-03-10 19:39:11 +00001253
1254}
1255
1256namespace Test28 {
1257
1258// Check that we do include the vtable for B in the D-in-E construction vtable, since
1259// B is a base class of a virtual base (C).
1260
1261struct A {
1262 virtual void a();
1263};
1264
1265struct B {
1266 virtual void b();
1267};
1268
1269struct C : A, B {
1270 virtual void c();
1271};
1272
1273struct D : virtual C {
1274};
1275
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001276// CHECK-35: Vtable for 'Test28::E' (14 entries).
1277// CHECK-35-NEXT: 0 | vbase_offset (8)
1278// CHECK-35-NEXT: 1 | offset_to_top (0)
1279// CHECK-35-NEXT: 2 | Test28::E RTTI
1280// CHECK-35-NEXT: -- (Test28::D, 0) vtable address --
1281// CHECK-35-NEXT: -- (Test28::E, 0) vtable address --
1282// CHECK-35-NEXT: 3 | void Test28::E::e()
1283// CHECK-35-NEXT: 4 | vcall_offset (8)
1284// CHECK-35-NEXT: 5 | vcall_offset (0)
1285// CHECK-35-NEXT: 6 | vcall_offset (0)
1286// CHECK-35-NEXT: 7 | offset_to_top (-8)
1287// CHECK-35-NEXT: 8 | Test28::E RTTI
1288// CHECK-35-NEXT: -- (Test28::A, 8) vtable address --
1289// CHECK-35-NEXT: -- (Test28::C, 8) vtable address --
1290// CHECK-35-NEXT: 9 | void Test28::A::a()
1291// CHECK-35-NEXT: 10 | void Test28::C::c()
1292// CHECK-35-NEXT: 11 | offset_to_top (-16)
1293// CHECK-35-NEXT: 12 | Test28::E RTTI
1294// CHECK-35-NEXT: -- (Test28::B, 16) vtable address --
1295// CHECK-35-NEXT: 13 | void Test28::B::b()
Anders Carlssona96a2e92010-03-10 19:39:11 +00001296
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001297// CHECK-35: Construction vtable for ('Test28::D', 0) in 'Test28::E' (13 entries).
1298// CHECK-35-NEXT: 0 | vbase_offset (8)
1299// CHECK-35-NEXT: 1 | offset_to_top (0)
1300// CHECK-35-NEXT: 2 | Test28::D RTTI
1301// CHECK-35-NEXT: -- (Test28::D, 0) vtable address --
1302// CHECK-35-NEXT: 3 | vcall_offset (8)
1303// CHECK-35-NEXT: 4 | vcall_offset (0)
1304// CHECK-35-NEXT: 5 | vcall_offset (0)
1305// CHECK-35-NEXT: 6 | offset_to_top (-8)
1306// CHECK-35-NEXT: 7 | Test28::D RTTI
1307// CHECK-35-NEXT: -- (Test28::A, 8) vtable address --
1308// CHECK-35-NEXT: -- (Test28::C, 8) vtable address --
1309// CHECK-35-NEXT: 8 | void Test28::A::a()
1310// CHECK-35-NEXT: 9 | void Test28::C::c()
1311// CHECK-35-NEXT: 10 | offset_to_top (-16)
1312// CHECK-35-NEXT: 11 | Test28::D RTTI
1313// CHECK-35-NEXT: -- (Test28::B, 16) vtable address --
1314// CHECK-35-NEXT: 12 | void Test28::B::b()
Anders Carlssona96a2e92010-03-10 19:39:11 +00001315struct E : D {
1316 virtual void e();
1317};
1318void E::e() { }
1319
Anders Carlssonf2c98ce2010-03-10 19:15:26 +00001320}
Anders Carlssonadb507d2010-03-29 15:08:41 +00001321
1322namespace Test29 {
1323
1324// Test that the covariant return thunk for B::f will have a virtual 'this' adjustment,
1325// matching gcc.
1326
1327struct V1 { };
1328struct V2 : virtual V1 { };
1329
1330struct A {
1331 virtual V1 *f();
1332};
1333
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001334// CHECK-36: Vtable for 'Test29::B' (6 entries).
1335// CHECK-36-NEXT: 0 | vbase_offset (0)
1336// CHECK-36-NEXT: 1 | vcall_offset (0)
1337// CHECK-36-NEXT: 2 | offset_to_top (0)
1338// CHECK-36-NEXT: 3 | Test29::B RTTI
1339// CHECK-36-NEXT: -- (Test29::A, 0) vtable address --
1340// CHECK-36-NEXT: -- (Test29::B, 0) vtable address --
1341// CHECK-36-NEXT: 4 | Test29::V2 *Test29::B::f()
1342// CHECK-36-NEXT: [return adjustment: 0 non-virtual, -24 vbase offset offset]
1343// CHECK-36-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
1344// CHECK-36-NEXT: 5 | Test29::V2 *Test29::B::f()
Anders Carlssonadb507d2010-03-29 15:08:41 +00001345struct B : virtual A {
1346 virtual V2 *f();
1347};
1348V2 *B::f() { return 0; }
1349
1350}
Anders Carlssonbdda6c12010-04-10 18:42:27 +00001351
1352namespace Test30 {
1353
1354// Test that we don't assert when generating a vtable for F.
1355struct A { };
1356
1357struct B : virtual A {
1358 int i;
1359};
1360
1361struct C {
1362 virtual void f();
1363};
1364
1365struct D : virtual C, B { };
1366struct E : virtual D { };
1367
1368struct F : E {
1369 virtual void f();
1370};
1371void F::f() { }
1372
1373}
Anders Carlssonf622b452010-04-10 20:39:29 +00001374
1375namespace Test31 {
1376
1377// Test that we don't add D::f twice to the primary vtable.
1378struct A {
1379 int a;
1380};
1381
1382struct B {
1383 virtual void f();
1384};
1385
1386struct C : A, virtual B {
1387 virtual void f();
1388};
1389
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001390// CHECK-37: Vtable for 'Test31::D' (11 entries).
1391// CHECK-37-NEXT: 0 | vbase_offset (0)
1392// CHECK-37-NEXT: 1 | vbase_offset (8)
1393// CHECK-37-NEXT: 2 | vcall_offset (0)
1394// CHECK-37-NEXT: 3 | offset_to_top (0)
1395// CHECK-37-NEXT: 4 | Test31::D RTTI
1396// CHECK-37-NEXT: -- (Test31::B, 0) vtable address --
1397// CHECK-37-NEXT: -- (Test31::D, 0) vtable address --
1398// CHECK-37-NEXT: 5 | void Test31::D::f()
1399// CHECK-37-NEXT: 6 | vbase_offset (-8)
1400// CHECK-37-NEXT: 7 | vcall_offset (-8)
1401// CHECK-37-NEXT: 8 | offset_to_top (-8)
1402// CHECK-37-NEXT: 9 | Test31::D RTTI
1403// CHECK-37-NEXT: -- (Test31::C, 8) vtable address --
1404// CHECK-37-NEXT: 10 | void Test31::D::f()
1405// CHECK-37-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
Anders Carlssonf622b452010-04-10 20:39:29 +00001406struct D : virtual C {
1407 virtual void f();
1408};
1409void D::f() { }
1410
1411}
Anders Carlsson573021f2010-04-10 21:35:33 +00001412
1413namespace Test32 {
1414
1415// Check that we correctly lay out the virtual bases of 'Test32::D'.
1416
1417struct A {
1418 virtual void f();
1419};
1420
1421struct B : virtual A { };
1422struct C : A, virtual B { };
1423struct D : virtual B { };
1424
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001425// CHECK-38: Virtual base offset offsets for 'Test32::E' (3 entries).
1426// CHECK-38-NEXT: Test32::A | -32
1427// CHECK-38-NEXT: Test32::B | -24
1428// CHECK-38-NEXT: Test32::D | -40
Anders Carlsson573021f2010-04-10 21:35:33 +00001429struct E : C, virtual D {
1430 virtual void f();
1431};
1432void E::f() { }
1433
1434}
Anders Carlssonaf6ddf22010-04-11 20:04:11 +00001435
1436namespace Test33 {
1437
1438// Test that we don't emit too many vcall offsets in 'Test32::F'.
1439
1440struct A {
1441 virtual void a();
1442};
1443
1444struct B {
1445 virtual void b();
1446};
1447
1448struct C : virtual A, virtual B {
1449 virtual void c();
1450};
1451
1452struct D : virtual C { };
1453
1454struct E : A, D {
1455 virtual void e();
1456};
1457
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001458// CHECK-39: Vtable for 'Test33::F' (30 entries).
1459// CHECK-39-NEXT: 0 | vbase_offset (24)
1460// CHECK-39-NEXT: 1 | vbase_offset (16)
1461// CHECK-39-NEXT: 2 | vbase_offset (16)
1462// CHECK-39-NEXT: 3 | vbase_offset (8)
1463// CHECK-39-NEXT: 4 | offset_to_top (0)
1464// CHECK-39-NEXT: 5 | Test33::F RTTI
1465// CHECK-39-NEXT: -- (Test33::A, 0) vtable address --
1466// CHECK-39-NEXT: -- (Test33::F, 0) vtable address --
1467// CHECK-39-NEXT: 6 | void Test33::A::a()
1468// CHECK-39-NEXT: 7 | void Test33::F::f()
1469// CHECK-39-NEXT: 8 | vcall_offset (0)
1470// CHECK-39-NEXT: 9 | vcall_offset (0)
1471// CHECK-39-NEXT: 10 | vbase_offset (16)
1472// CHECK-39-NEXT: 11 | vbase_offset (8)
1473// CHECK-39-NEXT: 12 | vbase_offset (8)
1474// CHECK-39-NEXT: 13 | offset_to_top (-8)
1475// CHECK-39-NEXT: 14 | Test33::F RTTI
1476// CHECK-39-NEXT: -- (Test33::A, 8) vtable address --
1477// CHECK-39-NEXT: -- (Test33::E, 8) vtable address --
1478// CHECK-39-NEXT: 15 | void Test33::A::a()
1479// CHECK-39-NEXT: 16 | void Test33::E::e()
1480// CHECK-39-NEXT: 17 | vbase_offset (0)
1481// CHECK-39-NEXT: 18 | vcall_offset (0)
1482// CHECK-39-NEXT: 19 | vbase_offset (8)
1483// CHECK-39-NEXT: 20 | vbase_offset (0)
1484// CHECK-39-NEXT: 21 | vcall_offset (0)
1485// CHECK-39-NEXT: 22 | offset_to_top (-16)
1486// CHECK-39-NEXT: 23 | Test33::F RTTI
1487// CHECK-39-NEXT: -- (Test33::A, 16) vtable address --
1488// CHECK-39-NEXT: -- (Test33::C, 16) vtable address --
1489// CHECK-39-NEXT: -- (Test33::D, 16) vtable address --
1490// CHECK-39-NEXT: 24 | void Test33::A::a()
1491// CHECK-39-NEXT: 25 | void Test33::C::c()
1492// CHECK-39-NEXT: 26 | vcall_offset (0)
1493// CHECK-39-NEXT: 27 | offset_to_top (-24)
1494// CHECK-39-NEXT: 28 | Test33::F RTTI
1495// CHECK-39-NEXT: -- (Test33::B, 24) vtable address --
1496// CHECK-39-NEXT: 29 | void Test33::B::b()
Anders Carlssonaf6ddf22010-04-11 20:04:11 +00001497struct F : virtual E, A {
1498 virtual void f();
1499};
1500void F::f() { }
1501
1502}
Anders Carlsson73e6fa02010-04-11 22:20:36 +00001503
1504namespace Test34 {
1505
Nick Lewycky69c05d52010-04-12 05:32:01 +00001506// Test that we lay out the construction vtable for 'Test34::E' in 'Test34::F' correctly.
Anders Carlsson73e6fa02010-04-11 22:20:36 +00001507
1508struct A {
1509 virtual void a();
1510};
1511struct B : virtual A { };
1512
1513struct C : B, A {
1514 virtual void c();
1515};
1516
1517struct D : A, C { };
1518
1519struct E : virtual D {
1520 virtual void e();
1521};
1522
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001523// CHECK-40: Construction vtable for ('Test34::E', 0) in 'Test34::F' (22 entries).
1524// CHECK-40-NEXT: 0 | vbase_offset (0)
1525// CHECK-40-NEXT: 1 | vbase_offset (8)
1526// CHECK-40-NEXT: 2 | vcall_offset (0)
1527// CHECK-40-NEXT: 3 | offset_to_top (0)
1528// CHECK-40-NEXT: 4 | Test34::E RTTI
1529// CHECK-40-NEXT: -- (Test34::A, 0) vtable address --
1530// CHECK-40-NEXT: -- (Test34::E, 0) vtable address --
1531// CHECK-40-NEXT: 5 | void Test34::A::a()
1532// CHECK-40-NEXT: 6 | void Test34::E::e()
1533// CHECK-40-NEXT: 7 | vcall_offset (8)
1534// CHECK-40-NEXT: 8 | vcall_offset (0)
1535// CHECK-40-NEXT: 9 | vbase_offset (-8)
1536// CHECK-40-NEXT: 10 | offset_to_top (-8)
1537// CHECK-40-NEXT: 11 | Test34::E RTTI
1538// CHECK-40-NEXT: -- (Test34::A, 8) vtable address --
1539// CHECK-40-NEXT: -- (Test34::D, 8) vtable address --
1540// CHECK-40-NEXT: 12 | void Test34::A::a()
1541// CHECK-40-NEXT: 13 | vbase_offset (-16)
1542// CHECK-40-NEXT: 14 | vcall_offset (-16)
1543// CHECK-40-NEXT: 15 | offset_to_top (-16)
1544// CHECK-40-NEXT: 16 | Test34::E RTTI
1545// CHECK-40-NEXT: -- (Test34::B, 16) vtable address --
1546// CHECK-40-NEXT: -- (Test34::C, 16) vtable address --
1547// CHECK-40-NEXT: 17 | [unused] void Test34::A::a()
1548// CHECK-40-NEXT: 18 | void Test34::C::c()
1549// CHECK-40-NEXT: 19 | offset_to_top (-24)
1550// CHECK-40-NEXT: 20 | Test34::E RTTI
1551// CHECK-40-NEXT: -- (Test34::A, 24) vtable address --
1552// CHECK-40-NEXT: 21 | void Test34::A::a()
Anders Carlsson73e6fa02010-04-11 22:20:36 +00001553struct F : E {
1554 virtual void f();
1555};
1556void F::f() { }
1557
1558}
Anders Carlsson97913572010-04-15 16:12:58 +00001559
1560namespace Test35 {
1561
1562// Test that we lay out the virtual bases of 'Test35::H' in the correct order.
1563
1564struct A {
1565 virtual void a();
1566
1567 int i;
1568};
1569
1570struct B : virtual A {
1571 virtual void b();
1572};
1573
1574struct C {
1575 virtual void c();
1576};
1577
1578struct D : C, virtual B {
1579 virtual void d();
1580};
1581
1582struct E : D {
1583 virtual void e();
1584
1585 bool b;
1586};
1587
1588struct F : virtual D { };
1589struct G : virtual E { };
1590
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001591// CHECK-41: Vtable for 'Test35::H' (32 entries).
1592// CHECK-41-NEXT: 0 | vbase_offset (32)
1593// CHECK-41-NEXT: 1 | vbase_offset (0)
1594// CHECK-41-NEXT: 2 | vcall_offset (0)
1595// CHECK-41-NEXT: 3 | vcall_offset (0)
1596// CHECK-41-NEXT: 4 | vbase_offset (16)
1597// CHECK-41-NEXT: 5 | vbase_offset (8)
1598// CHECK-41-NEXT: 6 | offset_to_top (0)
1599// CHECK-41-NEXT: 7 | Test35::H RTTI
1600// CHECK-41-NEXT: -- (Test35::C, 0) vtable address --
1601// CHECK-41-NEXT: -- (Test35::D, 0) vtable address --
1602// CHECK-41-NEXT: -- (Test35::F, 0) vtable address --
1603// CHECK-41-NEXT: -- (Test35::H, 0) vtable address --
1604// CHECK-41-NEXT: 8 | void Test35::C::c()
1605// CHECK-41-NEXT: 9 | void Test35::D::d()
1606// CHECK-41-NEXT: 10 | void Test35::H::h()
1607// CHECK-41-NEXT: 11 | vbase_offset (0)
1608// CHECK-41-NEXT: 12 | vbase_offset (24)
1609// CHECK-41-NEXT: 13 | vcall_offset (0)
1610// CHECK-41-NEXT: 14 | vbase_offset (8)
1611// CHECK-41-NEXT: 15 | offset_to_top (-8)
1612// CHECK-41-NEXT: 16 | Test35::H RTTI
1613// CHECK-41-NEXT: -- (Test35::B, 8) vtable address --
1614// CHECK-41-NEXT: -- (Test35::G, 8) vtable address --
1615// CHECK-41-NEXT: 17 | void Test35::B::b()
1616// CHECK-41-NEXT: 18 | vcall_offset (0)
1617// CHECK-41-NEXT: 19 | offset_to_top (-16)
1618// CHECK-41-NEXT: 20 | Test35::H RTTI
1619// CHECK-41-NEXT: -- (Test35::A, 16) vtable address --
1620// CHECK-41-NEXT: 21 | void Test35::A::a()
1621// CHECK-41-NEXT: 22 | vcall_offset (0)
1622// CHECK-41-NEXT: 23 | vcall_offset (0)
1623// CHECK-41-NEXT: 24 | vcall_offset (0)
1624// CHECK-41-NEXT: 25 | vbase_offset (-16)
1625// CHECK-41-NEXT: 26 | vbase_offset (-24)
1626// CHECK-41-NEXT: 27 | offset_to_top (-32)
1627// CHECK-41-NEXT: 28 | Test35::H RTTI
1628// CHECK-41-NEXT: -- (Test35::C, 32) vtable address --
1629// CHECK-41-NEXT: -- (Test35::D, 32) vtable address --
1630// CHECK-41-NEXT: -- (Test35::E, 32) vtable address --
1631// CHECK-41-NEXT: 29 | void Test35::C::c()
1632// CHECK-41-NEXT: 30 | void Test35::D::d()
1633// CHECK-41-NEXT: 31 | void Test35::E::e()
Anders Carlsson97913572010-04-15 16:12:58 +00001634
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001635// CHECK-41: Virtual base offset offsets for 'Test35::H' (4 entries).
1636// CHECK-41-NEXT: Test35::A | -32
1637// CHECK-41-NEXT: Test35::B | -24
1638// CHECK-41-NEXT: Test35::D | -56
1639// CHECK-41-NEXT: Test35::E | -64
Anders Carlsson97913572010-04-15 16:12:58 +00001640struct H : F, G {
1641 virtual void h();
1642};
1643void H::h() { }
1644
1645}
Anders Carlssonfbf05612010-04-17 17:24:33 +00001646
1647namespace Test36 {
1648
1649// Test that we don't mark B::f as unused in the vtable for D.
1650
1651struct A {
1652 virtual void f();
1653};
1654
1655struct B : virtual A { };
1656
1657struct C : virtual A {
1658 virtual void f();
1659};
1660
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001661// CHECK-42: Vtable for 'Test36::D' (12 entries).
1662// CHECK-42-NEXT: 0 | vbase_offset (8)
1663// CHECK-42-NEXT: 1 | vbase_offset (8)
1664// CHECK-42-NEXT: 2 | vcall_offset (0)
1665// CHECK-42-NEXT: 3 | offset_to_top (0)
1666// CHECK-42-NEXT: 4 | Test36::D RTTI
1667// CHECK-42-NEXT: -- (Test36::C, 0) vtable address --
1668// CHECK-42-NEXT: -- (Test36::D, 0) vtable address --
1669// CHECK-42-NEXT: 5 | void Test36::C::f()
1670// CHECK-42-NEXT: 6 | void Test36::D::g()
1671// CHECK-42-NEXT: 7 | vbase_offset (0)
1672// CHECK-42-NEXT: 8 | vcall_offset (-8)
1673// CHECK-42-NEXT: 9 | offset_to_top (-8)
1674// CHECK-42-NEXT: 10 | Test36::D RTTI
1675// CHECK-42-NEXT: -- (Test36::A, 8) vtable address --
1676// CHECK-42-NEXT: -- (Test36::B, 8) vtable address --
1677// CHECK-42-NEXT: 11 | void Test36::C::f()
1678// CHECK-42-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
Anders Carlssonfbf05612010-04-17 17:24:33 +00001679struct D : virtual B, C {
1680 virtual void g();
1681};
1682void D::g() { }
1683
1684}
Anders Carlssonb8bced02011-04-10 18:00:32 +00001685
1686namespace Test37 {
1687
1688// Test that we give C::f the right vtable index. (PR9660).
1689struct A {
1690 virtual A* f() = 0;
1691};
1692
1693struct B : virtual A {
1694 virtual B* f();
1695};
1696
1697// CHECK-43: VTable indices for 'Test37::C' (1 entries).
1698// CHECK-43-NEXT: 1 | Test37::C *Test37::C::f()
1699struct C : B {
1700 virtual C* f();
1701};
1702
1703C* C::f() { return 0; }
1704
1705}
John McCall260a3e42012-03-21 06:57:19 +00001706
1707// rdar://problem/10959710
1708namespace Test38 {
1709 struct A {
1710 virtual void *foo();
1711 virtual const void *foo() const;
1712 };
1713
1714 // CHECK-44: Vtable for 'Test38::B' (7 entries).
1715 // CHECK-44-NEXT: 0 | vbase_offset (0)
1716 // CHECK-44-NEXT: 1 | vcall_offset (0)
1717 // CHECK-44-NEXT: 2 | vcall_offset (0)
1718 // CHECK-44-NEXT: 3 | offset_to_top (0)
1719 // CHECK-44-NEXT: 4 | Test38::B RTTI
1720 // CHECK-44-NEXT: -- (Test38::A, 0) vtable address --
1721 // CHECK-44-NEXT: -- (Test38::B, 0) vtable address --
1722 // CHECK-44-NEXT: 5 | void *Test38::B::foo()
1723 // CHECK-44-NEXT: 6 | const void *Test38::B::foo() const
1724 class B : virtual public A {
1725 void *foo();
1726 const void *foo() const;
1727 };
1728
1729 void *B::foo() { return 0; }
1730}
David Blaikied954ab42012-10-16 20:25:33 +00001731
1732namespace Test39 {
1733 struct A {
1734 virtual void foo() = delete;
1735 };
1736
1737 // CHECK-45: Vtable for 'Test39::B' (4 entries).
1738 // CHECK-45-NEXT: 0 | offset_to_top (0)
1739 // CHECK-45-NEXT: 1 | Test39::B RTTI
1740 // CHECK-45-NEXT: -- (Test39::A, 0) vtable address --
1741 // CHECK-45-NEXT: -- (Test39::B, 0) vtable address --
1742 // CHECK-45-NEXT: 2 | void Test39::A::foo() [deleted]
1743 // CHECK-45-NEXT: 3 | void Test39::B::foo2()
1744 struct B: A {
1745 virtual void foo2();
1746 };
1747
1748 void B::foo2() {
1749 }
1750}