| 1 |
// Diamond inheritance. |
| 2 |
// A more complicated multiple inheritance example that includes longer chain of inheritance and a common ancestor. |
| 3 |
|
| 4 |
// RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -O1 -o - -emit-llvm -fhalf-no-semantic-interposition | FileCheck %s |
| 5 |
|
| 6 |
// VTable for B should contain offset to top (0), RTTI pointer, A::foo(), and B::barB(). |
| 7 |
// CHECK: @_ZTV1B.local = internal unnamed_addr constant { [4 x i32] } { [4 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZTI1B.rtti_proxy to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @_ZTV1B.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1A3fooEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @_ZTV1B.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1B4barBEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @_ZTV1B.local, i32 0, i32 0, i32 2) to i64)) to i32)] }, align 4 |
| 8 |
|
| 9 |
// VTable for C should contain offset to top (0), RTTI pointer, A::foo(), and C::barC(). |
| 10 |
// CHECK: @_ZTV1C.local = internal unnamed_addr constant { [4 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] }, ptr @_ZTV1C.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1A3fooEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 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 @_ZN1C4barCEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @_ZTV1C.local, i32 0, i32 0, i32 2) to i64)) to i32)] }, align 4 |
| 11 |
|
| 12 |
// VTable for D should be similar to the mutiple inheritance example where this |
| 13 |
// vtable contains 2 inner vtables: |
| 14 |
// - 1st table containing D::foo(), B::barB(), and D::baz(). |
| 15 |
// - 2nd table containing a thunk to D::foo() and C::barC(). |
| 16 |
// CHECK: @_ZTV1D.local = internal unnamed_addr constant { [5 x i32], [4 x i32] } { [5 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZTI1D.rtti_proxy to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [5 x i32], [4 x i32] }, ptr @_ZTV1D.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1D3fooEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [5 x i32], [4 x i32] }, ptr @_ZTV1D.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1B4barBEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [5 x i32], [4 x i32] }, ptr @_ZTV1D.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1D3bazEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [5 x i32], [4 x i32] }, ptr @_ZTV1D.local, i32 0, i32 0, i32 2) to i64)) to i32)], [4 x i32] [i32 -8, i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZTI1D.rtti_proxy to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [5 x i32], [4 x i32] }, ptr @_ZTV1D.local, i32 0, i32 1, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZThn8_N1D3fooEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [5 x i32], [4 x i32] }, ptr @_ZTV1D.local, i32 0, i32 1, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1C4barCEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [5 x i32], [4 x i32] }, ptr @_ZTV1D.local, i32 0, i32 1, i32 2) to i64)) to i32)] }, align 4 |
| 17 |
|
| 18 |
// @_ZTV1B ={{.*}} unnamed_addr alias { [4 x i32] }, ptr @_ZTV1B.local |
| 19 |
// @_ZTV1C ={{.*}} unnamed_addr alias { [4 x i32] }, ptr @_ZTV1C.local |
| 20 |
// @_ZTV1D ={{.*}} unnamed_addr alias { [5 x i32], [4 x i32] }, ptr @_ZTV1D.local |
| 21 |
|
| 22 |
class A { |
| 23 |
public: |
| 24 |
virtual void foo(); |
| 25 |
}; |
| 26 |
|
| 27 |
class B : public A { |
| 28 |
public: |
| 29 |
virtual void barB(); |
| 30 |
}; |
| 31 |
|
| 32 |
class C : public A { |
| 33 |
virtual void barC(); |
| 34 |
}; |
| 35 |
|
| 36 |
// Should be a struct with 2 arrays from 2 parents. |
| 37 |
// The 1st contains D::foo(), B::barB(), and D::baz(). |
| 38 |
// The 2nd contains C::barC(), and a thunk that points to D::foo(). |
| 39 |
class D : public B, C { |
| 40 |
public: |
| 41 |
virtual void baz(); |
| 42 |
void foo() override; |
| 43 |
}; |
| 44 |
|
| 45 |
void B::barB() {} |
| 46 |
void C::barC() {} |
| 47 |
void D::foo() {} |
| 48 |
void D::baz() {} |
| 49 |
|
| 50 |
void D_foo(D *d) { |
| 51 |
d->foo(); |
| 52 |
} |