diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1063,6 +1063,16 @@ const LangOptions &LangOpts, PassBuilder &PB) { PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + if (CodeGenOpts.OptimizationLevel == 0) { + if (!CodeGenOpts.ThinLTOIndexFile.empty()) + llvm::report_fatal_error( + "Unexpected optimizer in non-optimized ThinLTO PostLink"); + } else { + if (CodeGenOpts.PrepareForThinLTO) + llvm::report_fatal_error( + "Unexpected optimizer in optimized ThinLTO PreLink"); + } + if (CodeGenOpts.SanitizeCoverageType || CodeGenOpts.SanitizeCoverageIndirectCalls || CodeGenOpts.SanitizeCoverageTraceCmp) { @@ -1313,7 +1323,12 @@ FPM.addPass(BoundsCheckingPass()); }); - addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB); + if (CodeGenOpts.OptimizationLevel != 0 || + CodeGenOpts.ThinLTOIndexFile.empty()) { + // This is testing distributed ThinLTO PostLink. O0 called optimized in + // PreLink. + addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB); + } if (Optional Options = getGCOVOptions(CodeGenOpts, LangOpts)) PB.registerPipelineStartEPCallback( @@ -1522,6 +1537,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()], diff --git a/clang/test/CodeGen/thinlto-distributed-sanitizers.ll b/clang/test/CodeGen/thinlto-distributed-sanitizers.ll new file mode 100644 --- /dev/null +++ b/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 +} diff --git a/clang/test/Driver/asan.c b/clang/test/Driver/asan.c --- a/clang/test/Driver/asan.c +++ b/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 diff --git a/clang/test/Driver/dfsan.c b/clang/test/Driver/dfsan.c --- a/clang/test/Driver/dfsan.c +++ b/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 diff --git a/clang/test/Driver/msan.c b/clang/test/Driver/msan.c --- a/clang/test/Driver/msan.c +++ b/clang/test/Driver/msan.c @@ -1,49 +1,50 @@ // 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 -// 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 -// 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 -// 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 -// 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 -// 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 -// 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 -// 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 +// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s +// 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 +// 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 +// 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=CHECK -// 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 -// 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 -// 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 -// 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 -// 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 -// 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 -// 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 +// RUN: %clang -fno-experimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s +// 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 +// 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 +// 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=CHECK -// RUN: %clang -target mips64el-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK -// RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK -// RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK +// RUN: %clang -target mips64-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s +// RUN: %clang -target mips64el-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s +// RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s +// RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s // 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 -// RUN: %clang -O1 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK -// RUN: %clang -O2 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK -// RUN: %clang -O3 -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK -// 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 -// 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 -// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -flto -o - | FileCheck %s --check-prefixes=CHECK -// 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 +// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s +// 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 +// 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 +// 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=CHECK -// 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 -// 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 -// 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 -// 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 -// 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 -// 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 -// 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 +// RUN: %clang -fexperimental-new-pass-manager -target x86_64-unknown-linux -fsanitize=kernel-memory %s -S -emit-llvm -o - | FileCheck %s +// 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 +// 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 +// 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; } // CHECK: @__msan_ +// NOMSAN-NOT: __msan diff --git a/clang/test/Driver/sancov.c b/clang/test/Driver/sancov.c --- a/clang/test/Driver/sancov.c +++ b/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 \ No newline at end of file diff --git a/clang/test/Driver/tsan.c b/clang/test/Driver/tsan.c --- a/clang/test/Driver/tsan.c +++ b/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 diff --git a/llvm/include/llvm/LTO/Config.h b/llvm/include/llvm/LTO/Config.h --- a/llvm/include/llvm/LTO/Config.h +++ b/llvm/include/llvm/LTO/Config.h @@ -48,7 +48,9 @@ TargetOptions Options; std::vector MAttrs; std::vector PassPlugins; - /// For adding passes that run right before codegen. + /// For adding passes that run by optimizer. + std::function OptimizerLastPassBuilderHook; + /// For adding passes that run right before codegen (NewPM only). std::function PreCodeGenPassesHook; Optional RelocModel = Reloc::PIC_; Optional CodeModel = None; diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -253,6 +253,9 @@ PB.registerLoopAnalyses(LAM); PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); + if (Conf.OptimizerLastPassBuilderHook) + Conf.OptimizerLastPassBuilderHook(PB); + ModulePassManager MPM(Conf.DebugPassManager); if (!Conf.DisableVerify)