Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -599,14 +599,15 @@ /// AddressSanitizer: instrument the code in module to find memory bugs. struct AddressSanitizer { - explicit AddressSanitizer(Module &M, DominatorTree *DT, - bool CompileKernel = false, bool Recover = false, + explicit AddressSanitizer(bool CompileKernel = false, bool Recover = false, bool UseAfterScope = false) - : UseAfterScope(UseAfterScope || ClUseAfterScope), DT(DT) { + : UseAfterScope(UseAfterScope || ClUseAfterScope) { this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover; this->CompileKernel = ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan : CompileKernel; + } + void doInitialization(Module &M) { // Initialize the private fields. No one has accessed them before. GlobalsMD.init(M); C = &(M.getContext()); @@ -616,6 +617,8 @@ Mapping = getShadowMapping(TargetTriple, LongSize, CompileKernel); } + void doFinalization(Module &M) { GlobalsMD.reset(); } + uint64_t getAllocaSizeInBytes(const AllocaInst &AI) const { uint64_t ArraySize = 1; if (AI.isArrayAllocation()) { @@ -665,8 +668,6 @@ /// Return true if the function changed. bool instrument(Function &F, const TargetLibraryInfo *TLI); - DominatorTree &getDominatorTree() const { return *DT; } - private: friend struct FunctionStackPoisoner; @@ -701,7 +702,6 @@ bool UseAfterScope; Type *IntptrTy; ShadowMapping Mapping; - DominatorTree *DT; Function *AsanHandleNoReturnFunc; Function *AsanPtrCmpFunction, *AsanPtrSubFunction; Constant *AsanShadowGlobal; @@ -1018,13 +1018,6 @@ // ---------------------- Helpers. void initializeCallbacks(Module &M); - bool doesDominateAllExits(const Instruction *I) const { - for (auto Ret : RetVec) { - if (!ASan.getDominatorTree().dominates(I, Ret)) return false; - } - return true; - } - /// Finds alloca where the value comes from. AllocaInst *findAllocaForValue(Value *V); @@ -1055,8 +1048,7 @@ explicit AddressSanitizerLegacyPass(bool CompileKernel = false, bool Recover = false, bool UseAfterScope = false) - : FunctionPass(ID), CompileKernel(CompileKernel), Recover(Recover), - UseAfterScope(UseAfterScope) { + : FunctionPass(ID), Sanitizer(CompileKernel, Recover, UseAfterScope) { initializeAddressSanitizerLegacyPassPass(*PassRegistry::getPassRegistry()); } @@ -1065,24 +1057,27 @@ } void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired(); AU.addRequired(); } + bool doInitialization(Module &M) override { + Sanitizer.doInitialization(M); + return true; + } + + bool doFinalization(Module &M) override { + Sanitizer.doFinalization(M); + return false; + } + bool runOnFunction(Function &F) override { - DominatorTree *DTree = - &getAnalysis().getDomTree(); const TargetLibraryInfo *TLI = &getAnalysis().getTLI(); - AddressSanitizer Sanitizer(*F.getParent(), DTree, CompileKernel, Recover, - UseAfterScope); return Sanitizer.instrument(F, TLI); } private: - bool CompileKernel; - bool Recover; - bool UseAfterScope; + AddressSanitizer Sanitizer; }; class AddressSanitizerModuleLegacyPass : public ModulePass { @@ -1117,13 +1112,14 @@ PreservedAnalyses AddressSanitizerPass::run(Function &F, AnalysisManager &AM) { - DominatorTree *DT = &AM.getResult(F); const TargetLibraryInfo *TLI = &AM.getResult(F); - AddressSanitizer Sanitizer(*F.getParent(), DT, CompileKernel, Recover, - UseAfterScope); - if (Sanitizer.instrument(F, TLI)) - return PreservedAnalyses::none(); - return PreservedAnalyses::all(); + AddressSanitizer Sanitizer(CompileKernel, Recover, UseAfterScope); + Sanitizer.doInitialization(*F.getParent()); + PreservedAnalyses Result = Sanitizer.instrument(F, TLI) + ? PreservedAnalyses::none() + : PreservedAnalyses::all(); + Sanitizer.doFinalization(*F.getParent()); + return Result; } PreservedAnalyses AddressSanitizerPass::run(Module &M, @@ -1140,7 +1136,6 @@ AddressSanitizerLegacyPass, "asan", "AddressSanitizer: detects use-after-free and out-of-bounds bugs.", false, false) -INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) INITIALIZE_PASS_END( AddressSanitizerLegacyPass, "asan",