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 @@ -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 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()], 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 @@ -31,7 +31,7 @@ // 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 -// FIX: %clang -O2 -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 --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 @@ -40,7 +40,7 @@ // 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 -// FIX: %clang -O2 -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 --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 @@ -50,3 +50,5 @@ // CHECK-NOT: = alloca // 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 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,6 +48,8 @@ TargetOptions Options; std::vector MAttrs; std::vector PassPlugins; + /// For adding passes that run by optimizer (NewPM only). + std::function OptimizerLastPassBuilderHook; /// For adding passes that run right before codegen. std::function PreCodeGenPassesHook; Optional RelocModel = Reloc::PIC_; 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 @@ -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)