1;; Test that symbols defined in shared libraries prevent devirtualization. 2 3;; First check that we get devirtualization when the defs are in the 4;; LTO unit. 5 6;; Index based WPD 7;; Generate unsplit module with summary for ThinLTO index-based WPD. 8; RUN: opt --thinlto-bc -o %t1a.o %s 9; RUN: opt --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll 10; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 11; RUN: --plugin-opt=whole-program-visibility \ 12; RUN: --plugin-opt=save-temps \ 13; RUN: --plugin-opt=-pass-remarks=. \ 14; RUN: %t1a.o %t2a.o -o %t3a 2>&1 | FileCheck %s --check-prefix=REMARK 15; RUN: llvm-dis %t1a.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 16 17;; Hybrid WPD 18;; Generate split module with summary for hybrid Thin/Regular LTO WPD. 19; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s 20; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll 21; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 22; RUN: --plugin-opt=whole-program-visibility \ 23; RUN: --plugin-opt=save-temps \ 24; RUN: --plugin-opt=-pass-remarks=. \ 25; RUN: %t1b.o %t2b.o -o %t3b 2>&1 | FileCheck %s --check-prefix=REMARK 26; RUN: llvm-dis %t1b.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 27 28;; Regular LTO WPD 29; RUN: opt -o %t1c.o %s 30; RUN: opt -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll 31; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 32; RUN: --plugin-opt=whole-program-visibility \ 33; RUN: --plugin-opt=save-temps \ 34; RUN: --plugin-opt=-pass-remarks=. \ 35; RUN: %t1c.o %t2c.o -o %t3c 2>&1 | FileCheck %s --check-prefix=REMARK 36; RUN: llvm-dis %t3c.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 37 38; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi 39 40;; Check that WPD fails with when linking against a shared library 41;; containing the strong defs of the vtables. 42; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 43; RUN: %t2c.o -o %t.so -shared 44 45;; Index based WPD 46; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 47; RUN: --plugin-opt=whole-program-visibility \ 48; RUN: --plugin-opt=-pass-remarks=. \ 49; RUN: %t1a.o %t.so -o %t4a \ 50; RUN: --export-dynamic 2>&1 | count 0 51 52;; Hybrid WPD 53; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t4.o %s 54; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 55; RUN: --plugin-opt=whole-program-visibility \ 56; RUN: --plugin-opt=-pass-remarks=. \ 57; RUN: %t1b.o %t.so -o %t4b \ 58; RUN: --export-dynamic 2>&1 | count 0 59 60;; Regular LTO WPD 61; RUN: opt -o %t4.o %s 62; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 63; RUN: --plugin-opt=whole-program-visibility \ 64; RUN: --plugin-opt=-pass-remarks=. \ 65; RUN: %t1c.o %t.so -o %t4c \ 66; RUN: --export-dynamic 2>&1 | count 0 67 68target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 69target triple = "x86_64-grtev4-linux-gnu" 70 71%struct.A = type { ptr } 72%struct.B = type { %struct.A } 73 74@_ZTV1A = available_externally unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1A1fEi, ptr @_ZN1A1nEi] }, !type !0, !vcall_visibility !2 75@_ZTV1B = linkonce_odr unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !2 76 77;; Prevent the vtables from being dead code eliminated. 78@llvm.used = appending global [2 x ptr] [ ptr @_ZTV1A, ptr @_ZTV1B] 79 80; CHECK-IR-LABEL: define dso_local i32 @_start 81define i32 @_start(ptr %obj, i32 %a) { 82entry: 83 %vtable = load ptr, ptr %obj 84 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A") 85 call void @llvm.assume(i1 %p) 86 %fptrptr = getelementptr ptr, ptr %vtable, i32 1 87 %fptr1 = load ptr, ptr %fptrptr, align 8 88 89 ;; Check that the call was devirtualized. 90 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi 91 ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1 92 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a) 93 94 ret i32 %call 95} 96; CHECK-IR-LABEL: ret i32 97; CHECK-IR-LABEL: } 98 99declare i1 @llvm.type.test(ptr, metadata) 100declare void @llvm.assume(i1) 101 102define available_externally i32 @_ZN1A1fEi(ptr %this, i32 %a) #0 { 103 ret i32 0 104} 105 106define available_externally i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 { 107 ret i32 0 108} 109 110define linkonce_odr i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 { 111 ret i32 0 112} 113 114;; Make sure we don't inline or otherwise optimize out the direct calls. 115attributes #0 = { noinline optnone } 116 117!0 = !{i64 16, !"_ZTS1A"} 118!1 = !{i64 16, !"_ZTS1B"} 119!2 = !{i64 0} 120