171568a9eSLeonard Chan // Multiple inheritance.
271568a9eSLeonard Chan 
3532dc62bSNikita Popov // RUN: %clang_cc1 -no-opaque-pointers %s -triple=aarch64-unknown-fuchsia -O1 -S -o - -emit-llvm -fhalf-no-semantic-interposition | FileCheck %s
471568a9eSLeonard Chan 
571568a9eSLeonard Chan // CHECK: %class.C = type { %class.A, %class.B }
671568a9eSLeonard Chan // CHECK: %class.A = type { i32 (...)** }
771568a9eSLeonard Chan // CHECK: %class.B = type { i32 (...)** }
871568a9eSLeonard Chan 
971568a9eSLeonard Chan // 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.
1071568a9eSLeonard Chan // The component for bar() instead points to a thunk which redirects to C::bar() which overrides B::bar().
1171568a9eSLeonard Chan // Now that we have a class with 2 parents, the offset to top in the second array is non-zero.
12cf8ff75bSLeonard Chan // 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
1371568a9eSLeonard Chan 
14fd739804SFangrui Song // CHECK: @_ZTV1C ={{.*}} unnamed_addr alias { [4 x i32], [3 x i32] }, { [4 x i32], [3 x i32] }* @_ZTV1C.local
1571568a9eSLeonard Chan 
161b1c8d83Shyeongyu kim // CHECK:      define{{.*}} void @_Z8C_foobarP1C(%class.C* noundef %c) local_unnamed_addr
1771568a9eSLeonard Chan // CHECK-NEXT: entry:
1871568a9eSLeonard Chan // CHECK-NEXT:   [[c:%[0-9]+]] = bitcast %class.C* %c to i8**
1971568a9eSLeonard Chan // CHECK-NEXT:   [[vtable:%[a-z0-9]+]] = load i8*, i8** [[c]], align 8
2071568a9eSLeonard Chan 
2171568a9eSLeonard Chan // Offset 0 to get first method
22*bfb9b8e0SSanjay Patel // CHECK-NEXT:   [[ptr1:%[0-9]+]] = tail call i8* @llvm.load.relative.i32(i8* [[vtable]], i32 0)
2371568a9eSLeonard Chan // CHECK-NEXT:   [[method1:%[0-9]+]] = bitcast i8* [[ptr1]] to void (%class.C*)*
2469cd776eSCJ Johnson // CHECK-NEXT:   call void [[method1]](%class.C* {{[^,]*}} %c)
2571568a9eSLeonard Chan // CHECK-NEXT:   [[vtable:%[a-z0-9]+]] = load i8*, i8** [[c]], align 8
2671568a9eSLeonard Chan 
2771568a9eSLeonard Chan // Offset by 4 to get the next bar()
28*bfb9b8e0SSanjay Patel // CHECK-NEXT:   [[ptr2:%[0-9]+]] = tail call i8* @llvm.load.relative.i32(i8* [[vtable]], i32 4)
2971568a9eSLeonard Chan // CHECK-NEXT:   [[method2:%[0-9]+]] = bitcast i8* [[ptr2]] to void (%class.C*)*
3069cd776eSCJ Johnson // CHECK-NEXT:   call void [[method2]](%class.C* {{[^,]*}} %c)
3171568a9eSLeonard Chan // CHECK-NEXT:   ret void
3271568a9eSLeonard Chan // CHECK-NEXT: }
3371568a9eSLeonard Chan 
3471568a9eSLeonard Chan class A {
3571568a9eSLeonard Chan public:
3671568a9eSLeonard Chan   virtual void foo();
3771568a9eSLeonard Chan };
3871568a9eSLeonard Chan 
3971568a9eSLeonard Chan class B {
4071568a9eSLeonard Chan   virtual void bar();
4171568a9eSLeonard Chan };
4271568a9eSLeonard Chan 
4371568a9eSLeonard Chan class C : public A, public B {
4471568a9eSLeonard Chan public:
4571568a9eSLeonard Chan   void foo() override;
4671568a9eSLeonard Chan   void bar() override;
4771568a9eSLeonard Chan };
4871568a9eSLeonard Chan 
foo()4971568a9eSLeonard Chan void C::foo() {}
bar()5071568a9eSLeonard Chan void C::bar() {}
5171568a9eSLeonard Chan 
C_foobar(C * c)5271568a9eSLeonard Chan void C_foobar(C *c) {
5371568a9eSLeonard Chan   c->foo();
5471568a9eSLeonard Chan   c->bar();
5571568a9eSLeonard Chan }
56