kstoimenov updated this revision to Diff 383819. kstoimenov added a comment.
Fixed remaing 2 tests. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112732/new/ https://reviews.llvm.org/D112732 Files: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h llvm/lib/Passes/PassBuilder.cpp llvm/lib/Passes/PassRegistry.def llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll llvm/test/Other/new-pm-print-pipeline.ll llvm/tools/opt/NewPMDriver.cpp
Index: llvm/tools/opt/NewPMDriver.cpp =================================================================== --- llvm/tools/opt/NewPMDriver.cpp +++ llvm/tools/opt/NewPMDriver.cpp @@ -340,19 +340,16 @@ PB.registerPipelineParsingCallback( [](StringRef Name, ModulePassManager &MPM, ArrayRef<PassBuilder::PipelineElement>) { - AddressSanitizerOptions Opts; if (Name == "asan-pipeline") { MPM.addPass( RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>()); - MPM.addPass( - createModuleToFunctionPassAdaptor(AddressSanitizerPass(Opts))); MPM.addPass(ModuleAddressSanitizerPass()); return true; } else if (Name == "asan-function-pipeline") { + // FIXME: now this is the same as asan-pipeline and can me removed. MPM.addPass( RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>()); - MPM.addPass( - createModuleToFunctionPassAdaptor(AddressSanitizerPass(Opts))); + MPM.addPass(ModuleAddressSanitizerPass()); return true; } return false; Index: llvm/test/Other/new-pm-print-pipeline.ll =================================================================== --- llvm/test/Other/new-pm-print-pipeline.ll +++ llvm/test/Other/new-pm-print-pipeline.ll @@ -46,8 +46,8 @@ ; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='module(hwasan<>,hwasan<kernel;recover>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-14 ; CHECK-14: hwasan<>,hwasan<kernel;recover> -; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(asan<>,asan<kernel>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-15 -; CHECK-15: function(asan<>,asan<kernel>) +; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='module(asan-module<>,asan-module<kernel>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-15 +; CHECK-15: asan-module<>,asan-module<kernel> ; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='module(loop-extract<>,loop-extract<single>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-16 ; CHECK-16: loop-extract<>,loop-extract<single> Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll =================================================================== --- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll +++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll @@ -2,7 +2,7 @@ ; Make sure asan does not instrument __sancov_gen_ ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard -S | FileCheck %s -; RUN: opt < %s -passes='module(require<asan-globals-md>,sancov-module,asan-module),function(asan)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard -S | FileCheck %s +; RUN: opt < %s -passes='module(require<asan-globals-md>,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard -S | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" $Foo = comdat any Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1254,35 +1254,6 @@ return GlobalsMetadata(M); } -PreservedAnalyses AddressSanitizerPass::run(Function &F, - AnalysisManager<Function> &AM) { - auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F); - Module &M = *F.getParent(); - if (auto *R = MAMProxy.getCachedResult<ASanGlobalsMetadataAnalysis>(M)) { - const TargetLibraryInfo *TLI = &AM.getResult<TargetLibraryAnalysis>(F); - AddressSanitizer Sanitizer(M, R, Options.CompileKernel, Options.Recover, - Options.UseAfterScope, Options.UseAfterReturn); - if (Sanitizer.instrumentFunction(F, TLI)) - return PreservedAnalyses::none(); - return PreservedAnalyses::all(); - } - - report_fatal_error( - "The ASanGlobalsMetadataAnalysis is required to run before " - "AddressSanitizer can run"); - return PreservedAnalyses::all(); -} - -void AddressSanitizerPass::printPipeline( - raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) { - static_cast<PassInfoMixin<AddressSanitizerPass> *>(this)->printPipeline( - OS, MapClassName2PassName); - OS << "<"; - if (Options.CompileKernel) - OS << "kernel"; - OS << ">"; -} - void ModuleAddressSanitizerPass::printPipeline( raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) { static_cast<PassInfoMixin<ModuleAddressSanitizerPass> *>(this)->printPipeline( @@ -1295,17 +1266,28 @@ ModuleAddressSanitizerPass::ModuleAddressSanitizerPass( bool CompileKernel, bool Recover, bool UseGlobalGC, bool UseOdrIndicator, - AsanDtorKind DestructorKind) + AsanDtorKind DestructorKind, bool UseAfterScope, + AsanDetectStackUseAfterReturnMode UseAfterReturn) : CompileKernel(CompileKernel), Recover(Recover), UseGlobalGC(UseGlobalGC), - UseOdrIndicator(UseOdrIndicator), DestructorKind(DestructorKind) {} + UseOdrIndicator(UseOdrIndicator), DestructorKind(DestructorKind), + UseAfterScope(UseAfterScope), UseAfterReturn(UseAfterReturn) {} PreservedAnalyses ModuleAddressSanitizerPass::run(Module &M, - AnalysisManager<Module> &AM) { - GlobalsMetadata &GlobalsMD = AM.getResult<ASanGlobalsMetadataAnalysis>(M); - ModuleAddressSanitizer Sanitizer(M, &GlobalsMD, CompileKernel, Recover, - UseGlobalGC, UseOdrIndicator, - DestructorKind); - if (Sanitizer.instrumentModule(M)) + ModuleAnalysisManager &MAM) { + GlobalsMetadata &GlobalsMD = MAM.getResult<ASanGlobalsMetadataAnalysis>(M); + ModuleAddressSanitizer ModuleSanitizer(M, &GlobalsMD, CompileKernel, Recover, + UseGlobalGC, UseOdrIndicator, + DestructorKind); + bool Modified = false; + auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); + for (Function &F : M) { + AddressSanitizer FunctionSanitizer(M, &GlobalsMD, CompileKernel, Recover, + UseAfterScope, UseAfterReturn); + const TargetLibraryInfo &TLI = FAM.getResult<TargetLibraryAnalysis>(F); + Modified |= FunctionSanitizer.instrumentFunction(F, &TLI); + } + Modified |= ModuleSanitizer.instrumentModule(M); + if (Modified) return PreservedAnalyses::none(); return PreservedAnalyses::all(); } @@ -2844,6 +2826,7 @@ if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) return false; if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return false; if (F.getName().startswith("__asan_")) return false; + if (F.empty()) return false; bool FunctionModified = false; Index: llvm/lib/Passes/PassRegistry.def =================================================================== --- llvm/lib/Passes/PassRegistry.def +++ llvm/lib/Passes/PassRegistry.def @@ -393,13 +393,6 @@ "no-profile-peeling;profile-peeling;" "no-runtime;runtime;" "no-upperbound;upperbound") -FUNCTION_PASS_WITH_PARAMS("asan", - "AddressSanitizerPass", - [](AddressSanitizerOptions Opts) { - return AddressSanitizerPass(Opts); - }, - parseASanPassOptions, - "kernel") FUNCTION_PASS_WITH_PARAMS("msan", "MemorySanitizerPass", [](MemorySanitizerOptions Opts) { Index: llvm/lib/Passes/PassBuilder.cpp =================================================================== --- llvm/lib/Passes/PassBuilder.cpp +++ llvm/lib/Passes/PassBuilder.cpp @@ -584,24 +584,6 @@ return parseSinglePassOption(Params, "kernel", "ModuleAddressSanitizer"); } -Expected<AddressSanitizerOptions> parseASanPassOptions(StringRef Params) { - AddressSanitizerOptions Result; - while (!Params.empty()) { - StringRef ParamName; - std::tie(ParamName, Params) = Params.split(';'); - - if (ParamName == "kernel") { - Result.CompileKernel = true; - } else { - return make_error<StringError>( - formatv("invalid AddressSanitizer pass parameter '{0}' ", ParamName) - .str(), - inconvertibleErrorCode()); - } - } - return Result; -} - Expected<HWAddressSanitizerOptions> parseHWASanPassOptions(StringRef Params) { HWAddressSanitizerOptions Result; while (!Params.empty()) { Index: llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h =================================================================== --- llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h +++ llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h @@ -89,40 +89,6 @@ static AnalysisKey Key; }; -struct AddressSanitizerOptions { - AddressSanitizerOptions() - : AddressSanitizerOptions(false, false, false, - AsanDetectStackUseAfterReturnMode::Runtime){}; - AddressSanitizerOptions(bool CompileKernel, bool Recover, bool UseAfterScope, - AsanDetectStackUseAfterReturnMode UseAfterReturn) - : CompileKernel(CompileKernel), Recover(Recover), - UseAfterScope(UseAfterScope), UseAfterReturn(UseAfterReturn){}; - bool CompileKernel; - bool Recover; - bool UseAfterScope; - AsanDetectStackUseAfterReturnMode UseAfterReturn; -}; - -/// Public interface to the address sanitizer pass for instrumenting code to -/// check for various memory errors at runtime. -/// -/// The sanitizer itself is a function pass that works by inserting various -/// calls to the ASan runtime library functions. The runtime library essentially -/// replaces malloc() and free() with custom implementations that allow regions -/// surrounding requested memory to be checked for invalid accesses. -class AddressSanitizerPass : public PassInfoMixin<AddressSanitizerPass> { -public: - explicit AddressSanitizerPass(AddressSanitizerOptions Options) - : Options(Options){}; - PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); - void printPipeline(raw_ostream &OS, - function_ref<StringRef(StringRef)> MapClassName2PassName); - static bool isRequired() { return true; } - -private: - AddressSanitizerOptions Options; -}; - /// Public interface to the address sanitizer module pass for instrumenting code /// to check for various memory errors. /// @@ -132,9 +98,12 @@ : public PassInfoMixin<ModuleAddressSanitizerPass> { public: explicit ModuleAddressSanitizerPass( - bool CompileKernel = false, bool Recover = false, bool UseGlobalGC = true, - bool UseOdrIndicator = false, - AsanDtorKind DestructorKind = AsanDtorKind::Global); + bool CompileKernel = false, bool Recover = false, + bool UseGlobalGC = true, bool UseOdrIndicator = false, + AsanDtorKind DestructorKind = AsanDtorKind::Global, + bool UseAfterScope = false, + AsanDetectStackUseAfterReturnMode UseAfterReturn = + AsanDetectStackUseAfterReturnMode::Runtime); PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); void printPipeline(raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName); @@ -146,6 +115,8 @@ bool UseGlobalGC; bool UseOdrIndicator; AsanDtorKind DestructorKind; + bool UseAfterScope; + AsanDetectStackUseAfterReturnMode UseAfterReturn; }; // Insert AddressSanitizer (address sanity checking) instrumentation Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -1187,9 +1187,7 @@ MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>()); MPM.addPass(ModuleAddressSanitizerPass( CompileKernel, Recover, ModuleUseAfterScope, UseOdrIndicator, - DestructorKind)); - MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass( - {CompileKernel, Recover, UseAfterScope, UseAfterReturn}))); + DestructorKind, UseAfterScope, UseAfterReturn)); } }; ASanPass(SanitizerKind::Address, false);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits