| 1 |
// Multiple inheritance. |
| 2 |
|
| 3 |
// RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -O1 -o - -emit-llvm -fhalf-no-semantic-interposition | FileCheck %s |
| 4 |
|
| 5 |
// 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. |
| 6 |
// The component for bar() instead points to a thunk which redirects to C::bar() which overrides B::bar(). |
| 7 |
// Now that we have a class with 2 parents, the offset to top in the second array is non-zero. |
| 8 |
// CHECK: @_ZTV1C.local = internal unnamed_addr constant { [4 x i32], [3 x i32] } { [4 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZTI1C.rtti_proxy to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32], [3 x i32] }, ptr @_ZTV1C.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1C3fooEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32], [3 x i32] }, ptr @_ZTV1C.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1C3barEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32], [3 x i32] }, ptr @_ZTV1C.local, i32 0, i32 0, i32 2) to i64)) to i32)], [3 x i32] [i32 -8, i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZTI1C.rtti_proxy to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32], [3 x i32] }, ptr @_ZTV1C.local, i32 0, i32 1, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZThn8_N1C3barEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32], [3 x i32] }, ptr @_ZTV1C.local, i32 0, i32 1, i32 2) to i64)) to i32)] }, align 4 |
| 9 |
|
| 10 |
// CHECK: @_ZTV1C ={{.*}} unnamed_addr alias { [4 x i32], [3 x i32] }, ptr @_ZTV1C.local |
| 11 |
|
| 12 |
// CHECK: define{{.*}} void @_Z8C_foobarP1C(ptr noundef %c) local_unnamed_addr |
| 13 |
// CHECK-NEXT: entry: |
| 14 |
// CHECK-NEXT: [[vtable:%[a-z0-9]+]] = load ptr, ptr %c, align 8 |
| 15 |
|
| 16 |
// Offset 0 to get first method |
| 17 |
// CHECK-NEXT: [[ptr1:%[0-9]+]] = tail call ptr @llvm.load.relative.i32(ptr [[vtable]], i32 0) |
| 18 |
// CHECK-NEXT: call void [[ptr1]](ptr {{[^,]*}} %c) |
| 19 |
// CHECK-NEXT: [[vtable:%[a-z0-9]+]] = load ptr, ptr %c, align 8 |
| 20 |
|
| 21 |
// Offset by 4 to get the next bar() |
| 22 |
// CHECK-NEXT: [[ptr2:%[0-9]+]] = tail call ptr @llvm.load.relative.i32(ptr [[vtable]], i32 4) |
| 23 |
// CHECK-NEXT: call void [[ptr2]](ptr {{[^,]*}} %c) |
| 24 |
// CHECK-NEXT: ret void |
| 25 |
// CHECK-NEXT: } |
| 26 |
|
| 27 |
class A { |
| 28 |
public: |
| 29 |
virtual void foo(); |
| 30 |
}; |
| 31 |
|
| 32 |
class B { |
| 33 |
virtual void bar(); |
| 34 |
}; |
| 35 |
|
| 36 |
class C : public A, public B { |
| 37 |
public: |
| 38 |
void foo() override; |
| 39 |
void bar() override; |
| 40 |
}; |
| 41 |
|
| 42 |
void C::foo() {} |
| 43 |
void C::bar() {} |
| 44 |
|
| 45 |
void C_foobar(C *c) { |
| 46 |
c->foo(); |
| 47 |
c->bar(); |
| 48 |
} |