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 @@ -1176,20 +1176,20 @@ 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()); - 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 --- a/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h @@ -106,7 +106,7 @@ /// surrounding requested memory to be checked for invalid accesses. class AddressSanitizerPass : public PassInfoMixin { 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 ModuleAddressSanitizerPass : public PassInfoMixin { 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 @@ 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 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -138,12 +138,10 @@ "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 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1288,23 +1288,23 @@ static_cast *>(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 &AM) { GlobalsMetadata &GlobalsMD = AM.getResult(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 --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -346,7 +346,7 @@ RequireAnalysisPass()); MPM.addPass( createModuleToFunctionPassAdaptor(AddressSanitizerPass(Opts))); - MPM.addPass(ModuleAddressSanitizerPass()); + MPM.addPass(ModuleAddressSanitizerPass(Opts)); return true; } else if (Name == "asan-function-pipeline") { MPM.addPass(