1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm-only -fdump-vtable-layouts > %t
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
44 // RUN: FileCheck --check-prefix=CHECK-43 %s < %t
45 // RUN: FileCheck --check-prefix=CHECK-44 %s < %t
46 // RUN: FileCheck --check-prefix=CHECK-45 %s < %t
47 // RUN: FileCheck --check-prefix=CHECK-46 %s < %t
48 
49 // For now, just verify this doesn't crash.
50 namespace test0 {
51   struct Obj {};
52 
53   struct Base {           virtual const Obj *foo() = 0; };
footest0::Derived54   struct Derived : Base { virtual       Obj *foo() { return new Obj(); } };
55 
test(Derived * D)56   void test(Derived *D) { D->foo(); }
57 }
58 
59 namespace Test1 {
60 // CHECK-1:      Vtable for 'Test1::A' (3 entries).
61 // CHECK-1-NEXT:   0 | offset_to_top (0)
62 // CHECK-1-NEXT:   1 | Test1::A RTTI
63 // CHECK-1-NEXT:       -- (Test1::A, 0) vtable address --
64 // CHECK-1-NEXT:   2 | void Test1::A::f()
65 //
66 // CHECK-1:      VTable indices for 'Test1::A' (1 entries).
67 // CHECK-1-NEXT:   0 | void Test1::A::f()
68 struct A {
69   virtual void f();
70 };
f()71 void A::f() { }
72 
73 }
74 
75 namespace Test2 {
76 
77 // This is a smoke test of the vtable dumper.
78 // CHECK-2:      Vtable for 'Test2::A' (9 entries).
79 // CHECK-2-NEXT:   0 | offset_to_top (0)
80 // CHECK-2-NEXT:   1 | Test2::A RTTI
81 // CHECK-2-NEXT:       -- (Test2::A, 0) vtable address --
82 // CHECK-2-NEXT:   2 | void Test2::A::f()
83 // CHECK-2-NEXT:   3 | void Test2::A::f() const
84 // CHECK-2-NEXT:   4 | Test2::A *Test2::A::g(int)
85 // CHECK-2-NEXT:   5 | Test2::A::~A() [complete]
86 // CHECK-2-NEXT:   6 | Test2::A::~A() [deleting]
87 // CHECK-2-NEXT:   7 | void Test2::A::h()
88 // CHECK-2-NEXT:   8 | Test2::A &Test2::A::operator=(const Test2::A &)
89 //
90 // CHECK-2:      VTable indices for 'Test2::A' (7 entries).
91 // CHECK-2-NEXT:   0 | void Test2::A::f()
92 // CHECK-2-NEXT:   1 | void Test2::A::f() const
93 // CHECK-2-NEXT:   2 | Test2::A *Test2::A::g(int)
94 // CHECK-2-NEXT:   3 | Test2::A::~A() [complete]
95 // CHECK-2-NEXT:   4 | Test2::A::~A() [deleting]
96 // CHECK-2-NEXT:   5 | void Test2::A::h()
97 // CHECK-2-NEXT:   6 | Test2::A &Test2::A::operator=(const Test2::A &)
98 struct A {
99   virtual void f();
100   virtual void f() const;
101 
102   virtual A* g(int a);
103   virtual ~A();
104   virtual void h();
105   virtual A& operator=(const A&);
106 };
f()107 void A::f() { }
108 
109 // Another simple vtable dumper test.
110 
111 // CHECK-3:     Vtable for 'Test2::B' (6 entries).
112 // CHECK-3-NEXT:  0 | offset_to_top (0)
113 // CHECK-3-NEXT:  1 | Test2::B RTTI
114 // CHECK-3-NEXT:    -- (Test2::B, 0) vtable address --
115 // CHECK-3-NEXT:  2 | void Test2::B::f()
116 // CHECK-3-NEXT:  3 | void Test2::B::g() [pure]
117 // CHECK-3-NEXT:  4 | Test2::B::~B() [complete] [pure]
118 // CHECK-3-NEXT:  5 | Test2::B::~B() [deleting] [pure]
119 //
120 // CHECK-3:     VTable indices for 'Test2::B' (4 entries).
121 // CHECK-3-NEXT:  0 | void Test2::B::f()
122 // CHECK-3-NEXT:  1 | void Test2::B::g()
123 // CHECK-3-NEXT:  2 | Test2::B::~B() [complete]
124 // CHECK-3-NEXT:  3 | Test2::B::~B() [deleting]
125 struct B {
126   virtual void f();
127   virtual void g() = 0;
128   virtual ~B() = 0;
129 };
f()130 void B::f() { }
131 
132 }
133 
134 namespace Test3 {
135 
136 // If a function in a derived class overrides a function in a primary base,
137 // then the function should not have an entry in the derived class (unless the return
138 // value requires adjusting).
139 
140 // CHECK-4:      Vtable for 'Test3::A' (3 entries).
141 // CHECK-4-NEXT:   0 | offset_to_top (0)
142 // CHECK-4-NEXT:   1 | Test3::A RTTI
143 // CHECK-4-NEXT:       -- (Test3::A, 0) vtable address --
144 // CHECK-4-NEXT:   2 | void Test3::A::f()
145 //
146 // CHECK-4:      VTable indices for 'Test3::A' (1 entries).
147 // CHECK-4-NEXT:   0 | void Test3::A::f()
148 struct A {
149   virtual void f();
150 };
f()151 void A::f() { }
152 
153 // CHECK-5:     Vtable for 'Test3::B' (4 entries).
154 // CHECK-5-NEXT:  0 | offset_to_top (0)
155 // CHECK-5-NEXT:  1 | Test3::B RTTI
156 // CHECK-5-NEXT:      -- (Test3::A, 0) vtable address --
157 // CHECK-5-NEXT:      -- (Test3::B, 0) vtable address --
158 // CHECK-5-NEXT:  2 | void Test3::B::f()
159 // CHECK-5-NEXT:  3 | void Test3::B::g()
160 //
161 // CHECK-5:     VTable indices for 'Test3::B' (2 entries).
162 // CHECK-5-NEXT:  0 | void Test3::B::f()
163 // CHECK-5-NEXT:  1 | void Test3::B::g()
164 struct B : A {
165   virtual void f();
166   virtual void g();
167 };
f()168 void B::f() { }
169 
170 // CHECK-6:     Vtable for 'Test3::C' (5 entries).
171 // CHECK-6-NEXT:  0 | offset_to_top (0)
172 // CHECK-6-NEXT:  1 | Test3::C RTTI
173 // CHECK-6-NEXT:     -- (Test3::A, 0) vtable address --
174 // CHECK-6-NEXT:     -- (Test3::C, 0) vtable address --
175 // CHECK-6-NEXT:  2 | void Test3::A::f()
176 // CHECK-6-NEXT:  3 | void Test3::C::g()
177 // CHECK-6-NEXT:  4 | void Test3::C::h()
178 //
179 // CHECK-6:     VTable indices for 'Test3::C' (2 entries).
180 // CHECK-6-NEXT:  1 | void Test3::C::g()
181 // CHECK-6-NEXT:  2 | void Test3::C::h()
182 struct C : A {
183   virtual void g();
184   virtual void h();
185 };
g()186 void C::g() { }
187 
188 // CHECK-7:     Vtable for 'Test3::D' (5 entries).
189 // CHECK-7-NEXT:  0 | offset_to_top (0)
190 // CHECK-7-NEXT:  1 | Test3::D RTTI
191 // CHECK-7-NEXT:     -- (Test3::A, 0) vtable address --
192 // CHECK-7-NEXT:     -- (Test3::B, 0) vtable address --
193 // CHECK-7-NEXT:     -- (Test3::D, 0) vtable address --
194 // CHECK-7-NEXT:  2 | void Test3::D::f()
195 // CHECK-7-NEXT:  3 | void Test3::D::g()
196 // CHECK-7-NEXT:  4 | void Test3::D::h()
197 //
198 // CHECK-7:     VTable indices for 'Test3::D' (3 entries).
199 // CHECK-7-NEXT:  0 | void Test3::D::f()
200 // CHECK-7-NEXT:  1 | void Test3::D::g()
201 // CHECK-7-NEXT:  2 | void Test3::D::h()
202 struct D : B {
203   virtual void f();
204   virtual void g();
205   virtual void h();
206 };
207 
f()208 void D::f() { }
209 }
210 
211 namespace Test4 {
212 
213 // Test non-virtual result adjustments.
214 
215 struct R1 { int r1; };
216 struct R2 { int r2; };
217 struct R3 : R1, R2 { int r3; };
218 
219 struct A {
220   virtual R2 *f();
221 };
222 
223 // CHECK-8:     Vtable for 'Test4::B' (4 entries).
224 // CHECK-8-NEXT:  0 | offset_to_top (0)
225 // CHECK-8-NEXT:  1 | Test4::B RTTI
226 // CHECK-8-NEXT:      -- (Test4::A, 0) vtable address --
227 // CHECK-8-NEXT:      -- (Test4::B, 0) vtable address --
228 // CHECK-8-NEXT:  2 | Test4::R3 *Test4::B::f()
229 // CHECK-8-NEXT:      [return adjustment: 4 non-virtual]
230 // CHECK-8-NEXT:  3 | Test4::R3 *Test4::B::f()
231 //
232 // CHECK-8:     VTable indices for 'Test4::B' (1 entries).
233 // CHECK-8-NEXT:  1 | Test4::R3 *Test4::B::f()
234 struct B : A {
235   virtual R3 *f();
236 };
f()237 R3 *B::f() { return 0; }
238 
239 // Test virtual result adjustments.
240 struct V1 { int v1; };
241 struct V2 : virtual V1 { int v1; };
242 
243 struct C {
244   virtual V1 *f();
245 };
246 
247 // CHECK-9:     Vtable for 'Test4::D' (4 entries).
248 // CHECK-9-NEXT:   0 | offset_to_top (0)
249 // CHECK-9-NEXT:   1 | Test4::D RTTI
250 // CHECK-9-NEXT:       -- (Test4::C, 0) vtable address --
251 // CHECK-9-NEXT:       -- (Test4::D, 0) vtable address --
252 // CHECK-9-NEXT:   2 | Test4::V2 *Test4::D::f()
253 // CHECK-9-NEXT:       [return adjustment: 0 non-virtual, -24 vbase offset offset]
254 // CHECK-9-NEXT:   3 | Test4::V2 *Test4::D::f()
255 //
256 // CHECK-9:     VTable indices for 'Test4::D' (1 entries).
257 // CHECK-9-NEXT:   1 | Test4::V2 *Test4::D::f()
258 struct D : C {
259   virtual V2 *f();
260 };
f()261 V2 *D::f() { return 0; };
262 
263 // Virtual result adjustments with an additional non-virtual adjustment.
264 struct V3 : virtual R3 { int r3; };
265 
266 // CHECK-10:     Vtable for 'Test4::E' (4 entries).
267 // CHECK-10-NEXT:   0 | offset_to_top (0)
268 // CHECK-10-NEXT:   1 | Test4::E RTTI
269 // CHECK-10-NEXT:       -- (Test4::A, 0) vtable address --
270 // CHECK-10-NEXT:       -- (Test4::E, 0) vtable address --
271 // CHECK-10-NEXT:   2 | Test4::V3 *Test4::E::f()
272 // CHECK-10-NEXT:       [return adjustment: 4 non-virtual, -24 vbase offset offset]
273 // CHECK-10-NEXT:   3 | Test4::V3 *Test4::E::f()
274 //
275 // CHECK-10:     VTable indices for 'Test4::E' (1 entries).
276 // CHECK-10-NEXT:   1 | Test4::V3 *Test4::E::f()
277 struct E : A {
278   virtual V3 *f();
279 };
f()280 V3 *E::f() { return 0;}
281 
282 // Test that a pure virtual member doesn't get a thunk.
283 
284 // CHECK-11:     Vtable for 'Test4::F' (5 entries).
285 // CHECK-11-NEXT:   0 | offset_to_top (0)
286 // CHECK-11-NEXT:   1 | Test4::F RTTI
287 // CHECK-11-NEXT:       -- (Test4::A, 0) vtable address --
288 // CHECK-11-NEXT:       -- (Test4::F, 0) vtable address --
289 // CHECK-11-NEXT:   2 | Test4::R3 *Test4::F::f() [pure]
290 // CHECK-11-NEXT:   3 | void Test4::F::g()
291 // CHECK-11-NEXT:   4 | Test4::R3 *Test4::F::f() [pure]
292 //
293 // CHECK-11:     VTable indices for 'Test4::F' (2 entries).
294 // CHECK-11-NEXT:   1 | void Test4::F::g()
295 // CHECK-11-NEXT:   2 | Test4::R3 *Test4::F::f()
296 struct F : A {
297   virtual void g();
298   virtual R3 *f() = 0;
299 };
g()300 void F::g() { }
301 
302 }
303 
304 namespace Test5 {
305 
306 // Simple secondary vtables without 'this' pointer adjustments.
307 struct A {
308   virtual void f();
309   virtual void g();
310   int a;
311 };
312 
313 struct B1 : A {
314   virtual void f();
315   int b1;
316 };
317 
318 struct B2 : A {
319   virtual void g();
320   int b2;
321 };
322 
323 // CHECK-12:     Vtable for 'Test5::C' (9 entries).
324 // CHECK-12-NEXT:   0 | offset_to_top (0)
325 // CHECK-12-NEXT:   1 | Test5::C RTTI
326 // CHECK-12-NEXT:       -- (Test5::A, 0) vtable address --
327 // CHECK-12-NEXT:       -- (Test5::B1, 0) vtable address --
328 // CHECK-12-NEXT:       -- (Test5::C, 0) vtable address --
329 // CHECK-12-NEXT:   2 | void Test5::B1::f()
330 // CHECK-12-NEXT:   3 | void Test5::A::g()
331 // CHECK-12-NEXT:   4 | void Test5::C::h()
332 // CHECK-12-NEXT:   5 | offset_to_top (-16)
333 // CHECK-12-NEXT:   6 | Test5::C RTTI
334 // CHECK-12-NEXT:       -- (Test5::A, 16) vtable address --
335 // CHECK-12-NEXT:       -- (Test5::B2, 16) vtable address --
336 // CHECK-12-NEXT:   7 | void Test5::A::f()
337 // CHECK-12-NEXT:   8 | void Test5::B2::g()
338 //
339 // CHECK-12:     VTable indices for 'Test5::C' (1 entries).
340 // CHECK-12-NEXT:   2 | void Test5::C::h()
341 struct C : B1, B2 {
342   virtual void h();
343 };
h()344 void C::h() { }
345 }
346 
347 namespace Test6 {
348 
349 // Simple non-virtual 'this' pointer adjustments.
350 struct A1 {
351   virtual void f();
352   int a;
353 };
354 
355 struct A2 {
356   virtual void f();
357   int a;
358 };
359 
360 // CHECK-13:     Vtable for 'Test6::C' (6 entries).
361 // CHECK-13-NEXT:   0 | offset_to_top (0)
362 // CHECK-13-NEXT:   1 | Test6::C RTTI
363 // CHECK-13-NEXT:       -- (Test6::A1, 0) vtable address --
364 // CHECK-13-NEXT:       -- (Test6::C, 0) vtable address --
365 // CHECK-13-NEXT:   2 | void Test6::C::f()
366 // CHECK-13-NEXT:   3 | offset_to_top (-16)
367 // CHECK-13-NEXT:   4 | Test6::C RTTI
368 // CHECK-13-NEXT:       -- (Test6::A2, 16) vtable address --
369 // CHECK-13-NEXT:   5 | void Test6::C::f()
370 // CHECK-13-NEXT:       [this adjustment: -16 non-virtual]
371 //
372 // CHECK-13:     VTable indices for 'Test6::C' (1 entries).
373 // CHECK-13-NEXT:   0 | void Test6::C::f()
374 struct C : A1, A2 {
375   virtual void f();
376 };
f()377 void C::f() { }
378 
379 }
380 
381 namespace Test7 {
382 
383 // Test that the D::f overrider for A::f have different 'this' pointer
384 // adjustments in the two A base subobjects.
385 
386 struct A {
387   virtual void f();
388   int a;
389 };
390 
391 struct B1 : A { };
392 struct B2 : A { };
393 
394 struct C { virtual void c(); };
395 
396 // CHECK-14:     Vtable for 'Test7::D' (10 entries).
397 // CHECK-14-NEXT:   0 | offset_to_top (0)
398 // CHECK-14-NEXT:   1 | Test7::D RTTI
399 // CHECK-14-NEXT:       -- (Test7::C, 0) vtable address --
400 // CHECK-14-NEXT:       -- (Test7::D, 0) vtable address --
401 // CHECK-14-NEXT:   2 | void Test7::C::c()
402 // CHECK-14-NEXT:   3 | void Test7::D::f()
403 // CHECK-14-NEXT:   4 | offset_to_top (-8)
404 // CHECK-14-NEXT:   5 | Test7::D RTTI
405 // CHECK-14-NEXT:       -- (Test7::A, 8) vtable address --
406 // CHECK-14-NEXT:       -- (Test7::B1, 8) vtable address --
407 // CHECK-14-NEXT:   6 | void Test7::D::f()
408 // CHECK-14-NEXT:       [this adjustment: -8 non-virtual]
409 // CHECK-14-NEXT:   7 | offset_to_top (-24)
410 // CHECK-14-NEXT:   8 | Test7::D RTTI
411 // CHECK-14-NEXT:       -- (Test7::A, 24) vtable address --
412 // CHECK-14-NEXT:       -- (Test7::B2, 24) vtable address --
413 // CHECK-14-NEXT:   9 | void Test7::D::f()
414 // CHECK-14-NEXT:       [this adjustment: -24 non-virtual]
415 //
416 // CHECK-14:     VTable indices for 'Test7::D' (1 entries).
417 // CHECK-14-NEXT:   1 | void Test7::D::f()
418 struct D : C, B1, B2 {
419   virtual void f();
420 };
f()421 void D::f() { }
422 
423 }
424 
425 namespace Test8 {
426 
427 // Test that we don't try to layout vtables for classes that don't have
428 // virtual bases or virtual member functions.
429 
430 struct A { };
431 
432 // CHECK-15:     Vtable for 'Test8::B' (3 entries).
433 // CHECK-15-NEXT:   0 | offset_to_top (0)
434 // CHECK-15-NEXT:   1 | Test8::B RTTI
435 // CHECK-15-NEXT:       -- (Test8::B, 0) vtable address --
436 // CHECK-15-NEXT:   2 | void Test8::B::f()
437 //
438 // CHECK-15:     VTable indices for 'Test8::B' (1 entries).
439 // CHECK-15-NEXT:   0 | void Test8::B::f()
440 struct B : A {
441   virtual void f();
442 };
f()443 void B::f() { }
444 
445 }
446 
447 namespace Test9 {
448 
449 // Simple test of vbase offsets.
450 
451 struct A1 { int a1; };
452 struct A2 { int a2; };
453 
454 // CHECK-16:     Vtable for 'Test9::B' (5 entries).
455 // CHECK-16-NEXT:   0 | vbase_offset (16)
456 // CHECK-16-NEXT:   1 | vbase_offset (12)
457 // CHECK-16-NEXT:   2 | offset_to_top (0)
458 // CHECK-16-NEXT:   3 | Test9::B RTTI
459 // CHECK-16-NEXT:       -- (Test9::B, 0) vtable address --
460 // CHECK-16-NEXT:   4 | void Test9::B::f()
461 //
462 // CHECK-16:     VTable indices for 'Test9::B' (1 entries).
463 // CHECK-16-NEXT:   0 | void Test9::B::f()
464 struct B : virtual A1, virtual A2 {
465   int b;
466 
467   virtual void f();
468 };
469 
470 
f()471 void B::f() { }
472 
473 }
474 
475 namespace Test10 {
476 
477 // Test for a bug where we would not emit secondary vtables for bases
478 // of a primary base.
479 struct A1 { virtual void a1(); };
480 struct A2 { virtual void a2(); };
481 
482 // CHECK-17:     Vtable for 'Test10::C' (7 entries).
483 // CHECK-17-NEXT:   0 | offset_to_top (0)
484 // CHECK-17-NEXT:   1 | Test10::C RTTI
485 // CHECK-17-NEXT:       -- (Test10::A1, 0) vtable address --
486 // CHECK-17-NEXT:       -- (Test10::B, 0) vtable address --
487 // CHECK-17-NEXT:       -- (Test10::C, 0) vtable address --
488 // CHECK-17-NEXT:   2 | void Test10::A1::a1()
489 // CHECK-17-NEXT:   3 | void Test10::C::f()
490 // CHECK-17-NEXT:   4 | offset_to_top (-8)
491 // CHECK-17-NEXT:   5 | Test10::C RTTI
492 // CHECK-17-NEXT:       -- (Test10::A2, 8) vtable address --
493 // CHECK-17-NEXT:   6 | void Test10::A2::a2()
494 //
495 // CHECK-17:     VTable indices for 'Test10::C' (1 entries).
496 // CHECK-17-NEXT:   1 | void Test10::C::f()
497 struct B : A1, A2 {
498   int b;
499 };
500 
501 struct C : B {
502   virtual void f();
503 };
f()504 void C::f() { }
505 
506 }
507 
508 namespace Test11 {
509 
510 // Very simple test of vtables for virtual bases.
511 struct A1 { int a; };
512 struct A2 { int b; };
513 
514 struct B : A1, virtual A2 {
515   int b;
516 };
517 
518 // CHECK-18:     Vtable for 'Test11::C' (8 entries).
519 // CHECK-18-NEXT:   0 | vbase_offset (24)
520 // CHECK-18-NEXT:   1 | vbase_offset (8)
521 // CHECK-18-NEXT:   2 | offset_to_top (0)
522 // CHECK-18-NEXT:   3 | Test11::C RTTI
523 // CHECK-18-NEXT:       -- (Test11::C, 0) vtable address --
524 // CHECK-18-NEXT:   4 | void Test11::C::f()
525 // CHECK-18-NEXT:   5 | vbase_offset (16)
526 // CHECK-18-NEXT:   6 | offset_to_top (-8)
527 // CHECK-18-NEXT:   7 | Test11::C RTTI
528 //
529 // CHECK-18:     VTable indices for 'Test11::C' (1 entries).
530 // CHECK-18-NEXT:   0 | void Test11::C::f()
531 struct C : virtual B {
532   virtual void f();
533 };
f()534 void C::f() { }
535 
536 }
537 
538 namespace Test12 {
539 
540 // Test that the right vcall offsets are generated in the right order.
541 
542 // CHECK-19:      Vtable for 'Test12::B' (19 entries).
543 // CHECK-19-NEXT:    0 | vbase_offset (8)
544 // CHECK-19-NEXT:    1 | offset_to_top (0)
545 // CHECK-19-NEXT:    2 | Test12::B RTTI
546 // CHECK-19-NEXT:        -- (Test12::B, 0) vtable address --
547 // CHECK-19-NEXT:    3 | void Test12::B::f()
548 // CHECK-19-NEXT:    4 | void Test12::B::a()
549 // CHECK-19-NEXT:    5 | vcall_offset (32)
550 // CHECK-19-NEXT:    6 | vcall_offset (16)
551 // CHECK-19-NEXT:    7 | vcall_offset (-8)
552 // CHECK-19-NEXT:    8 | vcall_offset (0)
553 // CHECK-19-NEXT:    9 | offset_to_top (-8)
554 // CHECK-19-NEXT:   10 | Test12::B RTTI
555 // CHECK-19-NEXT:        -- (Test12::A, 8) vtable address --
556 // CHECK-19-NEXT:        -- (Test12::A1, 8) vtable address --
557 // CHECK-19-NEXT:   11 | void Test12::A1::a1()
558 // CHECK-19-NEXT:   12 | void Test12::B::a()
559 // CHECK-19-NEXT:        [this adjustment: 0 non-virtual, -32 vcall offset offset]
560 // CHECK-19-NEXT:   13 | offset_to_top (-24)
561 // CHECK-19-NEXT:   14 | Test12::B RTTI
562 // CHECK-19-NEXT:        -- (Test12::A2, 24) vtable address --
563 // CHECK-19-NEXT:   15 | void Test12::A2::a2()
564 // CHECK-19-NEXT:   16 | offset_to_top (-40)
565 // CHECK-19-NEXT:   17 | Test12::B RTTI
566 // CHECK-19-NEXT:        -- (Test12::A3, 40) vtable address --
567 // CHECK-19-NEXT:   18 | void Test12::A3::a3()
568 //
569 // CHECK-19:      VTable indices for 'Test12::B' (2 entries).
570 // CHECK-19-NEXT:    0 | void Test12::B::f()
571 // CHECK-19-NEXT:    1 | void Test12::B::a()
572 struct A1 {
573   virtual void a1();
574   int a;
575 };
576 
577 struct A2 {
578   virtual void a2();
579   int a;
580 };
581 
582 struct A3 {
583   virtual void a3();
584   int a;
585 };
586 
587 struct A : A1, A2, A3 {
588   virtual void a();
589   int i;
590 };
591 
592 struct B : virtual A {
593   virtual void f();
594 
595   virtual void a();
596 };
f()597 void B::f() { }
598 
599 }
600 
601 namespace Test13 {
602 
603 // Test that we don't try to emit a vtable for 'A' twice.
604 struct A {
605   virtual void f();
606 };
607 
608 struct B : virtual A {
609   virtual void f();
610 };
611 
612 // CHECK-20:      Vtable for 'Test13::C' (6 entries).
613 // CHECK-20-NEXT:    0 | vbase_offset (0)
614 // CHECK-20-NEXT:    1 | vbase_offset (0)
615 // CHECK-20-NEXT:    2 | vcall_offset (0)
616 // CHECK-20-NEXT:    3 | offset_to_top (0)
617 // CHECK-20-NEXT:    4 | Test13::C RTTI
618 // CHECK-20-NEXT:        -- (Test13::A, 0) vtable address --
619 // CHECK-20-NEXT:        -- (Test13::B, 0) vtable address --
620 // CHECK-20-NEXT:        -- (Test13::C, 0) vtable address --
621 // CHECK-20-NEXT:    5 | void Test13::C::f()
622 //
623 // CHECK-20:      VTable indices for 'Test13::C' (1 entries).
624 // CHECK-20-NEXT:    0 | void Test13::C::f()
625 struct C : virtual B, virtual A {
626   virtual void f();
627 };
f()628 void C::f() { }
629 
630 }
631 
632 namespace Test14 {
633 
634 // Verify that we handle A being a non-virtual base of B, which is a virtual base.
635 
636 struct A {
637   virtual void f();
638 };
639 
640 struct B : A { };
641 
642 struct C : virtual B { };
643 
644 // CHECK-21:      Vtable for 'Test14::D' (5 entries).
645 // CHECK-21-NEXT:    0 | vbase_offset (0)
646 // CHECK-21-NEXT:    1 | vcall_offset (0)
647 // CHECK-21-NEXT:    2 | offset_to_top (0)
648 // CHECK-21-NEXT:    3 | Test14::D RTTI
649 // CHECK-21-NEXT:        -- (Test14::A, 0) vtable address --
650 // CHECK-21-NEXT:        -- (Test14::B, 0) vtable address --
651 // CHECK-21-NEXT:        -- (Test14::C, 0) vtable address --
652 // CHECK-21-NEXT:        -- (Test14::D, 0) vtable address --
653 // CHECK-21-NEXT:    4 | void Test14::D::f()
654 //
655 // CHECK-21:      VTable indices for 'Test14::D' (1 entries).
656 // CHECK-21-NEXT:    0 | void Test14::D::f()
657 struct D : C, virtual B {
658  virtual void f();
659 };
f()660 void D::f() { }
661 
662 }
663 
664 namespace Test15 {
665 
666 // Test that we don't emit an extra vtable for B since it's a primary base of C.
667 struct A { virtual void a(); };
668 struct B { virtual void b(); };
669 
670 struct C : virtual B { };
671 
672 // CHECK-22:      Vtable for 'Test15::D' (11 entries).
673 // CHECK-22-NEXT:    0 | vbase_offset (8)
674 // CHECK-22-NEXT:    1 | vbase_offset (8)
675 // CHECK-22-NEXT:    2 | offset_to_top (0)
676 // CHECK-22-NEXT:    3 | Test15::D RTTI
677 // CHECK-22-NEXT:        -- (Test15::A, 0) vtable address --
678 // CHECK-22-NEXT:        -- (Test15::D, 0) vtable address --
679 // CHECK-22-NEXT:    4 | void Test15::A::a()
680 // CHECK-22-NEXT:    5 | void Test15::D::f()
681 // CHECK-22-NEXT:    6 | vbase_offset (0)
682 // CHECK-22-NEXT:    7 | vcall_offset (0)
683 // CHECK-22-NEXT:    8 | offset_to_top (-8)
684 // CHECK-22-NEXT:    9 | Test15::D RTTI
685 // CHECK-22-NEXT:        -- (Test15::B, 8) vtable address --
686 // CHECK-22-NEXT:        -- (Test15::C, 8) vtable address --
687 // CHECK-22-NEXT:   10 | void Test15::B::b()
688 //
689 // CHECK-22:      VTable indices for 'Test15::D' (1 entries).
690 // CHECK-22-NEXT:    1 | void Test15::D::f()
691 struct D : A, virtual B, virtual C {
692   virtual void f();
693 };
f()694 void D::f() { }
695 
696 }
697 
698 namespace Test16 {
699 
700 // Test that destructors share vcall offsets.
701 
702 struct A { virtual ~A(); };
703 struct B { virtual ~B(); };
704 
705 struct C : A, B { virtual ~C(); };
706 
707 // CHECK-23:      Vtable for 'Test16::D' (15 entries).
708 // CHECK-23-NEXT:    0 | vbase_offset (8)
709 // CHECK-23-NEXT:    1 | offset_to_top (0)
710 // CHECK-23-NEXT:    2 | Test16::D RTTI
711 // CHECK-23-NEXT:        -- (Test16::D, 0) vtable address --
712 // CHECK-23-NEXT:    3 | void Test16::D::f()
713 // CHECK-23-NEXT:    4 | Test16::D::~D() [complete]
714 // CHECK-23-NEXT:    5 | Test16::D::~D() [deleting]
715 // CHECK-23-NEXT:    6 | vcall_offset (-8)
716 // CHECK-23-NEXT:    7 | offset_to_top (-8)
717 // CHECK-23-NEXT:    8 | Test16::D RTTI
718 // CHECK-23-NEXT:        -- (Test16::A, 8) vtable address --
719 // CHECK-23-NEXT:        -- (Test16::C, 8) vtable address --
720 // CHECK-23-NEXT:    9 | Test16::D::~D() [complete]
721 // CHECK-23-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
722 // CHECK-23-NEXT:   10 | Test16::D::~D() [deleting]
723 // CHECK-23-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
724 // CHECK-23-NEXT:   11 | offset_to_top (-16)
725 // CHECK-23-NEXT:   12 | Test16::D RTTI
726 // CHECK-23-NEXT:        -- (Test16::B, 16) vtable address --
727 // CHECK-23-NEXT:   13 | Test16::D::~D() [complete]
728 // CHECK-23-NEXT:        [this adjustment: -8 non-virtual, -24 vcall offset offset]
729 // CHECK-23-NEXT:   14 | Test16::D::~D() [deleting]
730 // CHECK-23-NEXT:        [this adjustment: -8 non-virtual, -24 vcall offset offset]
731 //
732 // CHECK-23:      VTable indices for 'Test16::D' (3 entries).
733 // CHECK-23-NEXT:    0 | void Test16::D::f()
734 // CHECK-23-NEXT:    1 | Test16::D::~D() [complete]
735 // CHECK-23-NEXT:    2 | Test16::D::~D() [deleting]
736 struct D : virtual C {
737   virtual void f();
738 };
f()739 void D::f() { }
740 
741 }
742 
743 namespace Test17 {
744 
745 // Test that we don't mark E::f in the C-in-E vtable as unused.
746 struct A { virtual void f(); };
747 struct B : virtual A { virtual void f(); };
748 struct C : virtual A { virtual void f(); };
749 struct D : virtual B, virtual C { virtual void f(); };
750 
751 // CHECK-24:      Vtable for 'Test17::E' (13 entries).
752 // CHECK-24-NEXT:    0 | vbase_offset (0)
753 // CHECK-24-NEXT:    1 | vbase_offset (8)
754 // CHECK-24-NEXT:    2 | vbase_offset (0)
755 // CHECK-24-NEXT:    3 | vbase_offset (0)
756 // CHECK-24-NEXT:    4 | vcall_offset (0)
757 // CHECK-24-NEXT:    5 | offset_to_top (0)
758 // CHECK-24-NEXT:    6 | Test17::E RTTI
759 // CHECK-24-NEXT:        -- (Test17::A, 0) vtable address --
760 // CHECK-24-NEXT:        -- (Test17::B, 0) vtable address --
761 // CHECK-24-NEXT:        -- (Test17::D, 0) vtable address --
762 // CHECK-24-NEXT:        -- (Test17::E, 0) vtable address --
763 // CHECK-24-NEXT:    7 | void Test17::E::f()
764 // CHECK-24-NEXT:    8 | vbase_offset (-8)
765 // CHECK-24-NEXT:    9 | vcall_offset (-8)
766 // CHECK-24-NEXT:   10 | offset_to_top (-8)
767 // CHECK-24-NEXT:   11 | Test17::E RTTI
768 // CHECK-24-NEXT:        -- (Test17::C, 8) vtable address --
769 // CHECK-24-NEXT:   12 | void Test17::E::f()
770 // CHECK-24-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
771 //
772 // CHECK-24:      VTable indices for 'Test17::E' (1 entries).
773 // CHECK-24-NEXT:    0 | void Test17::E::f()
774 class E : virtual D {
775   virtual void f();
776 };
f()777 void E::f() {}
778 
779 }
780 
781 namespace Test18 {
782 
783 // Test that we compute the right 'this' adjustment offsets.
784 
785 struct A {
786   virtual void f();
787   virtual void g();
788 };
789 
790 struct B : virtual A {
791   virtual void f();
792 };
793 
794 struct C : A, B {
795   virtual void g();
796 };
797 
798 // CHECK-25:      Vtable for 'Test18::D' (24 entries).
799 // CHECK-25-NEXT:    0 | vbase_offset (8)
800 // CHECK-25-NEXT:    1 | vbase_offset (0)
801 // CHECK-25-NEXT:    2 | vbase_offset (0)
802 // CHECK-25-NEXT:    3 | vcall_offset (8)
803 // CHECK-25-NEXT:    4 | vcall_offset (0)
804 // CHECK-25-NEXT:    5 | offset_to_top (0)
805 // CHECK-25-NEXT:    6 | Test18::D RTTI
806 // CHECK-25-NEXT:        -- (Test18::A, 0) vtable address --
807 // CHECK-25-NEXT:        -- (Test18::B, 0) vtable address --
808 // CHECK-25-NEXT:        -- (Test18::D, 0) vtable address --
809 // CHECK-25-NEXT:    7 | void Test18::D::f()
810 // CHECK-25-NEXT:    8 | void Test18::C::g()
811 // CHECK-25-NEXT:        [this adjustment: 0 non-virtual, -32 vcall offset offset]
812 // CHECK-25-NEXT:    9 | void Test18::D::h()
813 // CHECK-25-NEXT:   10 | vcall_offset (0)
814 // CHECK-25-NEXT:   11 | vcall_offset (-8)
815 // CHECK-25-NEXT:   12 | vbase_offset (-8)
816 // CHECK-25-NEXT:   13 | offset_to_top (-8)
817 // CHECK-25-NEXT:   14 | Test18::D RTTI
818 // CHECK-25-NEXT:        -- (Test18::A, 8) vtable address --
819 // CHECK-25-NEXT:        -- (Test18::C, 8) vtable address --
820 // CHECK-25-NEXT:   15 | void Test18::D::f()
821 // CHECK-25-NEXT:        [this adjustment: 0 non-virtual, -32 vcall offset offset]
822 // CHECK-25-NEXT:   16 | void Test18::C::g()
823 // CHECK-25-NEXT:   17 | vbase_offset (-16)
824 // CHECK-25-NEXT:   18 | vcall_offset (-8)
825 // CHECK-25-NEXT:   19 | vcall_offset (-16)
826 // CHECK-25-NEXT:   20 | offset_to_top (-16)
827 // CHECK-25-NEXT:   21 | Test18::D RTTI
828 // CHECK-25-NEXT:        -- (Test18::B, 16) vtable address --
829 // CHECK-25-NEXT:   22 | void Test18::D::f()
830 // CHECK-25-NEXT:        [this adjustment: -8 non-virtual, -32 vcall offset offset]
831 // CHECK-25-NEXT:   23 | [unused] void Test18::C::g()
832 //
833 // CHECK-25:      VTable indices for 'Test18::D' (2 entries).
834 // CHECK-25-NEXT:    0 | void Test18::D::f()
835 // CHECK-25-NEXT:    2 | void Test18::D::h()
836 
837 // CHECK-25:      Construction vtable for ('Test18::B', 0) in 'Test18::D' (7 entries).
838 // CHECK-25-NEXT:    0 | vbase_offset (0)
839 // CHECK-25-NEXT:    1 | vcall_offset (0)
840 // CHECK-25-NEXT:    2 | vcall_offset (0)
841 // CHECK-25-NEXT:    3 | offset_to_top (0)
842 // CHECK-25-NEXT:    4 | Test18::B RTTI
843 // CHECK-25-NEXT:        -- (Test18::A, 0) vtable address --
844 // CHECK-25-NEXT:        -- (Test18::B, 0) vtable address --
845 // CHECK-25-NEXT:    5 | void Test18::B::f()
846 // CHECK-25-NEXT:    6 | void Test18::A::g()
847 
848 // CHECK-25:      Construction vtable for ('Test18::C', 8) in 'Test18::D' (20 entries).
849 // CHECK-25-NEXT:    0 | vcall_offset (0)
850 // CHECK-25-NEXT:    1 | vcall_offset (0)
851 // CHECK-25-NEXT:    2 | vbase_offset (-8)
852 // CHECK-25-NEXT:    3 | offset_to_top (0)
853 // CHECK-25-NEXT:    4 | Test18::C RTTI
854 // CHECK-25-NEXT:        -- (Test18::A, 8) vtable address --
855 // CHECK-25-NEXT:        -- (Test18::C, 8) vtable address --
856 // CHECK-25-NEXT:    5 | void Test18::A::f()
857 // CHECK-25-NEXT:    6 | void Test18::C::g()
858 // CHECK-25-NEXT:    7 | vbase_offset (-16)
859 // CHECK-25-NEXT:    8 | vcall_offset (-8)
860 // CHECK-25-NEXT:    9 | vcall_offset (0)
861 // CHECK-25-NEXT:   10 | offset_to_top (-8)
862 // CHECK-25-NEXT:   11 | Test18::C RTTI
863 // CHECK-25-NEXT:        -- (Test18::B, 16) vtable address --
864 // CHECK-25-NEXT:   12 | void Test18::B::f()
865 // CHECK-25-NEXT:   13 | [unused] void Test18::C::g()
866 // CHECK-25-NEXT:   14 | vcall_offset (8)
867 // CHECK-25-NEXT:   15 | vcall_offset (16)
868 // CHECK-25-NEXT:   16 | offset_to_top (8)
869 // CHECK-25-NEXT:   17 | Test18::C RTTI
870 // CHECK-25-NEXT:        -- (Test18::A, 0) vtable address --
871 // CHECK-25-NEXT:   18 | void Test18::B::f()
872 // CHECK-25-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
873 // CHECK-25-NEXT:   19 | void Test18::C::g()
874 // CHECK-25-NEXT:        [this adjustment: 0 non-virtual, -32 vcall offset offset]
875 
876 // CHECK-25:      Construction vtable for ('Test18::B', 16) in 'Test18::D' (13 entries).
877 // CHECK-25-NEXT:    0 | vbase_offset (-16)
878 // CHECK-25-NEXT:    1 | vcall_offset (-16)
879 // CHECK-25-NEXT:    2 | vcall_offset (0)
880 // CHECK-25-NEXT:    3 | offset_to_top (0)
881 // CHECK-25-NEXT:    4 | Test18::B RTTI
882 // CHECK-25-NEXT:        -- (Test18::B, 16) vtable address --
883 // CHECK-25-NEXT:    5 | void Test18::B::f()
884 // CHECK-25-NEXT:    6 | [unused] void Test18::A::g()
885 // CHECK-25-NEXT:    7 | vcall_offset (0)
886 // CHECK-25-NEXT:    8 | vcall_offset (16)
887 // CHECK-25-NEXT:    9 | offset_to_top (16)
888 // CHECK-25-NEXT:   10 | Test18::B RTTI
889 // CHECK-25-NEXT:        -- (Test18::A, 0) vtable address --
890 // CHECK-25-NEXT:   11 | void Test18::B::f()
891 // CHECK-25-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
892 // CHECK-25-NEXT:   12 | void Test18::A::g()
893 struct D : virtual B, virtual C, virtual A
894 {
895   virtual void f();
896   virtual void h();
897 };
f()898 void D::f() {}
899 
900 }
901 
902 namespace Test19 {
903 
904 // Another 'this' adjustment test.
905 
906 struct A {
907   int a;
908 
909   virtual void f();
910 };
911 
912 struct B : A {
913   int b;
914 
915   virtual void g();
916 };
917 
918 struct C {
919   virtual void c();
920 };
921 
922 // CHECK-26:      Vtable for 'Test19::D' (13 entries).
923 // CHECK-26-NEXT:    0 | vbase_offset (24)
924 // CHECK-26-NEXT:    1 | offset_to_top (0)
925 // CHECK-26-NEXT:    2 | Test19::D RTTI
926 // CHECK-26-NEXT:        -- (Test19::C, 0) vtable address --
927 // CHECK-26-NEXT:        -- (Test19::D, 0) vtable address --
928 // CHECK-26-NEXT:    3 | void Test19::C::c()
929 // CHECK-26-NEXT:    4 | void Test19::D::f()
930 // CHECK-26-NEXT:    5 | offset_to_top (-8)
931 // CHECK-26-NEXT:    6 | Test19::D RTTI
932 // CHECK-26-NEXT:        -- (Test19::A, 8) vtable address --
933 // CHECK-26-NEXT:        -- (Test19::B, 8) vtable address --
934 // CHECK-26-NEXT:    7 | void Test19::D::f()
935 // CHECK-26-NEXT:        [this adjustment: -8 non-virtual]
936 // CHECK-26-NEXT:    8 | void Test19::B::g()
937 // CHECK-26-NEXT:    9 | vcall_offset (-24)
938 // CHECK-26-NEXT:   10 | offset_to_top (-24)
939 // CHECK-26-NEXT:   11 | Test19::D RTTI
940 // CHECK-26-NEXT:        -- (Test19::A, 24) vtable address --
941 // CHECK-26-NEXT:   12 | void Test19::D::f()
942 // CHECK-26-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
943 //
944 // CHECK-26:      VTable indices for 'Test19::D' (1 entries).
945 // CHECK-26-NEXT:    1 | void Test19::D::f()
946 struct D : C, B, virtual A {
947   virtual void f();
948 };
f()949 void D::f() { }
950 
951 }
952 
953 namespace Test20 {
954 
955 // pure virtual member functions should never have 'this' adjustments.
956 
957 struct A {
958   virtual void f() = 0;
959   virtual void g();
960 };
961 
962 struct B : A { };
963 
964 // CHECK-27:      Vtable for 'Test20::C' (9 entries).
965 // CHECK-27-NEXT:    0 | offset_to_top (0)
966 // CHECK-27-NEXT:    1 | Test20::C RTTI
967 // CHECK-27-NEXT:        -- (Test20::A, 0) vtable address --
968 // CHECK-27-NEXT:        -- (Test20::C, 0) vtable address --
969 // CHECK-27-NEXT:    2 | void Test20::C::f() [pure]
970 // CHECK-27-NEXT:    3 | void Test20::A::g()
971 // CHECK-27-NEXT:    4 | void Test20::C::h()
972 // CHECK-27-NEXT:    5 | offset_to_top (-8)
973 // CHECK-27-NEXT:    6 | Test20::C RTTI
974 // CHECK-27-NEXT:        -- (Test20::A, 8) vtable address --
975 // CHECK-27-NEXT:        -- (Test20::B, 8) vtable address --
976 // CHECK-27-NEXT:    7 | void Test20::C::f() [pure]
977 // CHECK-27-NEXT:    8 | void Test20::A::g()
978 //
979 // CHECK-27:      VTable indices for 'Test20::C' (2 entries).
980 // CHECK-27-NEXT:    0 | void Test20::C::f()
981 // CHECK-27-NEXT:    2 | void Test20::C::h()
982 struct C : A, B {
983   virtual void f() = 0;
984   virtual void h();
985 };
h()986 void C::h() { }
987 
988 }
989 
990 namespace Test21 {
991 
992 // Test that we get vbase offsets right in secondary vtables.
993 struct A {
994   virtual void f();
995 };
996 
997 struct B : virtual A { };
998 class C : virtual B { };
999 class D : virtual C { };
1000 
1001 class E : virtual C { };
1002 
1003 // CHECK-28:      Vtable for 'Test21::F' (16 entries).
1004 // CHECK-28-NEXT:    0 | vbase_offset (8)
1005 // CHECK-28-NEXT:    1 | vbase_offset (0)
1006 // CHECK-28-NEXT:    2 | vbase_offset (0)
1007 // CHECK-28-NEXT:    3 | vbase_offset (0)
1008 // CHECK-28-NEXT:    4 | vbase_offset (0)
1009 // CHECK-28-NEXT:    5 | vcall_offset (0)
1010 // CHECK-28-NEXT:    6 | offset_to_top (0)
1011 // CHECK-28-NEXT:    7 | Test21::F RTTI
1012 // CHECK-28-NEXT:        -- (Test21::A, 0) vtable address --
1013 // CHECK-28-NEXT:        -- (Test21::B, 0) vtable address --
1014 // CHECK-28-NEXT:        -- (Test21::C, 0) vtable address --
1015 // CHECK-28-NEXT:        -- (Test21::D, 0) vtable address --
1016 // CHECK-28-NEXT:        -- (Test21::F, 0) vtable address --
1017 // CHECK-28-NEXT:    8 | void Test21::F::f()
1018 // CHECK-28-NEXT:    9 | vbase_offset (-8)
1019 // CHECK-28-NEXT:   10 | vbase_offset (-8)
1020 // CHECK-28-NEXT:   11 | vbase_offset (-8)
1021 // CHECK-28-NEXT:   12 | vcall_offset (-8)
1022 // CHECK-28-NEXT:   13 | offset_to_top (-8)
1023 // CHECK-28-NEXT:   14 | Test21::F RTTI
1024 // CHECK-28-NEXT:        -- (Test21::E, 8) vtable address --
1025 // CHECK-28-NEXT:   15 | [unused] void Test21::F::f()
1026 //
1027 // CHECK-28:      Virtual base offset offsets for 'Test21::F' (5 entries).
1028 // CHECK-28-NEXT:    Test21::A | -32
1029 // CHECK-28-NEXT:    Test21::B | -40
1030 // CHECK-28-NEXT:    Test21::C | -48
1031 // CHECK-28-NEXT:    Test21::D | -56
1032 // CHECK-28-NEXT:    Test21::E | -64
1033 //
1034 // CHECK-28:      VTable indices for 'Test21::F' (1 entries).
1035 // CHECK-28-NEXT:    0 | void Test21::F::f()
1036 class F : virtual D, virtual E {
1037   virtual void f();
1038 };
f()1039 void F::f() { }
1040 
1041 }
1042 
1043 namespace Test22 {
1044 
1045 // Very simple construction vtable test.
1046 struct V1 {
1047   int v1;
1048 };
1049 
1050 struct V2 : virtual V1 {
1051   int v2;
1052 };
1053 
1054 // CHECK-29:      Vtable for 'Test22::C' (8 entries).
1055 // CHECK-29-NEXT:    0 | vbase_offset (16)
1056 // CHECK-29-NEXT:    1 | vbase_offset (12)
1057 // CHECK-29-NEXT:    2 | offset_to_top (0)
1058 // CHECK-29-NEXT:    3 | Test22::C RTTI
1059 // CHECK-29-NEXT:        -- (Test22::C, 0) vtable address --
1060 // CHECK-29-NEXT:    4 | void Test22::C::f()
1061 // CHECK-29-NEXT:    5 | vbase_offset (-4)
1062 // CHECK-29-NEXT:    6 | offset_to_top (-16)
1063 // CHECK-29-NEXT:    7 | Test22::C RTTI
1064 // CHECK-29-NEXT:        -- (Test22::V2, 16) vtable address --
1065 //
1066 // CHECK-29:      VTable indices for 'Test22::C' (1 entries).
1067 // CHECK-29-NEXT:    0 | void Test22::C::f()
1068 
1069 // CHECK-29:      Construction vtable for ('Test22::V2', 16) in 'Test22::C' (3 entries).
1070 // CHECK-29-NEXT:    0 | vbase_offset (-4)
1071 // CHECK-29-NEXT:    1 | offset_to_top (0)
1072 // CHECK-29-NEXT:    2 | Test22::V2 RTTI
1073 
1074 struct C : virtual V1, virtual V2 {
1075   int c;
1076   virtual void f();
1077 };
f()1078 void C::f() { }
1079 
1080 }
1081 
1082 namespace Test23 {
1083 
1084 struct A {
1085   int a;
1086 };
1087 
1088 struct B : virtual A {
1089   int b;
1090 };
1091 
1092 struct C : A, virtual B {
1093   int c;
1094 };
1095 
1096 // CHECK-30:      Vtable for 'Test23::D' (7 entries).
1097 // CHECK-30-NEXT:    0 | vbase_offset (20)
1098 // CHECK-30-NEXT:    1 | vbase_offset (24)
1099 // CHECK-30-NEXT:    2 | offset_to_top (0)
1100 // CHECK-30-NEXT:    3 | Test23::D RTTI
1101 // CHECK-30-NEXT:        -- (Test23::C, 0) vtable address --
1102 // CHECK-30-NEXT:        -- (Test23::D, 0) vtable address --
1103 // CHECK-30-NEXT:    4 | vbase_offset (-4)
1104 // CHECK-30-NEXT:    5 | offset_to_top (-24)
1105 // CHECK-30-NEXT:    6 | Test23::D RTTI
1106 // CHECK-30-NEXT:        -- (Test23::B, 24) vtable address --
1107 
1108 // CHECK-30:      Construction vtable for ('Test23::C', 0) in 'Test23::D' (7 entries).
1109 // CHECK-30-NEXT:    0 | vbase_offset (20)
1110 // CHECK-30-NEXT:    1 | vbase_offset (24)
1111 // CHECK-30-NEXT:    2 | offset_to_top (0)
1112 // CHECK-30-NEXT:    3 | Test23::C RTTI
1113 // CHECK-30-NEXT:        -- (Test23::C, 0) vtable address --
1114 // CHECK-30-NEXT:    4 | vbase_offset (-4)
1115 // CHECK-30-NEXT:    5 | offset_to_top (-24)
1116 // CHECK-30-NEXT:    6 | Test23::C RTTI
1117 // CHECK-30-NEXT:        -- (Test23::B, 24) vtable address --
1118 
1119 // CHECK-30:      Construction vtable for ('Test23::B', 24) in 'Test23::D' (3 entries).
1120 // CHECK-30-NEXT:    0 | vbase_offset (-4)
1121 // CHECK-30-NEXT:    1 | offset_to_top (0)
1122 // CHECK-30-NEXT:    2 | Test23::B RTTI
1123 // CHECK-30-NEXT:        -- (Test23::B, 24) vtable address --
1124 
1125 struct D : virtual A, virtual B, C {
1126   int d;
1127 
1128   void f();
1129 };
f()1130 void D::f() { }
1131   D d;
1132 }
1133 
1134 namespace Test24 {
1135 
1136 // Another construction vtable test.
1137 
1138 struct A {
1139   virtual void f();
1140 };
1141 
1142 struct B : virtual A { };
1143 struct C : virtual A { };
1144 
1145 // CHECK-31:      Vtable for 'Test24::D' (10 entries).
1146 // CHECK-31-NEXT:    0 | vbase_offset (0)
1147 // CHECK-31-NEXT:    1 | vcall_offset (0)
1148 // CHECK-31-NEXT:    2 | offset_to_top (0)
1149 // CHECK-31-NEXT:    3 | Test24::D RTTI
1150 // CHECK-31-NEXT:        -- (Test24::A, 0) vtable address --
1151 // CHECK-31-NEXT:        -- (Test24::B, 0) vtable address --
1152 // CHECK-31-NEXT:        -- (Test24::D, 0) vtable address --
1153 // CHECK-31-NEXT:    4 | void Test24::D::f()
1154 // CHECK-31-NEXT:    5 | vbase_offset (-8)
1155 // CHECK-31-NEXT:    6 | vcall_offset (-8)
1156 // CHECK-31-NEXT:    7 | offset_to_top (-8)
1157 // CHECK-31-NEXT:    8 | Test24::D RTTI
1158 // CHECK-31-NEXT:        -- (Test24::C, 8) vtable address --
1159 // CHECK-31-NEXT:    9 | [unused] void Test24::D::f()
1160 //
1161 // CHECK-31:      VTable indices for 'Test24::D' (1 entries).
1162 // CHECK-31-NEXT:   0 | void Test24::D::f()
1163 
1164 // CHECK-31:      Construction vtable for ('Test24::B', 0) in 'Test24::D' (5 entries).
1165 // CHECK-31-NEXT:    0 | vbase_offset (0)
1166 // CHECK-31-NEXT:    1 | vcall_offset (0)
1167 // CHECK-31-NEXT:    2 | offset_to_top (0)
1168 // CHECK-31-NEXT:    3 | Test24::B RTTI
1169 // CHECK-31-NEXT:        -- (Test24::A, 0) vtable address --
1170 // CHECK-31-NEXT:        -- (Test24::B, 0) vtable address --
1171 // CHECK-31-NEXT:    4 | void Test24::A::f()
1172 
1173 // CHECK-31:      Construction vtable for ('Test24::C', 8) in 'Test24::D' (9 entries).
1174 // CHECK-31-NEXT:    0 | vbase_offset (-8)
1175 // CHECK-31-NEXT:    1 | vcall_offset (-8)
1176 // CHECK-31-NEXT:    2 | offset_to_top (0)
1177 // CHECK-31-NEXT:    3 | Test24::C RTTI
1178 // CHECK-31-NEXT:        -- (Test24::C, 8) vtable address --
1179 // CHECK-31-NEXT:    4 | [unused] void Test24::A::f()
1180 // CHECK-31-NEXT:    5 | vcall_offset (0)
1181 // CHECK-31-NEXT:    6 | offset_to_top (8)
1182 // CHECK-31-NEXT:    7 | Test24::C RTTI
1183 // CHECK-31-NEXT:        -- (Test24::A, 0) vtable address --
1184 // CHECK-31-NEXT:    8 | void Test24::A::f()
1185 struct D : B, C {
1186   virtual void f();
1187 };
f()1188 void D::f() { }
1189 
1190 }
1191 
1192 namespace Test25 {
1193 
1194 // This mainly tests that we don't assert on this class hierarchy.
1195 
1196 struct V {
1197   virtual void f();
1198 };
1199 
1200 struct A : virtual V { };
1201 struct B : virtual V { };
1202 
1203 // CHECK-32:      Vtable for 'Test25::C' (11 entries).
1204 // CHECK-32-NEXT:    0 | vbase_offset (0)
1205 // CHECK-32-NEXT:    1 | vcall_offset (0)
1206 // CHECK-32-NEXT:    2 | offset_to_top (0)
1207 // CHECK-32-NEXT:    3 | Test25::C RTTI
1208 // CHECK-32-NEXT:        -- (Test25::A, 0) vtable address --
1209 // CHECK-32-NEXT:        -- (Test25::C, 0) vtable address --
1210 // CHECK-32-NEXT:        -- (Test25::V, 0) vtable address --
1211 // CHECK-32-NEXT:    4 | void Test25::V::f()
1212 // CHECK-32-NEXT:    5 | void Test25::C::g()
1213 // CHECK-32-NEXT:    6 | vbase_offset (-8)
1214 // CHECK-32-NEXT:    7 | vcall_offset (-8)
1215 // CHECK-32-NEXT:    8 | offset_to_top (-8)
1216 // CHECK-32-NEXT:    9 | Test25::C RTTI
1217 // CHECK-32-NEXT:        -- (Test25::B, 8) vtable address --
1218 // CHECK-32-NEXT:   10 | [unused] void Test25::V::f()
1219 //
1220 // CHECK-32:      VTable indices for 'Test25::C' (1 entries).
1221 // CHECK-32-NEXT:    1 | void Test25::C::g()
1222 
1223 // CHECK-32:      Construction vtable for ('Test25::A', 0) in 'Test25::C' (5 entries).
1224 // CHECK-32-NEXT:    0 | vbase_offset (0)
1225 // CHECK-32-NEXT:    1 | vcall_offset (0)
1226 // CHECK-32-NEXT:    2 | offset_to_top (0)
1227 // CHECK-32-NEXT:    3 | Test25::A RTTI
1228 // CHECK-32-NEXT:        -- (Test25::A, 0) vtable address --
1229 // CHECK-32-NEXT:        -- (Test25::V, 0) vtable address --
1230 // CHECK-32-NEXT:    4 | void Test25::V::f()
1231 
1232 // CHECK-32:      Construction vtable for ('Test25::B', 8) in 'Test25::C' (9 entries).
1233 // CHECK-32-NEXT:    0 | vbase_offset (-8)
1234 // CHECK-32-NEXT:    1 | vcall_offset (-8)
1235 // CHECK-32-NEXT:    2 | offset_to_top (0)
1236 // CHECK-32-NEXT:    3 | Test25::B RTTI
1237 // CHECK-32-NEXT:        -- (Test25::B, 8) vtable address --
1238 // CHECK-32-NEXT:    4 | [unused] void Test25::V::f()
1239 // CHECK-32-NEXT:    5 | vcall_offset (0)
1240 // CHECK-32-NEXT:    6 | offset_to_top (8)
1241 // CHECK-32-NEXT:    7 | Test25::B RTTI
1242 // CHECK-32-NEXT:        -- (Test25::V, 0) vtable address --
1243 // CHECK-32-NEXT:    8 | void Test25::V::f()
1244 struct C : A, virtual V, B {
1245   virtual void g();
1246 };
g()1247 void C::g() { }
1248 
1249 }
1250 
1251 namespace Test26 {
1252 
1253 // Test that we generate the right number of entries in the C-in-D construction vtable, and that
1254 // we don't mark A::a as unused.
1255 
1256 struct A {
1257   virtual void a();
1258 };
1259 
1260 struct B {
1261   virtual void c();
1262 };
1263 
1264 struct C : virtual A {
1265   virtual void b();
1266 };
1267 
1268 // CHECK-33:      Vtable for 'Test26::D' (15 entries).
1269 // CHECK-33-NEXT:    0 | vbase_offset (8)
1270 // CHECK-33-NEXT:    1 | vbase_offset (8)
1271 // CHECK-33-NEXT:    2 | vbase_offset (0)
1272 // CHECK-33-NEXT:    3 | vcall_offset (0)
1273 // CHECK-33-NEXT:    4 | offset_to_top (0)
1274 // CHECK-33-NEXT:    5 | Test26::D RTTI
1275 // CHECK-33-NEXT:        -- (Test26::B, 0) vtable address --
1276 // CHECK-33-NEXT:        -- (Test26::D, 0) vtable address --
1277 // CHECK-33-NEXT:    6 | void Test26::B::c()
1278 // CHECK-33-NEXT:    7 | void Test26::D::d()
1279 // CHECK-33-NEXT:    8 | vcall_offset (0)
1280 // CHECK-33-NEXT:    9 | vbase_offset (0)
1281 // CHECK-33-NEXT:   10 | vcall_offset (0)
1282 // CHECK-33-NEXT:   11 | offset_to_top (-8)
1283 // CHECK-33-NEXT:   12 | Test26::D RTTI
1284 // CHECK-33-NEXT:        -- (Test26::A, 8) vtable address --
1285 // CHECK-33-NEXT:        -- (Test26::C, 8) vtable address --
1286 // CHECK-33-NEXT:   13 | void Test26::A::a()
1287 // CHECK-33-NEXT:   14 | void Test26::C::b()
1288 //
1289 // CHECK-33:      VTable indices for 'Test26::D' (1 entries).
1290 // CHECK-33-NEXT:   1 | void Test26::D::d()
1291 
1292 // CHECK-33:      Construction vtable for ('Test26::C', 8) in 'Test26::D' (7 entries).
1293 // CHECK-33-NEXT:    0 | vcall_offset (0)
1294 // CHECK-33-NEXT:    1 | vbase_offset (0)
1295 // CHECK-33-NEXT:    2 | vcall_offset (0)
1296 // CHECK-33-NEXT:    3 | offset_to_top (0)
1297 // CHECK-33-NEXT:    4 | Test26::C RTTI
1298 // CHECK-33-NEXT:        -- (Test26::A, 8) vtable address --
1299 // CHECK-33-NEXT:        -- (Test26::C, 8) vtable address --
1300 // CHECK-33-NEXT:    5 | void Test26::A::a()
1301 // CHECK-33-NEXT:    6 | void Test26::C::b()
1302 class D : virtual B, virtual C {
1303   virtual void d();
1304 };
d()1305 void D::d() { }
1306 
1307 }
1308 
1309 namespace Test27 {
1310 
1311 // Test that we don't generate a secondary vtable for C in the D-in-E vtable, since
1312 // C doesn't have any virtual bases.
1313 
1314 struct A {
1315   virtual void a();
1316 };
1317 
1318 struct B {
1319   virtual void b();
1320 };
1321 
1322 struct C {
1323   virtual void c();
1324 };
1325 
1326 struct D : A, virtual B, C {
1327   virtual void d();
1328 };
1329 
1330 // CHECK-34:      Vtable for 'Test27::E' (13 entries).
1331 // CHECK-34-NEXT:    0 | vbase_offset (16)
1332 // CHECK-34-NEXT:    1 | offset_to_top (0)
1333 // CHECK-34-NEXT:    2 | Test27::E RTTI
1334 // CHECK-34-NEXT:        -- (Test27::A, 0) vtable address --
1335 // CHECK-34-NEXT:        -- (Test27::D, 0) vtable address --
1336 // CHECK-34-NEXT:        -- (Test27::E, 0) vtable address --
1337 // CHECK-34-NEXT:    3 | void Test27::A::a()
1338 // CHECK-34-NEXT:    4 | void Test27::D::d()
1339 // CHECK-34-NEXT:    5 | void Test27::E::e()
1340 // CHECK-34-NEXT:    6 | offset_to_top (-8)
1341 // CHECK-34-NEXT:    7 | Test27::E RTTI
1342 // CHECK-34-NEXT:        -- (Test27::C, 8) vtable address --
1343 // CHECK-34-NEXT:    8 | void Test27::C::c()
1344 // CHECK-34-NEXT:    9 | vcall_offset (0)
1345 // CHECK-34-NEXT:   10 | offset_to_top (-16)
1346 // CHECK-34-NEXT:   11 | Test27::E RTTI
1347 // CHECK-34-NEXT:        -- (Test27::B, 16) vtable address --
1348 // CHECK-34-NEXT:   12 | void Test27::B::b()
1349 //
1350 // CHECK-34:      VTable indices for 'Test27::E' (1 entries).
1351 // CHECK-34-NEXT:    2 | void Test27::E::e()
1352 
1353 // CHECK-34:      Construction vtable for ('Test27::D', 0) in 'Test27::E' (9 entries).
1354 // CHECK-34-NEXT:    0 | vbase_offset (16)
1355 // CHECK-34-NEXT:    1 | offset_to_top (0)
1356 // CHECK-34-NEXT:    2 | Test27::D RTTI
1357 // CHECK-34-NEXT:        -- (Test27::A, 0) vtable address --
1358 // CHECK-34-NEXT:        -- (Test27::D, 0) vtable address --
1359 // CHECK-34-NEXT:    3 | void Test27::A::a()
1360 // CHECK-34-NEXT:    4 | void Test27::D::d()
1361 // CHECK-34-NEXT:    5 | vcall_offset (0)
1362 // CHECK-34-NEXT:    6 | offset_to_top (-16)
1363 // CHECK-34-NEXT:    7 | Test27::D RTTI
1364 // CHECK-34-NEXT:        -- (Test27::B, 16) vtable address --
1365 // CHECK-34-NEXT:    8 | void Test27::B::b()
1366 struct E : D {
1367   virtual void e();
1368 };
e()1369 void E::e() { }
1370 
1371 }
1372 
1373 namespace Test28 {
1374 
1375 // Check that we do include the vtable for B in the D-in-E construction vtable, since
1376 // B is a base class of a virtual base (C).
1377 
1378 struct A {
1379   virtual void a();
1380 };
1381 
1382 struct B {
1383   virtual void b();
1384 };
1385 
1386 struct C : A, B {
1387   virtual void c();
1388 };
1389 
1390 struct D : virtual C {
1391 };
1392 
1393 // CHECK-35:      Vtable for 'Test28::E' (14 entries).
1394 // CHECK-35-NEXT:    0 | vbase_offset (8)
1395 // CHECK-35-NEXT:    1 | offset_to_top (0)
1396 // CHECK-35-NEXT:    2 | Test28::E RTTI
1397 // CHECK-35-NEXT:        -- (Test28::D, 0) vtable address --
1398 // CHECK-35-NEXT:        -- (Test28::E, 0) vtable address --
1399 // CHECK-35-NEXT:    3 | void Test28::E::e()
1400 // CHECK-35-NEXT:    4 | vcall_offset (8)
1401 // CHECK-35-NEXT:    5 | vcall_offset (0)
1402 // CHECK-35-NEXT:    6 | vcall_offset (0)
1403 // CHECK-35-NEXT:    7 | offset_to_top (-8)
1404 // CHECK-35-NEXT:    8 | Test28::E RTTI
1405 // CHECK-35-NEXT:        -- (Test28::A, 8) vtable address --
1406 // CHECK-35-NEXT:        -- (Test28::C, 8) vtable address --
1407 // CHECK-35-NEXT:    9 | void Test28::A::a()
1408 // CHECK-35-NEXT:   10 | void Test28::C::c()
1409 // CHECK-35-NEXT:   11 | offset_to_top (-16)
1410 // CHECK-35-NEXT:   12 | Test28::E RTTI
1411 // CHECK-35-NEXT:        -- (Test28::B, 16) vtable address --
1412 // CHECK-35-NEXT:   13 | void Test28::B::b()
1413 //
1414 // CHECK-35:      VTable indices for 'Test28::E' (1 entries).
1415 // CHECK-35-NEXT :   0 | void Test28::E::e()
1416 
1417 // CHECK-35:      Construction vtable for ('Test28::D', 0) in 'Test28::E' (13 entries).
1418 // CHECK-35-NEXT:    0 | vbase_offset (8)
1419 // CHECK-35-NEXT:    1 | offset_to_top (0)
1420 // CHECK-35-NEXT:    2 | Test28::D RTTI
1421 // CHECK-35-NEXT:        -- (Test28::D, 0) vtable address --
1422 // CHECK-35-NEXT:    3 | vcall_offset (8)
1423 // CHECK-35-NEXT:    4 | vcall_offset (0)
1424 // CHECK-35-NEXT:    5 | vcall_offset (0)
1425 // CHECK-35-NEXT:    6 | offset_to_top (-8)
1426 // CHECK-35-NEXT:    7 | Test28::D RTTI
1427 // CHECK-35-NEXT:        -- (Test28::A, 8) vtable address --
1428 // CHECK-35-NEXT:        -- (Test28::C, 8) vtable address --
1429 // CHECK-35-NEXT:    8 | void Test28::A::a()
1430 // CHECK-35-NEXT:    9 | void Test28::C::c()
1431 // CHECK-35-NEXT:   10 | offset_to_top (-16)
1432 // CHECK-35-NEXT:   11 | Test28::D RTTI
1433 // CHECK-35-NEXT:        -- (Test28::B, 16) vtable address --
1434 // CHECK-35-NEXT:   12 | void Test28::B::b()
1435 struct E : D {
1436   virtual void e();
1437 };
e()1438 void E::e() { }
1439 
1440 }
1441 
1442 namespace Test29 {
1443 
1444 // Test that the covariant return thunk for B::f will have a virtual 'this' adjustment,
1445 // matching gcc.
1446 
1447 struct V1 { };
1448 struct V2 : virtual V1 { };
1449 
1450 struct A {
1451   virtual V1 *f();
1452 };
1453 
1454 // CHECK-36:      Vtable for 'Test29::B' (6 entries).
1455 // CHECK-36-NEXT:    0 | vbase_offset (0)
1456 // CHECK-36-NEXT:    1 | vcall_offset (0)
1457 // CHECK-36-NEXT:    2 | offset_to_top (0)
1458 // CHECK-36-NEXT:    3 | Test29::B RTTI
1459 // CHECK-36-NEXT:        -- (Test29::A, 0) vtable address --
1460 // CHECK-36-NEXT:        -- (Test29::B, 0) vtable address --
1461 // CHECK-36-NEXT:    4 | Test29::V2 *Test29::B::f()
1462 // CHECK-36-NEXT:        [return adjustment: 0 non-virtual, -24 vbase offset offset]
1463 // CHECK-36-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
1464 // CHECK-36-NEXT:    5 | Test29::V2 *Test29::B::f()
1465 //
1466 // CHECK-36:      VTable indices for 'Test29::B' (1 entries).
1467 // CHECK-36-NEXT:    1 | Test29::V2 *Test29::B::f()
1468 struct B : virtual A {
1469   virtual V2 *f();
1470 };
f()1471 V2 *B::f() { return 0; }
1472 
1473 }
1474 
1475 namespace Test30 {
1476 
1477 // Test that we don't assert when generating a vtable for F.
1478 struct A { };
1479 
1480 struct B : virtual A {
1481  int i;
1482 };
1483 
1484 struct C {
1485  virtual void f();
1486 };
1487 
1488 struct D : virtual C, B { };
1489 struct E : virtual D { };
1490 
1491 struct F : E {
1492  virtual void f();
1493 };
f()1494 void F::f() { }
1495 
1496 }
1497 
1498 namespace Test31 {
1499 
1500 // Test that we don't add D::f twice to the primary vtable.
1501 struct A {
1502   int a;
1503 };
1504 
1505 struct B {
1506   virtual void f();
1507 };
1508 
1509 struct C : A, virtual B {
1510   virtual void f();
1511 };
1512 
1513 // CHECK-37:      Vtable for 'Test31::D' (11 entries).
1514 // CHECK-37-NEXT:    0 | vbase_offset (0)
1515 // CHECK-37-NEXT:    1 | vbase_offset (8)
1516 // CHECK-37-NEXT:    2 | vcall_offset (0)
1517 // CHECK-37-NEXT:    3 | offset_to_top (0)
1518 // CHECK-37-NEXT:    4 | Test31::D RTTI
1519 // CHECK-37-NEXT:        -- (Test31::B, 0) vtable address --
1520 // CHECK-37-NEXT:        -- (Test31::D, 0) vtable address --
1521 // CHECK-37-NEXT:    5 | void Test31::D::f()
1522 // CHECK-37-NEXT:    6 | vbase_offset (-8)
1523 // CHECK-37-NEXT:    7 | vcall_offset (-8)
1524 // CHECK-37-NEXT:    8 | offset_to_top (-8)
1525 // CHECK-37-NEXT:    9 | Test31::D RTTI
1526 // CHECK-37-NEXT:        -- (Test31::C, 8) vtable address --
1527 // CHECK-37-NEXT:   10 | void Test31::D::f()
1528 // CHECK-37-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
1529 //
1530 // CHECK-37:      VTable indices for 'Test31::D' (1 entries).
1531 // CHECK-37-NEXT:    0 | void Test31::D::f()
1532 struct D : virtual C {
1533   virtual void f();
1534 };
f()1535 void D::f() { }
1536 
1537 }
1538 
1539 namespace Test32 {
1540 
1541 // Check that we correctly lay out the virtual bases of 'Test32::D'.
1542 
1543 struct A {
1544   virtual void f();
1545 };
1546 
1547 struct B : virtual A { };
1548 struct C : A, virtual B { };
1549 struct D : virtual B { };
1550 
1551 // CHECK-38:      Virtual base offset offsets for 'Test32::E' (3 entries).
1552 // CHECK-38-NEXT:    Test32::A | -32
1553 // CHECK-38-NEXT:    Test32::B | -24
1554 // CHECK-38-NEXT:    Test32::D | -40
1555 struct E : C, virtual D {
1556   virtual void f();
1557 };
f()1558 void E::f() { }
1559 
1560 }
1561 
1562 namespace Test33 {
1563 
1564 // Test that we don't emit too many vcall offsets in 'Test32::F'.
1565 
1566 struct A {
1567   virtual void a();
1568 };
1569 
1570 struct B {
1571   virtual void b();
1572 };
1573 
1574 struct C : virtual A, virtual B {
1575   virtual void c();
1576 };
1577 
1578 struct D : virtual C { };
1579 
1580 struct E : A, D {
1581   virtual void e();
1582 };
1583 
1584 // CHECK-39:      Vtable for 'Test33::F' (30 entries).
1585 // CHECK-39-NEXT:    0 | vbase_offset (24)
1586 // CHECK-39-NEXT:    1 | vbase_offset (16)
1587 // CHECK-39-NEXT:    2 | vbase_offset (16)
1588 // CHECK-39-NEXT:    3 | vbase_offset (8)
1589 // CHECK-39-NEXT:    4 | offset_to_top (0)
1590 // CHECK-39-NEXT:    5 | Test33::F RTTI
1591 // CHECK-39-NEXT:        -- (Test33::A, 0) vtable address --
1592 // CHECK-39-NEXT:        -- (Test33::F, 0) vtable address --
1593 // CHECK-39-NEXT:    6 | void Test33::A::a()
1594 // CHECK-39-NEXT:    7 | void Test33::F::f()
1595 // CHECK-39-NEXT:    8 | vcall_offset (0)
1596 // CHECK-39-NEXT:    9 | vcall_offset (0)
1597 // CHECK-39-NEXT:   10 | vbase_offset (16)
1598 // CHECK-39-NEXT:   11 | vbase_offset (8)
1599 // CHECK-39-NEXT:   12 | vbase_offset (8)
1600 // CHECK-39-NEXT:   13 | offset_to_top (-8)
1601 // CHECK-39-NEXT:   14 | Test33::F RTTI
1602 // CHECK-39-NEXT:        -- (Test33::A, 8) vtable address --
1603 // CHECK-39-NEXT:        -- (Test33::E, 8) vtable address --
1604 // CHECK-39-NEXT:   15 | void Test33::A::a()
1605 // CHECK-39-NEXT:   16 | void Test33::E::e()
1606 // CHECK-39-NEXT:   17 | vbase_offset (0)
1607 // CHECK-39-NEXT:   18 | vcall_offset (0)
1608 // CHECK-39-NEXT:   19 | vbase_offset (8)
1609 // CHECK-39-NEXT:   20 | vbase_offset (0)
1610 // CHECK-39-NEXT:   21 | vcall_offset (0)
1611 // CHECK-39-NEXT:   22 | offset_to_top (-16)
1612 // CHECK-39-NEXT:   23 | Test33::F RTTI
1613 // CHECK-39-NEXT:        -- (Test33::A, 16) vtable address --
1614 // CHECK-39-NEXT:        -- (Test33::C, 16) vtable address --
1615 // CHECK-39-NEXT:        -- (Test33::D, 16) vtable address --
1616 // CHECK-39-NEXT:   24 | void Test33::A::a()
1617 // CHECK-39-NEXT:   25 | void Test33::C::c()
1618 // CHECK-39-NEXT:   26 | vcall_offset (0)
1619 // CHECK-39-NEXT:   27 | offset_to_top (-24)
1620 // CHECK-39-NEXT:   28 | Test33::F RTTI
1621 // CHECK-39-NEXT:        -- (Test33::B, 24) vtable address --
1622 // CHECK-39-NEXT:   29 | void Test33::B::b()
1623 //
1624 // CHECK-39:      VTable indices for 'Test33::F' (1 entries).
1625 // CHECK-39-NEXT:    1 | void Test33::F::f()
1626 struct F : virtual E, A {
1627   virtual void f();
1628 };
f()1629 void F::f() { }
1630 
1631 }
1632 
1633 namespace Test34 {
1634 
1635 // Test that we lay out the construction vtable for 'Test34::E' in 'Test34::F' correctly.
1636 
1637 struct A {
1638   virtual void a();
1639 };
1640 struct B : virtual A { };
1641 
1642 struct C : B, A {
1643   virtual void c();
1644 };
1645 
1646 struct D : A, C { };
1647 
1648 struct E : virtual D {
1649   virtual void e();
1650 };
1651 
1652 // CHECK-40:      Construction vtable for ('Test34::E', 0) in 'Test34::F' (22 entries).
1653 // CHECK-40-NEXT:    0 | vbase_offset (0)
1654 // CHECK-40-NEXT:    1 | vbase_offset (8)
1655 // CHECK-40-NEXT:    2 | vcall_offset (0)
1656 // CHECK-40-NEXT:    3 | offset_to_top (0)
1657 // CHECK-40-NEXT:    4 | Test34::E RTTI
1658 // CHECK-40-NEXT:        -- (Test34::A, 0) vtable address --
1659 // CHECK-40-NEXT:        -- (Test34::E, 0) vtable address --
1660 // CHECK-40-NEXT:    5 | void Test34::A::a()
1661 // CHECK-40-NEXT:    6 | void Test34::E::e()
1662 // CHECK-40-NEXT:    7 | vcall_offset (8)
1663 // CHECK-40-NEXT:    8 | vcall_offset (0)
1664 // CHECK-40-NEXT:    9 | vbase_offset (-8)
1665 // CHECK-40-NEXT:   10 | offset_to_top (-8)
1666 // CHECK-40-NEXT:   11 | Test34::E RTTI
1667 // CHECK-40-NEXT:        -- (Test34::A, 8) vtable address --
1668 // CHECK-40-NEXT:        -- (Test34::D, 8) vtable address --
1669 // CHECK-40-NEXT:   12 | void Test34::A::a()
1670 // CHECK-40-NEXT:   13 | vbase_offset (-16)
1671 // CHECK-40-NEXT:   14 | vcall_offset (-16)
1672 // CHECK-40-NEXT:   15 | offset_to_top (-16)
1673 // CHECK-40-NEXT:   16 | Test34::E RTTI
1674 // CHECK-40-NEXT:        -- (Test34::B, 16) vtable address --
1675 // CHECK-40-NEXT:        -- (Test34::C, 16) vtable address --
1676 // CHECK-40-NEXT:   17 | [unused] void Test34::A::a()
1677 // CHECK-40-NEXT:   18 | void Test34::C::c()
1678 // CHECK-40-NEXT:   19 | offset_to_top (-24)
1679 // CHECK-40-NEXT:   20 | Test34::E RTTI
1680 // CHECK-40-NEXT:        -- (Test34::A, 24) vtable address --
1681 // CHECK-40-NEXT:   21 | void Test34::A::a()
1682 struct F : E {
1683   virtual void f();
1684 };
f()1685 void F::f() { }
1686 
1687 }
1688 
1689 namespace Test35 {
1690 
1691 // Test that we lay out the virtual bases of 'Test35::H' in the correct order.
1692 
1693 struct A {
1694  virtual void a();
1695 
1696  int i;
1697 };
1698 
1699 struct B : virtual A {
1700  virtual void b();
1701 };
1702 
1703 struct C {
1704  virtual void c();
1705 };
1706 
1707 struct D : C, virtual B {
1708  virtual void d();
1709 };
1710 
1711 struct E : D {
1712  virtual void e();
1713 
1714  bool b;
1715 };
1716 
1717 struct F : virtual D { };
1718 struct G : virtual E { };
1719 
1720 // CHECK-41:      Vtable for 'Test35::H' (32 entries).
1721 // CHECK-41-NEXT:    0 | vbase_offset (32)
1722 // CHECK-41-NEXT:    1 | vbase_offset (0)
1723 // CHECK-41-NEXT:    2 | vcall_offset (0)
1724 // CHECK-41-NEXT:    3 | vcall_offset (0)
1725 // CHECK-41-NEXT:    4 | vbase_offset (16)
1726 // CHECK-41-NEXT:    5 | vbase_offset (8)
1727 // CHECK-41-NEXT:    6 | offset_to_top (0)
1728 // CHECK-41-NEXT:    7 | Test35::H RTTI
1729 // CHECK-41-NEXT:        -- (Test35::C, 0) vtable address --
1730 // CHECK-41-NEXT:        -- (Test35::D, 0) vtable address --
1731 // CHECK-41-NEXT:        -- (Test35::F, 0) vtable address --
1732 // CHECK-41-NEXT:        -- (Test35::H, 0) vtable address --
1733 // CHECK-41-NEXT:    8 | void Test35::C::c()
1734 // CHECK-41-NEXT:    9 | void Test35::D::d()
1735 // CHECK-41-NEXT:   10 | void Test35::H::h()
1736 // CHECK-41-NEXT:   11 | vbase_offset (0)
1737 // CHECK-41-NEXT:   12 | vbase_offset (24)
1738 // CHECK-41-NEXT:   13 | vcall_offset (0)
1739 // CHECK-41-NEXT:   14 | vbase_offset (8)
1740 // CHECK-41-NEXT:   15 | offset_to_top (-8)
1741 // CHECK-41-NEXT:   16 | Test35::H RTTI
1742 // CHECK-41-NEXT:        -- (Test35::B, 8) vtable address --
1743 // CHECK-41-NEXT:        -- (Test35::G, 8) vtable address --
1744 // CHECK-41-NEXT:   17 | void Test35::B::b()
1745 // CHECK-41-NEXT:   18 | vcall_offset (0)
1746 // CHECK-41-NEXT:   19 | offset_to_top (-16)
1747 // CHECK-41-NEXT:   20 | Test35::H RTTI
1748 // CHECK-41-NEXT:        -- (Test35::A, 16) vtable address --
1749 // CHECK-41-NEXT:   21 | void Test35::A::a()
1750 // CHECK-41-NEXT:   22 | vcall_offset (0)
1751 // CHECK-41-NEXT:   23 | vcall_offset (0)
1752 // CHECK-41-NEXT:   24 | vcall_offset (0)
1753 // CHECK-41-NEXT:   25 | vbase_offset (-16)
1754 // CHECK-41-NEXT:   26 | vbase_offset (-24)
1755 // CHECK-41-NEXT:   27 | offset_to_top (-32)
1756 // CHECK-41-NEXT:   28 | Test35::H RTTI
1757 // CHECK-41-NEXT:        -- (Test35::C, 32) vtable address --
1758 // CHECK-41-NEXT:        -- (Test35::D, 32) vtable address --
1759 // CHECK-41-NEXT:        -- (Test35::E, 32) vtable address --
1760 // CHECK-41-NEXT:   29 | void Test35::C::c()
1761 // CHECK-41-NEXT:   30 | void Test35::D::d()
1762 // CHECK-41-NEXT:   31 | void Test35::E::e()
1763 //
1764 // CHECK-41:      Virtual base offset offsets for 'Test35::H' (4 entries).
1765 // CHECK-41-NEXT:    Test35::A | -32
1766 // CHECK-41-NEXT:    Test35::B | -24
1767 // CHECK-41-NEXT:    Test35::D | -56
1768 // CHECK-41-NEXT:    Test35::E | -64
1769 //
1770 // CHECK-41:      VTable indices for 'Test35::H' (1 entries).
1771 // CHECK-41-NEXT:    2 | void Test35::H::h()
1772 struct H : F, G {
1773  virtual void h();
1774 };
h()1775 void H::h() { }
1776 
1777 }
1778 
1779 namespace Test36 {
1780 
1781 // Test that we don't mark B::f as unused in the vtable for D.
1782 
1783 struct A {
1784  virtual void f();
1785 };
1786 
1787 struct B : virtual A { };
1788 
1789 struct C : virtual A {
1790  virtual void f();
1791 };
1792 
1793 // CHECK-42:      Vtable for 'Test36::D' (12 entries).
1794 // CHECK-42-NEXT:    0 | vbase_offset (8)
1795 // CHECK-42-NEXT:    1 | vbase_offset (8)
1796 // CHECK-42-NEXT:    2 | vcall_offset (0)
1797 // CHECK-42-NEXT:    3 | offset_to_top (0)
1798 // CHECK-42-NEXT:    4 | Test36::D RTTI
1799 // CHECK-42-NEXT:        -- (Test36::C, 0) vtable address --
1800 // CHECK-42-NEXT:        -- (Test36::D, 0) vtable address --
1801 // CHECK-42-NEXT:    5 | void Test36::C::f()
1802 // CHECK-42-NEXT:    6 | void Test36::D::g()
1803 // CHECK-42-NEXT:    7 | vbase_offset (0)
1804 // CHECK-42-NEXT:    8 | vcall_offset (-8)
1805 // CHECK-42-NEXT:    9 | offset_to_top (-8)
1806 // CHECK-42-NEXT:   10 | Test36::D RTTI
1807 // CHECK-42-NEXT:        -- (Test36::A, 8) vtable address --
1808 // CHECK-42-NEXT:        -- (Test36::B, 8) vtable address --
1809 // CHECK-42-NEXT:   11 | void Test36::C::f()
1810 // CHECK-42-NEXT:        [this adjustment: 0 non-virtual, -24 vcall offset offset]
1811 //
1812 // CHECK-42:      VTable indices for 'Test36::D' (1 entries).
1813 // CHECK-42-NEXT:    1 | void Test36::D::g()
1814 struct D : virtual B, C {
1815  virtual void g();
1816 };
g()1817 void D::g() { }
1818 
1819 }
1820 
1821 namespace Test37 {
1822 
1823 // Test that we give C::f the right vtable index. (PR9660).
1824 struct A {
1825 	virtual A* f() = 0;
1826 };
1827 
1828 struct B : virtual A {
1829   virtual B* f();
1830 };
1831 
1832 // CHECK-43:      VTable indices for 'Test37::C' (1 entries).
1833 // CHECK-43-NEXT:    1 | Test37::C *Test37::C::f()
1834 struct C : B {
1835   virtual C* f();
1836 };
1837 
f()1838 C* C::f() { return 0; }
1839 
1840 }
1841 
1842 // rdar://problem/10959710
1843 namespace Test38 {
1844   struct A {
1845     virtual void *foo();
1846     virtual const void *foo() const;
1847   };
1848 
1849   // CHECK-44:      Vtable for 'Test38::B' (7 entries).
1850   // CHECK-44-NEXT:    0 | vbase_offset (0)
1851   // CHECK-44-NEXT:    1 | vcall_offset (0)
1852   // CHECK-44-NEXT:    2 | vcall_offset (0)
1853   // CHECK-44-NEXT:    3 | offset_to_top (0)
1854   // CHECK-44-NEXT:    4 | Test38::B RTTI
1855   // CHECK-44-NEXT:        -- (Test38::A, 0) vtable address --
1856   // CHECK-44-NEXT:        -- (Test38::B, 0) vtable address --
1857   // CHECK-44-NEXT:    5 | void *Test38::B::foo()
1858   // CHECK-44-NEXT:    6 | const void *Test38::B::foo() const
1859   //
1860   // CHECK-44:      VTable indices for 'Test38::B' (2 entries).
1861   // CHECK-44-NEXT:    0 | void *Test38::B::foo()
1862   // CHECK-44-NEXT:    1 | const void *Test38::B::foo() const
1863   class B : virtual public A {
1864     void *foo();
1865     const void *foo() const;
1866   };
1867 
foo()1868   void *B::foo() { return 0; }
1869 }
1870 
1871 namespace Test39 {
1872   struct A {
1873     virtual void foo() = delete;
1874   };
1875 
1876   // CHECK-45:      Vtable for 'Test39::B' (4 entries).
1877   // CHECK-45-NEXT:    0 | offset_to_top (0)
1878   // CHECK-45-NEXT:    1 | Test39::B RTTI
1879   // CHECK-45-NEXT:        -- (Test39::A, 0) vtable address --
1880   // CHECK-45-NEXT:        -- (Test39::B, 0) vtable address --
1881   // CHECK-45-NEXT:    2 | void Test39::A::foo() [deleted]
1882   // CHECK-45-NEXT:    3 | void Test39::B::foo2()
1883   //
1884   // CHECK-45:      VTable indices for 'Test39::B' (1 entries).
1885   // CHECK-45-NEXT:    1 | void Test39::B::foo2()
1886   struct B: A {
1887     virtual void foo2();
1888   };
1889 
foo2()1890   void B::foo2() {
1891   }
1892 }
1893 
1894 namespace Test40 {
1895   struct A {
1896     virtual void foo() = 0;
1897   };
1898 
1899   struct B : public A {
1900     virtual void foo();
1901   };
1902 
1903   struct C: public B {
1904     // CHECK-46: VTable indices for 'Test40::C' (8 entries).
1905     // CHECK-46-NEXT: 1 | int Test40::C::f(int)
1906     // CHECK-46-NEXT: 2 | int Test40::C::f()
1907     // CHECK-46-NEXT: 3 | int Test40::C::g(int)
1908     // CHECK-46-NEXT: 4 | int Test40::C::g()
1909     // CHECK-46-NEXT: 5 | int Test40::C::h(int)
1910     // CHECK-46-NEXT: 6 | int Test40::C::h()
1911     // CHECK-46-NEXT: 7 | int Test40::C::i(int)
1912     // CHECK-46-NEXT: 8 | int Test40::C::i()
1913     virtual int f(int);
1914     virtual int f();
1915     virtual int g(int);
1916     virtual int g();
1917     virtual int h(int);
1918     virtual int h();
1919     virtual int i(int);
1920     virtual int i();
1921   };
1922 
1923   class D : C {};
1924 
1925   D d;
1926 }
1927