clang/test/CodeGenCXX/RelativeVTablesABI/inheritted-virtual-function.cpp
raw| 1 | // Check the layout of the vtable for a child class that inherits a virtual |
| 2 | // function but does not override it. |
| 3 | |
| 4 | // RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -O1 -o - -emit-llvm -fhalf-no-semantic-interposition | FileCheck %s |
| 5 | |
| 6 | class A { |
| 7 | public: |
| 8 | virtual void foo(); |
| 9 | }; |
| 10 | |
| 11 | // The VTable for B should look similar to the vtable for A but the component for foo() should point to A::foo() and the component for bar() should point to B::bar(). |
| 12 | // 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 @_ZN1B3barEv 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 |
| 13 | // CHECK: @_ZTV1B ={{.*}} unnamed_addr alias { [4 x i32] }, ptr @_ZTV1B.local |
| 14 | |
| 15 | class B : public A { |
| 16 | public: |
| 17 | virtual void bar(); |
| 18 | }; |
| 19 | |
| 20 | void A::foo() {} |
| 21 | void B::bar() {} |
| 22 | |
| 23 | void A_foo(A *a) { |
| 24 | a->foo(); |
| 25 | } |
| 26 | |
| 27 | void B_foo(B *b) { |
| 28 | b->foo(); |
| 29 | } |