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 @@ -1265,7 +1265,6 @@ // Register callbacks to schedule sanitizer passes at the appropriate part of // the pipeline. - // FIXME: either handle asan/the remaining sanitizers or error out if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) PB.registerScalarOptimizerLateEPCallback( [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { @@ -1288,48 +1287,38 @@ if (LangOpts.Sanitize.has(SanitizerKind::Memory)) { int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins; bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::Memory); - PB.registerPipelineStartEPCallback( - [TrackOrigins, Recover](ModulePassManager &MPM) { - MPM.addPass(MemorySanitizerPass({TrackOrigins, Recover, false})); - }); PB.registerOptimizerLastEPCallback( [TrackOrigins, Recover](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + MPM.addPass(MemorySanitizerPass({TrackOrigins, Recover, false})); MPM.addPass(createModuleToFunctionPassAdaptor( MemorySanitizerPass({TrackOrigins, Recover, false}))); }); } if (LangOpts.Sanitize.has(SanitizerKind::Thread)) { - PB.registerPipelineStartEPCallback( - [](ModulePassManager &MPM) { MPM.addPass(ThreadSanitizerPass()); }); PB.registerOptimizerLastEPCallback( [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + MPM.addPass(ThreadSanitizerPass()); MPM.addPass( createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); }); } if (LangOpts.Sanitize.has(SanitizerKind::Address)) { - PB.registerPipelineStartEPCallback([&](ModulePassManager &MPM) { - MPM.addPass( - RequireAnalysisPass()); - }); bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::Address); bool UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope; - PB.registerOptimizerLastEPCallback( - [Recover, UseAfterScope](ModulePassManager &MPM, - PassBuilder::OptimizationLevel Level) { - MPM.addPass( - createModuleToFunctionPassAdaptor(AddressSanitizerPass( - /*CompileKernel=*/false, Recover, UseAfterScope))); - }); bool ModuleUseAfterScope = asanUseGlobalsGC(TargetTriple, CodeGenOpts); bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator; - PB.registerPipelineStartEPCallback( - [Recover, ModuleUseAfterScope, - UseOdrIndicator](ModulePassManager &MPM) { + PB.registerOptimizerLastEPCallback( + [Recover, UseAfterScope, ModuleUseAfterScope, UseOdrIndicator]( + ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + MPM.addPass( + RequireAnalysisPass()); MPM.addPass(ModuleAddressSanitizerPass( /*CompileKernel=*/false, Recover, ModuleUseAfterScope, UseOdrIndicator)); + MPM.addPass( + createModuleToFunctionPassAdaptor(AddressSanitizerPass( + /*CompileKernel=*/false, Recover, UseAfterScope))); }); } if (Optional Options = getGCOVOptions(CodeGenOpts)) diff --git a/clang/test/CodeGen/asan-new-pm.ll b/clang/test/CodeGen/asan-new-pm.ll --- a/clang/test/CodeGen/asan-new-pm.ll +++ b/clang/test/CodeGen/asan-new-pm.ll @@ -1,12 +1,8 @@ ; Test that ASan runs with the new pass manager -; RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - -fexperimental-new-pass-manager -fsanitize=address %s | FileCheck %s --check-prefixes=CHECK,LTO,THINLTO -; RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - -fexperimental-new-pass-manager -fsanitize=address -flto %s | FileCheck %s --check-prefixes=CHECK,LTO -; RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - -fexperimental-new-pass-manager -fsanitize=address -flto=thin %s | FileCheck %s --check-prefixes=CHECK,THINLTO -; RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - -O1 -fexperimental-new-pass-manager -fsanitize=address %s | FileCheck %s --check-prefixes=CHECK,LTO,THINLTO -; RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - -O1 -fexperimental-new-pass-manager -fsanitize=address -flto %s | FileCheck %s --check-prefixes=CHECK,LTO -; RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - -O1 -fexperimental-new-pass-manager -fsanitize=address -flto=thin %s | FileCheck %s --check-prefixes=CHECK,THINLTO +; RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - -fexperimental-new-pass-manager -fsanitize=address %s | FileCheck %s +; RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - -O1 -fexperimental-new-pass-manager -fsanitize=address %s | FileCheck %s -; DAG-CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor +; CHECK-DAG: @llvm.global_ctors = {{.*}}@asan.module_ctor define i32 @test_load(i32* %a) sanitize_address { entry: @@ -16,13 +12,11 @@ ; CHECK: __asan_init -; DAG-CHECK: define internal void @asan.module_ctor() { +; CHECK-DAG: define internal void @asan.module_ctor() { ; CHECK: {{.*}} call void @__asan_init() ; CHECK: {{.*}} call void @__asan_version_mismatch_check_v8() ; CHECK: ret void ; CHECK: } -; DAG-CHECK: __asan_version_mismatch_check_v8 +; CHECK-DAG: __asan_version_mismatch_check_v8 -; This is not used in ThinLTO -; DAG-LTO: __asan_report_load4 diff --git a/clang/test/CodeGen/sanitizer-module-constructor.c b/clang/test/CodeGen/sanitizer-module-constructor.c --- a/clang/test/CodeGen/sanitizer-module-constructor.c +++ b/clang/test/CodeGen/sanitizer-module-constructor.c @@ -19,4 +19,3 @@ // CHECK: Running pass: {{.*}}SanitizerPass on {{.*}}sanitizer-module-constructor.c // CHECK-NOT: Running pass: LoopSimplifyPass on {{.*}}san.module_ctor // CHECK: Running analysis: DominatorTreeAnalysis on {{.*}}san.module_ctor -// CHECK: Running pass: LoopSimplifyPass on {{.*}}san.module_ctor