[llvm-commits] [llvm] r58730 - in /llvm/trunk: lib/VMCore/PassManager.cpp tools/opt/opt.cpp

Nuno Lopes nunoplopes at sapo.pt
Tue Nov 4 15:03:59 PST 2008


Author: nlopes
Date: Tue Nov  4 17:03:58 2008
New Revision: 58730

URL: http://llvm.org/viewvc/llvm-project?rev=58730&view=rev
Log:
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

Modified:
    llvm/trunk/lib/VMCore/PassManager.cpp
    llvm/trunk/tools/opt/opt.cpp

Modified: llvm/trunk/lib/VMCore/PassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassManager.cpp?rev=58730&r1=58729&r2=58730&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/PassManager.cpp (original)
+++ llvm/trunk/lib/VMCore/PassManager.cpp Tue Nov  4 17:03:58 2008
@@ -458,8 +458,10 @@
   // 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);
 

Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=58730&r1=58729&r2=58730&view=diff

==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Tue Nov  4 17:03:58 2008
@@ -527,16 +527,21 @@
         cerr << argv[0] << ": cannot create pass: "
              << PassInf->getPassName() << "\n";
       if (P) {
+        bool isBBPass = dynamic_cast<BasicBlockPass*>(P) != 0;
+        bool isLPass = !isBBPass && dynamic_cast<LoopPass*>(P) != 0;
+        bool isFPass = !isLPass && dynamic_cast<FunctionPass*>(P) != 0;
+        bool isCGSCCPass = !isFPass && dynamic_cast<CallGraphSCCPass*>(P) != 0;
+
         addPass(Passes, P);
-        
+
         if (AnalyzeOnly) {
-          if (dynamic_cast<BasicBlockPass*>(P))
+          if (isBBPass)
             Passes.add(new BasicBlockPassPrinter(PassInf));
-          else if (dynamic_cast<LoopPass*>(P))
-            Passes.add(new  LoopPassPrinter(PassInf));
-          else if (dynamic_cast<FunctionPass*>(P))
+          else if (isLPass)
+            Passes.add(new LoopPassPrinter(PassInf));
+          else if (isFPass)
             Passes.add(new FunctionPassPrinter(PassInf));
-          else if (dynamic_cast<CallGraphSCCPass*>(P))
+          else if (isCGSCCPass)
             Passes.add(new CallGraphSCCPassPrinter(PassInf));
           else
             Passes.add(new ModulePassPrinter(PassInf));





More information about the llvm-commits mailing list