vitalybuka updated this revision to Diff 324528.
vitalybuka added a comment.
rebase
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96456/new/
https://reviews.llvm.org/D96456
Files:
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/thinlto-distributed-sanitizers.ll
clang/test/Driver/asan.c
clang/test/Driver/dfsan.c
clang/test/Driver/msan.c
clang/test/Driver/sancov.c
clang/test/Driver/tsan.c
llvm/include/llvm/LTO/Config.h
llvm/lib/LTO/LTOBackend.cpp
Index: llvm/lib/LTO/LTOBackend.cpp
===================================================================
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -258,6 +258,9 @@
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
+ if (Conf.OptimizerLastPassBuilderHook)
+ Conf.OptimizerLastPassBuilderHook(PB);
+
ModulePassManager MPM(Conf.DebugPassManager);
if (!Conf.DisableVerify)
Index: llvm/include/llvm/LTO/Config.h
===================================================================
--- llvm/include/llvm/LTO/Config.h
+++ llvm/include/llvm/LTO/Config.h
@@ -48,6 +48,8 @@
TargetOptions Options;
std::vector<std::string> MAttrs;
std::vector<std::string> PassPlugins;
+ /// For adding passes that run by optimizer (NewPM only).
+ std::function<void(PassBuilder &)> OptimizerLastPassBuilderHook;
/// For adding passes that run right before codegen.
std::function<void(legacy::PassManager &)> PreCodeGenPassesHook;
Optional<Reloc::Model> RelocModel = Reloc::PIC_;
Index: clang/test/Driver/tsan.c
===================================================================
--- clang/test/Driver/tsan.c
+++ clang/test/Driver/tsan.c
@@ -19,9 +19,10 @@
// RUN: %clang -O3 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -o - | FileCheck %s
// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -flto=thin -o - | FileCheck %s
-// FIX: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -flto=thin -o - | FileCheck %s
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=NOTSAN
// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -flto -o - | FileCheck %s
// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=thread %s -S -emit-llvm -flto -o - | FileCheck %s
int foo(int *a) { return *a; }
// CHECK: __tsan_init
+// NOTSAN-NOT: __tsan
Index: clang/test/Driver/sancov.c
===================================================================
--- clang/test/Driver/sancov.c
+++ clang/test/Driver/sancov.c
@@ -3,7 +3,7 @@
// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize-coverage=trace-pc-guard %s -S -emit-llvm -o - | FileCheck %s
// RUN: %clang -O3 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize-coverage=trace-pc-guard %s -S -emit-llvm -o - | FileCheck %s
// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize-coverage=trace-pc-guard %s -S -emit-llvm -flto=thin -o - | FileCheck %s
-// FIX: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize-coverage=trace-pc-guard %s -S -emit-llvm -flto=thin -o - | FileCheck %s
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize-coverage=trace-pc-guard %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=NOSANCOV
// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize-coverage=trace-pc-guard %s -S -emit-llvm -flto -o - | FileCheck %s
// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize-coverage=trace-pc-guard %s -S -emit-llvm -flto -o - | FileCheck %s
@@ -20,3 +20,4 @@
int foo(int *a) { return *a; }
// CHECK: _sancov_
+// NOSANCOV-NOT: _sancov
Index: clang/test/Driver/msan.c
===================================================================
--- clang/test/Driver/msan.c
+++ clang/test/Driver/msan.c
@@ -1,51 +1,54 @@
// REQUIRES: x86-registered-target
-// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O1 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -O3 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK,O1
-
-// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O1 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -O3 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK,O1
-
-// RUN: %clang -target mips64-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -target mips64el-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O0
+// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O1 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O3 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s
+// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto -o - | FileCheck %s
+
+// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O1 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O3 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s
+// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O2 -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto -o - | FileCheck %s
+
+// RUN: %clang -target mips64-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -target mips64el-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK0
// Verify that -fsanitize=memory and -fsanitize=kernel-memory invoke MSan/KMSAN instrumentation.
-// Also check that this works with the new pass manager with and without
-// optimization
-// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O1 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -O3 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK,O0
-// FIX: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK,O1
-
-// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O1 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -O3 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK,O0
-// FIX: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK,O1
-// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK,O0
-// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK,O1
+// Also check that this works with the new pass manager with and without optimization
+// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O1 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O3 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=NOMSAN
+// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto -o - | FileCheck %s
+
+// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O1 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O3 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=NOMSAN
+// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK0
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -flto -o - | FileCheck %s
int foo(int *a) { return *a; }
-// O0: = alloca
-// O1-NOT: = alloca
+// CHECK0: = alloca
+// CHECK0: @__msan_
+
+// CHECK-NOT: = alloca
// CHECK: @__msan_
+
+// NOMSAN-NOT: __msan
Index: clang/test/Driver/dfsan.c
===================================================================
--- clang/test/Driver/dfsan.c
+++ clang/test/Driver/dfsan.c
@@ -3,7 +3,7 @@
// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=dataflow %s -S -emit-llvm -o - | FileCheck %s
// RUN: %clang -O3 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=dataflow %s -S -emit-llvm -o - | FileCheck %s
// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=dataflow %s -S -emit-llvm -flto=thin -o - | FileCheck %s
-// FIX: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=dataflow %s -S -emit-llvm -flto=thin -o - | FileCheck %s
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=dataflow %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefixes=NODFSAN
// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=dataflow %s -S -emit-llvm -flto -o - | FileCheck %s
// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=dataflow %s -S -emit-llvm -flto -o - | FileCheck %s
@@ -20,3 +20,4 @@
int foo(int *a) { return *a; }
// CHECK: __dfsan
+// NODFSAN-NOT: __dfsan
Index: clang/test/Driver/asan.c
===================================================================
--- clang/test/Driver/asan.c
+++ clang/test/Driver/asan.c
@@ -3,7 +3,7 @@
// RUN: %clang -O2 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=address %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-ASAN
// RUN: %clang -O3 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=address %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-ASAN
// RUN: %clang -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=address %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-ASAN
-// FIX: %clang -O2 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=address %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-ASAN
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=address %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-NOASAN
// RUN: %clang -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=address %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-ASAN
// RUN: %clang -O2 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=address %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-ASAN
@@ -21,7 +21,7 @@
// RUN: %clang -O2 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=kernel-address %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-KASAN
// RUN: %clang -O3 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=kernel-address %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-KASAN
// RUN: %clang -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=kernel-address %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-KASAN
-// FIX: %clang -O2 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=kernel-address %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-KASAN
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=kernel-address %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-NOASAN
// RUN: %clang -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=kernel-address %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-KASAN
// RUN: %clang -O2 -fexperimental-new-pass-manager -target i386-unknown-linux -fsanitize=kernel-address %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-KASAN
@@ -39,7 +39,7 @@
// RUN: %clang -O2 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=hwaddress %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-HWASAN
// RUN: %clang -O3 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=hwaddress %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-HWASAN
// RUN: %clang -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=hwaddress %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-HWASAN
-// FIX: %clang -O2 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=hwaddress %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-HWASAN
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=hwaddress %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-NOHWASAN
// RUN: %clang -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=hwaddress %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-HWASAN
// RUN: %clang -O2 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=hwaddress %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-HWASAN
@@ -57,7 +57,7 @@
// RUN: %clang -O2 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
// RUN: %clang -O3 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
// RUN: %clang -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
-// FIX: %clang -O2 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
+// RUN: %clang -O2 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-NOHWASAN
// RUN: %clang -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
// RUN: %clang -O2 -fexperimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
@@ -68,7 +68,7 @@
// RUN: %clang -fno-experimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
// RUN: %clang -O2 -fno-experimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto=thin -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
// RUN: %clang -fno-experimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
-// FIX: %clang -O2 -fno-experimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
+// RUN: %clang -O2 -fno-experimental-new-pass-manager -target aarch64-unknown-linux -fsanitize=kernel-hwaddress %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefix=CHECK-KHWASAN
// Verify that -fsanitize={address,hwaddres,kernel-address,kernel-hwaddress} invokes ASan, HWAsan, KASan or KHWASan instrumentation.
int foo(int *a) { return *a; }
@@ -76,3 +76,6 @@
// CHECK-KASAN: __asan_{{.*}}load4_noabort
// CHECK-HWASAN: __hwasan_init
// CHECK-KHWASAN: __hwasan_tls
+
+// CHECK-NOASAN-NOT: __asan
+// CHECK-NOHWASAN-NOT: __asan
Index: clang/test/CodeGen/thinlto-distributed-sanitizers.ll
===================================================================
--- /dev/null
+++ clang/test/CodeGen/thinlto-distributed-sanitizers.ll
@@ -0,0 +1,164 @@
+; REQUIRES: x86-registered-target
+
+; Validate ThinLTO post link pipeline with sanitizers
+
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+; RUN: -o %t2.index \
+; RUN: -r=%t.o,main,px
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=address \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,ASAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=address \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,ASAN2 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=address \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,ASAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=address \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,ASAN2 %s
+
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=memory \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,MSAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=memory \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,MSAN2 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=memory \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,MSAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=memory \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,MSAN2 %s
+
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=thread \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,TSAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=thread \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,TSAN2 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=thread \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,TSAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=thread \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,TSAN2 %s
+
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=hwaddress \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,HWASAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=hwaddress \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,HWASAN2 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=hwaddress \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,HWASAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=hwaddress \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,HWASAN2 %s
+
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=dataflow \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,DFSAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=dataflow \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,DFSAN2 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=dataflow \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,DFSAN0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize=dataflow \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,DFSAN2 %s
+
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize-coverage=trace-pc-guard \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,SANCOV0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize-coverage=trace-pc-guard \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,SANCOV2 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize-coverage=trace-pc-guard \
+; RUN: -O0 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,SANCOV0 %s
+
+; RUN: %clang -target x86_64-grtev4-linux-gnu -fsanitize-coverage=trace-pc-guard \
+; RUN: -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
+; RUN: -c -fthinlto-index=/dev/null \
+; RUN: -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefixes=CHECK,SANCOV2 %s
+
+
+; CHECK: Starting llvm::Module pass manager
+; ASAN0-NOT: MemorySanitizer
+; MSAN0-NOT: AddressSanitizer
+; TSAN0-NOT: ThreadSanitizer
+; HWASAN0-NOT: HWAddressSanitizer
+; DFSAN0-NOT: DataFlowSanitizer
+; SANCOV0-NOT: SanitizerCoverage
+
+; ASAN2: Running analysis: ASanGlobalsMetadataAnalysis on {{.*}}.o
+; ASAN2: Running pass: ModuleAddressSanitizerPass on {{.*}}.o
+; ASAN2: Running pass: AddressSanitizerPass on main
+; MSAN2: Running pass: MemorySanitizerPass on {{.*}}.o
+; MSAN2: Running pass: MemorySanitizerPass on main
+; TSAN2: Running pass: ThreadSanitizerPass on {{.*}}.o
+; TSAN2: Running pass: ThreadSanitizerPass on main
+; HWASAN2: Running pass: HWAddressSanitizerPass on {{.*}}.o
+; DFSAN2: Running pass: DataFlowSanitizerPass on {{.*}}.o
+; SANCOV2: Running pass: ModuleSanitizerCoveragePass on {{.*}}.o
+
+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"
+
+define i32 @main() {
+ br label %b
+b:
+ br label %b
+ ret i32 0
+}
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1064,6 +1064,28 @@
const LangOptions &LangOpts, PassBuilder &PB) {
PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM,
PassBuilder::OptimizationLevel Level) {
+ if (CodeGenOpts.OptimizationLevel == 0) {
+ if (!CodeGenOpts.ThinLTOIndexFile.empty()) {
+ // ThinLTOIndexFile is provided so we must be in ThinLTO PostLink.
+ // For -O0 ThinLTO PreLink does basic optimization and triggers
+ // OptimizerLastEPCallbacks. PostLink will not run optimizations and
+ // this callback should not be called. See
+ // PassBuilder::buildThinLTODefaultPipeline.
+ llvm::report_fatal_error(
+ "Unexpected optimizer in non-optimized ThinLTO PostLink");
+ }
+ } else {
+ if (CodeGenOpts.PrepareForThinLTO &&
+ CodeGenOpts.ThinLTOIndexFile.empty()) {
+ // We are here if we in ThinLTO PreLink.
+ // For -O1 and above ThinLTO PreLink does no optimizations and does not
+ // trigger OptimizerLastEPCallbacks. See
+ // PassBuilder::buildThinLTOPreLinkDefaultPipeline.
+ llvm::report_fatal_error(
+ "Unexpected optimizer in optimized ThinLTO PreLink");
+ }
+ }
+
if (CodeGenOpts.SanitizeCoverageType ||
CodeGenOpts.SanitizeCoverageIndirectCalls ||
CodeGenOpts.SanitizeCoverageTraceCmp) {
@@ -1301,10 +1323,11 @@
// If we reached here with a non-empty index file name, then the index
// file was empty and we are not performing ThinLTO backend compilation
- // (used in testing in a distributed build environment). Drop any the type
- // test assume sequences inserted for whole program vtables so that
- // codegen doesn't complain.
- if (!CodeGenOpts.ThinLTOIndexFile.empty())
+ // (used in testing in a distributed build environment).
+ bool SkipThinLTOPostLink = !CodeGenOpts.ThinLTOIndexFile.empty();
+ // If so drop any the type test assume sequences inserted for whole program
+ // vtables so that codegen doesn't complain.
+ if (SkipThinLTOPostLink)
PB.registerPipelineStartEPCallback(
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
@@ -1328,7 +1351,16 @@
FPM.addPass(BoundsCheckingPass());
});
- addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB);
+ if (SkipThinLTOPostLink && CodeGenOpts.OptimizationLevel == 0) {
+ // If this is -O0 and the special case of ThinLTO OptimizerLastEPCallbacks
+ // will be called twice: from buildO0DefaultPipeline in ThinLTO PreLink
+ // and from the following buildO0DefaultPipeline here.
+ // We can't allow instrumenting the module twice and skip the second one.
+ } else {
+ // For anything else we assume OptimizerLastEPCallbacks will be called
+ // once per module and we will register sanitizers there.
+ addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB);
+ }
if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts, LangOpts))
PB.registerPipelineStartEPCallback(
@@ -1537,6 +1569,10 @@
Conf.CGFileType = getCodeGenFileType(Action);
break;
}
+ Triple TargetTriple(M->getTargetTriple());
+ Conf.OptimizerLastPassBuilderHook = [&](PassBuilder &PB) {
+ addSanitizers(TargetTriple, CGOpts, LOpts, PB);
+ };
if (Error E =
thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits