1 // Multiple inheritance.
2
3 // RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -O1 -S -o - -emit-llvm -fexperimental-relative-c++-abi-vtables | FileCheck %s
4
5 // CHECK: %class.C = type { %class.A, %class.B }
6 // CHECK: %class.A = type { i32 (...)** }
7 // CHECK: %class.B = type { i32 (...)** }
8
9 // VTable for C contains 2 sub-vtables (represented as 2 structs). The first contains the components for B and the second contains the components for C. The RTTI ptr in both arrays still point to the RTTI struct for C.
10 // The component for bar() instead points to a thunk which redirects to C::bar() which overrides B::bar().
11 // Now that we have a class with 2 parents, the offset to top in the second array is non-zero.
12 // CHECK: @_ZTV1C.local = private unnamed_addr constant { [4 x i32], [3 x i32] } { [4 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint ({ i8*, i8*, i32, i32, i8*, i64, i8*, i64 }** @_ZTI1C.rtti_proxy to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32], [3 x i32] }, { [4 x i32], [3 x i32] }* @_ZTV1C.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%class.C*)* dso_local_equivalent @_ZN1C3fooEv to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32], [3 x i32] }, { [4 x i32], [3 x i32] }* @_ZTV1C.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%class.C*)* dso_local_equivalent @_ZN1C3barEv to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32], [3 x i32] }, { [4 x i32], [3 x i32] }* @_ZTV1C.local, i32 0, i32 0, i32 2) to i64)) to i32)], [3 x i32] [i32 -8, i32 trunc (i64 sub (i64 ptrtoint ({ i8*, i8*, i32, i32, i8*, i64, i8*, i64 }** @_ZTI1C.rtti_proxy to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32], [3 x i32] }, { [4 x i32], [3 x i32] }* @_ZTV1C.local, i32 0, i32 1, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%class.C*)* dso_local_equivalent @_ZThn8_N1C3barEv to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32], [3 x i32] }, { [4 x i32], [3 x i32] }* @_ZTV1C.local, i32 0, i32 1, i32 2) to i64)) to i32)] }, align 4
13
14 // CHECK: @_ZTV1C = unnamed_addr alias { [4 x i32], [3 x i32] }, { [4 x i32], [3 x i32] }* @_ZTV1C.local
15
16 // CHECK: define void @_Z8C_foobarP1C(%class.C* %c) local_unnamed_addr
17 // CHECK-NEXT: entry:
18 // CHECK-NEXT: [[c:%[0-9]+]] = bitcast %class.C* %c to i8**
19 // CHECK-NEXT: [[vtable:%[a-z0-9]+]] = load i8*, i8** [[c]], align 8
20
21 // Offset 0 to get first method
22 // CHECK-NEXT: [[ptr1:%[0-9]+]] = call i8* @llvm.load.relative.i32(i8* [[vtable]], i32 0)
23 // CHECK-NEXT: [[method1:%[0-9]+]] = bitcast i8* [[ptr1]] to void (%class.C*)*
24 // CHECK-NEXT: call void [[method1]](%class.C* {{[^,]*}} %c)
25 // CHECK-NEXT: [[vtable:%[a-z0-9]+]] = load i8*, i8** [[c]], align 8
26
27 // Offset by 4 to get the next bar()
28 // CHECK-NEXT: [[ptr2:%[0-9]+]] = call i8* @llvm.load.relative.i32(i8* [[vtable]], i32 4)
29 // CHECK-NEXT: [[method2:%[0-9]+]] = bitcast i8* [[ptr2]] to void (%class.C*)*
30 // CHECK-NEXT: call void [[method2]](%class.C* {{[^,]*}} %c)
31 // CHECK-NEXT: ret void
32 // CHECK-NEXT: }
33
34 class A {
35 public:
36 virtual void foo();
37 };
38
39 class B {
40 virtual void bar();
41 };
42
43 class C : public A, public B {
44 public:
45 void foo() override;
46 void bar() override;
47 };
48
foo()49 void C::foo() {}
bar()50 void C::bar() {}
51
C_foobar(C * c)52 void C_foobar(C *c) {
53 c->foo();
54 c->bar();
55 }
56