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 { i32 (...)** }
108 %struct.B = type { %struct.A }
109 %struct.C = type { %struct.A }
110 %struct.D = type { i32 (...)** }
112 @_ZTV1B = linkonce_odr unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !1, !vcall_visibility !5
113 @_ZTV1C = linkonce_odr unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.C*, i32)* @_ZN1C1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !2, !vcall_visibility !5
114 @_ZTV1D = linkonce_odr unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.D*, i32)* @_ZN1D1mEi to i8*)] }, !type !3, !vcall_visibility !5
116 ;; Prevent the vtables from being dead code eliminated.
117 @llvm.used = appending global [3 x i8*] [ i8* bitcast ( { [4 x i8*] }* @_ZTV1B to i8*), i8* bitcast ( { [4 x i8*] }* @_ZTV1C to i8*), i8* bitcast ( { [3 x i8*] }* @_ZTV1D to i8*)]
119 ; CHECK-IR-LABEL: define dso_local i32 @_start
120 define i32 @_start(%struct.A* %obj, %struct.D* %obj2, i32 %a) {
122 %0 = bitcast %struct.A* %obj to i8***
123 %vtable = load i8**, i8*** %0
124 %1 = bitcast i8** %vtable to i8*
125 %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A")
126 call void @llvm.assume(i1 %p)
127 %fptrptr = getelementptr i8*, i8** %vtable, i32 1
128 %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)**
129 %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8
131 ;; Check that the call was devirtualized.
132 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
133 ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1
134 %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a)
136 %3 = bitcast i8** %vtable to i32 (%struct.A*, i32)**
137 %fptr22 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %3, align 8
139 ;; We still have to call it as virtual.
140 ; CHECK-IR: %call3 = tail call i32 %fptr22
141 ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr22
142 %call3 = tail call i32 %fptr22(%struct.A* nonnull %obj, i32 %call)
144 %4 = bitcast %struct.D* %obj2 to i8***
145 %vtable2 = load i8**, i8*** %4
146 %5 = bitcast i8** %vtable2 to i8*
147 %p2 = call i1 @llvm.type.test(i8* %5, metadata !4)
148 call void @llvm.assume(i1 %p2)
150 %6 = bitcast i8** %vtable2 to i32 (%struct.D*, i32)**
151 %fptr33 = load i32 (%struct.D*, i32)*, i32 (%struct.D*, i32)** %6, align 8
153 ;; Check that the call was devirtualized.
154 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi
155 ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33
156 %call4 = tail call i32 %fptr33(%struct.D* nonnull %obj2, i32 %call3)
159 ; CHECK-IR-LABEL: ret i32
162 declare i1 @llvm.type.test(i8*, metadata)
163 declare void @llvm.assume(i1)
165 define i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) #0 {
169 define i32 @_ZN1A1nEi(%struct.A* %this, i32 %a) #0 {
173 define i32 @_ZN1C1fEi(%struct.C* %this, i32 %a) #0 {
177 define i32 @_ZN1D1mEi(%struct.D* %this, i32 %a) #0 {
181 ;; Make sure we don't inline or otherwise optimize out the direct calls.
182 attributes #0 = { noinline optnone }
184 !0 = !{i64 16, !"_ZTS1A"}
185 !1 = !{i64 16, !"_ZTS1B"}
186 !2 = !{i64 16, !"_ZTS1C"}