Author: Vitaly Buka Date: 2021-11-03T11:32:14-07:00 New Revision: 3131714f8daca338492a7d5b189e4d63131bc808
URL: https://github.com/llvm/llvm-project/commit/3131714f8daca338492a7d5b189e4d63131bc808 DIFF: https://github.com/llvm/llvm-project/commit/3131714f8daca338492a7d5b189e4d63131bc808.diff LOG: [NFC][asan] Use AddressSanitizerOptions in ModuleAddressSanitizerPass Reviewed By: kstoimenov Differential Revision: https://reviews.llvm.org/D113072 Added: Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h llvm/lib/Passes/PassRegistry.def llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp llvm/tools/opt/NewPMDriver.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 534d98be4344a..64f972fe11a52 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1176,20 +1176,20 @@ static void addSanitizers(const Triple &TargetTriple, auto ASanPass = [&](SanitizerMask Mask, bool CompileKernel) { if (LangOpts.Sanitize.has(Mask)) { - bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); - bool UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope; bool UseGlobalGC = asanUseGlobalsGC(TargetTriple, CodeGenOpts); bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator; llvm::AsanDtorKind DestructorKind = CodeGenOpts.getSanitizeAddressDtor(); - llvm::AsanDetectStackUseAfterReturnMode UseAfterReturn = - CodeGenOpts.getSanitizeAddressUseAfterReturn(); + AddressSanitizerOptions Opts; + Opts.CompileKernel = CompileKernel; + Opts.Recover = CodeGenOpts.SanitizeRecover.has(Mask); + Opts.UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope; + Opts.UseAfterReturn = CodeGenOpts.getSanitizeAddressUseAfterReturn(); MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>()); - MPM.addPass(ModuleAddressSanitizerPass(CompileKernel, Recover, - UseGlobalGC, UseOdrIndicator, - DestructorKind)); - MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass( - {CompileKernel, Recover, UseAfterScope, UseAfterReturn}))); + MPM.addPass(ModuleAddressSanitizerPass( + Opts, UseGlobalGC, UseOdrIndicator, DestructorKind)); + MPM.addPass( + createModuleToFunctionPassAdaptor(AddressSanitizerPass(Opts))); } }; ASanPass(SanitizerKind::Address, false); diff --git a/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h index ea18974798570..c13407a440913 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h @@ -106,7 +106,7 @@ struct AddressSanitizerOptions { /// surrounding requested memory to be checked for invalid accesses. class AddressSanitizerPass : public PassInfoMixin<AddressSanitizerPass> { public: - explicit AddressSanitizerPass(AddressSanitizerOptions Options) + AddressSanitizerPass(const AddressSanitizerOptions &Options) : Options(Options){}; PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); void printPipeline(raw_ostream &OS, @@ -125,8 +125,8 @@ class AddressSanitizerPass : public PassInfoMixin<AddressSanitizerPass> { class ModuleAddressSanitizerPass : public PassInfoMixin<ModuleAddressSanitizerPass> { public: - explicit ModuleAddressSanitizerPass( - bool CompileKernel = false, bool Recover = false, bool UseGlobalGC = true, + ModuleAddressSanitizerPass( + const AddressSanitizerOptions &Options, bool UseGlobalGC = true, bool UseOdrIndicator = false, AsanDtorKind DestructorKind = AsanDtorKind::Global); PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); @@ -135,8 +135,7 @@ class ModuleAddressSanitizerPass static bool isRequired() { return true; } private: - bool CompileKernel; - bool Recover; + AddressSanitizerOptions Options; bool UseGlobalGC; bool UseOdrIndicator; AsanDtorKind DestructorKind; diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 655c472878a00..80ec9f839fd25 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -138,12 +138,10 @@ MODULE_PASS_WITH_PARAMS("hwasan", "kernel;recover") MODULE_PASS_WITH_PARAMS("asan-module", "ModuleAddressSanitizerPass", - [](bool CompileKernel) { - return ModuleAddressSanitizerPass(CompileKernel, - false, true, - false); + [](AddressSanitizerOptions Opts) { + return ModuleAddressSanitizerPass(Opts); }, - parseModuleAddressSanitizerPassOptions, + parseASanPassOptions, "kernel") #undef MODULE_PASS_WITH_PARAMS diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 5563fc14d151b..beb252b763c13 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1288,23 +1288,23 @@ void ModuleAddressSanitizerPass::printPipeline( static_cast<PassInfoMixin<ModuleAddressSanitizerPass> *>(this)->printPipeline( OS, MapClassName2PassName); OS << "<"; - if (CompileKernel) + if (Options.CompileKernel) OS << "kernel"; OS << ">"; } ModuleAddressSanitizerPass::ModuleAddressSanitizerPass( - bool CompileKernel, bool Recover, bool UseGlobalGC, bool UseOdrIndicator, - AsanDtorKind DestructorKind) - : CompileKernel(CompileKernel), Recover(Recover), UseGlobalGC(UseGlobalGC), + const AddressSanitizerOptions &Options, bool UseGlobalGC, + bool UseOdrIndicator, AsanDtorKind DestructorKind) + : Options(Options), UseGlobalGC(UseGlobalGC), UseOdrIndicator(UseOdrIndicator), DestructorKind(DestructorKind) {} PreservedAnalyses ModuleAddressSanitizerPass::run(Module &M, AnalysisManager<Module> &AM) { GlobalsMetadata &GlobalsMD = AM.getResult<ASanGlobalsMetadataAnalysis>(M); - ModuleAddressSanitizer Sanitizer(M, &GlobalsMD, CompileKernel, Recover, - UseGlobalGC, UseOdrIndicator, - DestructorKind); + ModuleAddressSanitizer Sanitizer(M, &GlobalsMD, Options.CompileKernel, + Options.Recover, UseGlobalGC, + UseOdrIndicator, DestructorKind); if (Sanitizer.instrumentModule(M)) return PreservedAnalyses::none(); return PreservedAnalyses::all(); diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp index 794c01f31c11f..8093023451176 100644 --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -346,7 +346,7 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>()); MPM.addPass( createModuleToFunctionPassAdaptor(AddressSanitizerPass(Opts))); - MPM.addPass(ModuleAddressSanitizerPass()); + MPM.addPass(ModuleAddressSanitizerPass(Opts)); return true; } else if (Name == "asan-function-pipeline") { MPM.addPass( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits