1 // Check the vtable layout for classes with key functions defined in different 2 // translation units. This TU only manifests the vtable for A. 3 4 // RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -O1 -S -o - -emit-llvm -fexperimental-relative-c++-abi-vtables | FileCheck %s 5 6 #include "cross-tu-header.h" 7 8 // CHECK: $_ZN1A3fooEv.stub = comdat any 9 // CHECK: $_ZN1A3barEv.stub = comdat any 10 // CHECK: $_ZTI1A.rtti_proxy = comdat any 11 12 // CHECK: @_ZTV1A.local = private unnamed_addr constant { [4 x i32] } { [4 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint ({ i8*, i8* }** @_ZTI1A.rtti_proxy to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32] }, { [4 x i32] }* @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%class.A*)* @_ZN1A3fooEv.stub to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32] }, { [4 x i32] }* @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (void (%class.A*)* @_ZN1A3barEv.stub to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32] }, { [4 x i32] }* @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32)] }, align 4 13 // @_ZTV1A = unnamed_addr alias { [4 x i32] }, { [4 x i32] }* @_ZTV1A.local 14 15 // A::foo() is still available for other modules to use since it is not marked with private or internal linkage. 16 // CHECK: define void @_ZN1A3fooEv(%class.A* nocapture %this) unnamed_addr 17 // CHECK-NEXT: entry: 18 // CHECK-NEXT: ret void 19 // CHECK-NEXT: } 20 21 // The proxy that we take a reference to in the vtable has hidden visibility and external linkage so it can be used only by other modules in the same DSO. A::foo() is inlined into this stub since it is defined in the same module. 22 // CHECK: define hidden void @_ZN1A3fooEv.stub(%class.A* nocapture %0) unnamed_addr #{{[0-9]+}} comdat 23 // CHECK-NEXT: entry: 24 // CHECK-NEXT: ret void 25 // CHECK-NEXT: } 26 27 // A::bar() is called within the module but not defined, even though the VTable for A is emitted here 28 // CHECK: declare void @_ZN1A3barEv(%class.A*) unnamed_addr 29 30 // The stub for A::bar() is made private, so it will not appear in the symbol table and is only used in this module. We tail call here because A::bar() is not defined in the same module. 31 // CHECK: define hidden void @_ZN1A3barEv.stub(%class.A* %0) unnamed_addr {{#[0-9]+}} comdat { 32 // CHECK-NEXT: entry: 33 // CHECK-NEXT: tail call void @_ZN1A3barEv(%class.A* %0) 34 // CHECK-NEXT: ret void 35 // CHECK-NEXT: } 36 37 void A::foo() {} 38 void A_foo(A *a) { a->foo(); } 39 void A_bar(A *a) { a->bar(); } 40