aboutsummaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorArthur Eubanks <aeubanks@google.com>2022-06-30 15:18:04 -0700
committerArthur Eubanks <aeubanks@google.com>2022-07-26 08:01:08 -0700
commit2eade1dba4a8d6e1c6867e9127bcd88cf4e55976 (patch)
tree080ccfec588a3231d14022bc922f5c05e9a11adb /lld
parente43621b09c9741d2e3a8a3d8ed216699af5ff8ba (diff)
downloadllvm-2eade1dba4a8d6e1c6867e9127bcd88cf4e55976.zip
llvm-2eade1dba4a8d6e1c6867e9127bcd88cf4e55976.tar.gz
llvm-2eade1dba4a8d6e1c6867e9127bcd88cf4e55976.tar.bz2
[WPD] Use new llvm.public.type.test intrinsic for potentially publicly visible classes
Turning on opaque pointers has uncovered an issue with WPD where we currently pattern match away `assume(type.test)` in WPD so that a later LTT doesn't resolve the type test to undef and introduce an `assume(false)`. The pattern matching can fail in cases where we transform two `assume(type.test)`s into `assume(phi(type.test.1, type.test.2))`. Currently we create `assume(type.test)` for all virtual calls that might be devirtualized. This is to support `-Wl,--lto-whole-program-visibility`. To prevent this, all virtual calls that may not be in the same LTO module instead use a new `llvm.public.type.test` intrinsic in place of the `llvm.type.test`. Then when we know if `-Wl,--lto-whole-program-visibility` is passed or not, we can either replace all `llvm.public.type.test` with `llvm.type.test`, or replace all `llvm.public.type.test` with `true`. This prevents WPD from trying to pattern match away `assume(type.test)` for public virtual calls when failing the pattern matching will result in miscompiles. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D128955
Diffstat (limited to 'lld')
-rw-r--r--lld/test/ELF/lto/update_public_type_test.ll27
1 files changed, 27 insertions, 0 deletions
diff --git a/lld/test/ELF/lto/update_public_type_test.ll b/lld/test/ELF/lto/update_public_type_test.ll
new file mode 100644
index 0000000..037e7b9
--- /dev/null
+++ b/lld/test/ELF/lto/update_public_type_test.ll
@@ -0,0 +1,27 @@
+; REQUIRES: x86
+
+; Check that we RAUW llvm.public.type.test with either llvm.type.test when --lto-whole-program-visibility is specified, or with true otherwise.
+
+; RUN: opt --thinlto-bc -o %t.o %s
+; RUN: ld.lld %t.o -o %t2.o --save-temps
+; RUN: llvm-dis %t.o.0.preopt.bc -o - | FileCheck %s --check-prefix=PUB
+; RUN: ld.lld %t.o -o %t3.o --save-temps --lto-whole-program-visibility
+; RUN: llvm-dis %t.o.0.preopt.bc -o - | FileCheck %s --check-prefix=WPV
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-grtev4-linux-gnu"
+
+declare i1 @llvm.public.type.test(ptr, metadata)
+declare void @llvm.assume(i1)
+
+; PUB-NOT: call {{.*}}@llvm.public.type.test
+; PUB-NOT: call {{.*}}@llvm.type.test
+; PUB: call {{.*}}@llvm.assume(i1 true)
+; WPV: call {{.*}}@llvm.type.test
+; WPV: call {{.*}}@llvm.assume
+
+define void @f(ptr %a) {
+ %i = call i1 @llvm.public.type.test(ptr %a, metadata !"_ZTS1A")
+ call void @llvm.assume(i1 %i)
+ ret void
+}