From: Nuno Lopes Date: Tue, 4 Nov 2008 23:03:58 +0000 (+0000) Subject: fix memory leak in pass manager when adding an analysis pass that already existed... X-Git-Tag: android-x86-6.0-r1~1003^2~24880 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=641397f2ef0a155159e1085bf594c1535485e3a3;p=android-x86%2Fexternal-llvm.git fix memory leak in pass manager when adding an analysis pass that already existed. as pass manager takes ownership of the added passes, it has to delete the pass if it isnt added to the pass list tweak the opt tool so that it doesnt access a Pass after the ownership was taken by the pass manager git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58730 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index ef90aace3da..6f559c47c3f 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -458,8 +458,10 @@ void PMTopLevelManager::schedulePass(Pass *P) { // generate the analysis again. Stale analysis info should not be // available at this point. if (P->getPassInfo() && - P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo())) + P->getPassInfo()->isAnalysis() && findAnalysisPass(P->getPassInfo())) { + delete P; return; + } AnalysisUsage *AnUsage = findAnalysisUsage(P); diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index a339d316ea8..b0077eaf29d 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -527,16 +527,21 @@ int main(int argc, char **argv) { cerr << argv[0] << ": cannot create pass: " << PassInf->getPassName() << "\n"; if (P) { + bool isBBPass = dynamic_cast(P) != 0; + bool isLPass = !isBBPass && dynamic_cast(P) != 0; + bool isFPass = !isLPass && dynamic_cast(P) != 0; + bool isCGSCCPass = !isFPass && dynamic_cast(P) != 0; + addPass(Passes, P); - + if (AnalyzeOnly) { - if (dynamic_cast(P)) + if (isBBPass) Passes.add(new BasicBlockPassPrinter(PassInf)); - else if (dynamic_cast(P)) - Passes.add(new LoopPassPrinter(PassInf)); - else if (dynamic_cast(P)) + else if (isLPass) + Passes.add(new LoopPassPrinter(PassInf)); + else if (isFPass) Passes.add(new FunctionPassPrinter(PassInf)); - else if (dynamic_cast(P)) + else if (isCGSCCPass) Passes.add(new CallGraphSCCPassPrinter(PassInf)); else Passes.add(new ModulePassPrinter(PassInf));