1 ;; Test that dynamically exported symbols prevent devirtualization.
2 ;; Note that --export-dynamic-symbol and --dynamic-list are tested similarly
3 ;; in the v1.16 directory, because those were not properly passed down to the
6 ;; First check that we get devirtualization without any export dynamic options.
9 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
10 ; RUN: opt -thinlto-bc -o %t2.o %s
11 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
12 ; RUN: --plugin-opt=whole-program-visibility \
13 ; RUN: --plugin-opt=save-temps \
14 ; RUN: --plugin-opt=-pass-remarks=. \
15 ; RUN: %t2.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK
16 ; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
19 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
20 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s
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: %t.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK
26 ; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
29 ; RUN: opt -o %t4.o %s
30 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
31 ; RUN: --plugin-opt=whole-program-visibility \
32 ; RUN: --plugin-opt=save-temps \
33 ; RUN: --plugin-opt=-pass-remarks=. \
34 ; RUN: %t4.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK
35 ; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
37 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi
38 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi
40 ;; Check that all WPD fails with --export-dynamic.
43 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
44 ; RUN: --plugin-opt=whole-program-visibility \
45 ; RUN: --plugin-opt=save-temps \
46 ; RUN: --plugin-opt=-pass-remarks=. \
48 ; RUN: --export-dynamic 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
49 ; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR
52 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
53 ; RUN: --plugin-opt=whole-program-visibility \
54 ; RUN: --plugin-opt=save-temps \
55 ; RUN: --plugin-opt=-pass-remarks=. \
57 ; RUN: --export-dynamic 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
58 ; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR
61 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
62 ; RUN: --plugin-opt=whole-program-visibility \
63 ; RUN: --plugin-opt=save-temps \
64 ; RUN: --plugin-opt=-pass-remarks=. \
66 ; RUN: --export-dynamic 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
67 ; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR
69 ;; Check that all WPD fails with when linking against a shared library containing
70 ;; preemptible versions of the vtables. In this case the symbols in the object being
71 ;; linked against the shared library must be exported to .dynsym to allow the runtime
72 ;; preemption, even without any options.
75 ; RUN: opt -relocation-model=pic --thinlto-bc -o %t5.o %s
76 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
77 ; RUN: %t5.o -o %t5.so -shared
78 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
79 ; RUN: --plugin-opt=whole-program-visibility \
80 ; RUN: --plugin-opt=-pass-remarks=. \
81 ; RUN: %t5.o %t5.so -o %t5 \
82 ; RUN: --export-dynamic 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
85 ; RUN: opt -relocation-model=pic --thinlto-bc --thinlto-split-lto-unit -o %t5.o %s
86 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
87 ; RUN: %t5.o -o %t5.so -shared
88 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
89 ; RUN: --plugin-opt=whole-program-visibility \
90 ; RUN: --plugin-opt=-pass-remarks=. \
91 ; RUN: %t5.o %t5.so -o %t5 \
92 ; RUN: --export-dynamic 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
95 ; RUN: opt -relocation-model=pic -o %t5.o %s
96 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
97 ; RUN: %t5.o -o %t5.so -shared
98 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
99 ; RUN: --plugin-opt=whole-program-visibility \
100 ; RUN: --plugin-opt=-pass-remarks=. \
101 ; RUN: %t5.o %t5.so -o %t5 \
102 ; RUN: --export-dynamic 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
104 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
105 target triple = "x86_64-grtev4-linux-gnu"
107 %struct.A = type { ptr }
108 %struct.B = type { %struct.A }
109 %struct.C = type { %struct.A }
110 %struct.D = type { ptr }
112 @_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 !5
113 @_ZTV1C = linkonce_odr unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1C1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !2, !vcall_visibility !5
114 @_ZTV1D = linkonce_odr unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEi] }, !type !3, !vcall_visibility !5
116 ;; Prevent the vtables from being dead code eliminated.
117 @llvm.used = appending global [3 x ptr] [ ptr @_ZTV1B, ptr @_ZTV1C, ptr @_ZTV1D]
119 ; CHECK-IR-LABEL: define dso_local {{(noundef )?}}i32 @_start
120 define i32 @_start(ptr %obj, ptr %obj2, i32 %a) {
122 %vtable = load ptr, ptr %obj
123 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")
124 call void @llvm.assume(i1 %p)
125 %fptrptr = getelementptr ptr, ptr %vtable, i32 1
126 %fptr1 = load ptr, ptr %fptrptr, align 8
128 ;; Check that the call was devirtualized.
129 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
130 ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1
131 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)
133 %fptr22 = load ptr, ptr %vtable, align 8
135 ;; We still have to call it as virtual.
136 ; CHECK-IR: %call3 = tail call i32 %fptr22
137 ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr22
138 %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call)
140 %vtable2 = load ptr, ptr %obj2
141 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !4)
142 call void @llvm.assume(i1 %p2)
144 %fptr33 = load ptr, ptr %vtable2, align 8
146 ;; Check that the call was devirtualized.
147 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi
148 ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33
149 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3)
152 ; CHECK-IR-LABEL: ret i32
155 declare i1 @llvm.type.test(ptr, metadata)
156 declare void @llvm.assume(i1)
158 define i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {
162 define i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {
166 define i32 @_ZN1C1fEi(ptr %this, i32 %a) #0 {
170 define i32 @_ZN1D1mEi(ptr %this, i32 %a) #0 {
174 ;; Make sure we don't inline or otherwise optimize out the direct calls.
175 attributes #0 = { noinline optnone }
177 !0 = !{i64 16, !"_ZTS1A"}
178 !1 = !{i64 16, !"_ZTS1B"}
179 !2 = !{i64 16, !"_ZTS1C"}