[cfe-commits] r77648 - in /cfe/trunk: include/clang/Analysis/PathSensitive/AnalysisManager.h lib/Frontend/AnalysisConsumer.cpp

Ted Kremenek kremenek at apple.com
Thu Jul 30 17:34:52 PDT 2009


Author: kremenek
Date: Thu Jul 30 19:34:52 2009
New Revision: 77648

URL: http://llvm.org/viewvc/llvm-project?rev=77648&view=rev
Log:
Fix use-after-release bug introduced in r77585 where the PathDiagnosticClient
created by AnalysisConsumer would be released by an instance of AnalysisManager
and then reused by later instances of AnalysisManager. Ownership of the
PathDiagnosticClient now belongs (for now) in AnalysisConsumer.

We also need this layering (for now) because the HTMLDiagnostiClient requires
that the entire translation unit be processed before emitting diagnostics. This
is done in its destructor (which should also be fixed, but that is another
issue).

This fixes PR 4653.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h
    cfe/trunk/lib/Frontend/AnalysisConsumer.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h?rev=77648&r1=77647&r2=77648&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h Thu Jul 30 19:34:52 2009
@@ -29,7 +29,7 @@
   Diagnostic &Diags;
   const LangOptions &LangInfo;
 
-  llvm::OwningPtr<PathDiagnosticClient> PD;
+  PathDiagnosticClient *PD;
   
   // Configurable components creators.
   StoreManagerCreator CreateStoreMgr;
@@ -51,7 +51,6 @@
                   ConstraintManagerCreator constraintmgr,
                   bool displayProgress, bool vizdot, bool vizubi, 
                   bool purge, bool eager, bool trim)
-
     : Ctx(ctx), Diags(diags), LangInfo(lang), PD(pd), 
       CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
       AScope(ScopeDecl), DisplayedFunction(!displayProgress),
@@ -124,7 +123,7 @@
   }
     
   virtual PathDiagnosticClient *getPathDiagnosticClient() {
-    return PD.get();      
+    return PD;      
   }
     
   bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }

Modified: cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/AnalysisConsumer.cpp?rev=77648&r1=77647&r2=77648&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/AnalysisConsumer.cpp Thu Jul 30 19:34:52 2009
@@ -84,8 +84,7 @@
     const std::string OutDir;
     AnalyzerOptions Opts;
 
-    // PD is owned by AnalysisManager.
-    PathDiagnosticClient *PD;
+    llvm::OwningPtr<PathDiagnosticClient> PD;
     StoreManagerCreator CreateStoreMgr;
     ConstraintManagerCreator CreateConstraintMgr;
 
@@ -106,7 +105,7 @@
         switch (Opts.AnalysisDiagOpt) {
         default:
 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN, AUTOCREATE) \
-          case PD_##NAME: PD = CREATEFN(OutDir, PP, PPF); break;
+          case PD_##NAME: PD.reset(CREATEFN(OutDir, PP, PPF)); break;
 #include "clang/Frontend/Analyses.def"
         }
       }
@@ -216,7 +215,7 @@
 void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
 
   if(!TranslationUnitActions.empty()) {
-    AnalysisManager mgr(*Ctx, Diags, LOpts, PD, 
+    AnalysisManager mgr(*Ctx, Diags, LOpts, PD.get(), 
                         CreateStoreMgr, CreateConstraintMgr,
                         Opts.AnalyzerDisplayProgress, Opts.VisualizeEGDot,
                         Opts.VisualizeEGUbi, Opts.PurgeDead, Opts.EagerlyAssume,
@@ -251,7 +250,7 @@
 
   // Create an AnalysisManager that will manage the state for analyzing
   // this method/function.
-  AnalysisManager mgr(D, *Ctx, Diags, LOpts, PD, 
+  AnalysisManager mgr(D, *Ctx, Diags, LOpts, PD.get(), 
                       CreateStoreMgr, CreateConstraintMgr,
                       Opts.AnalyzerDisplayProgress, Opts.VisualizeEGDot,
                       Opts.VisualizeEGUbi, Opts.PurgeDead, Opts.EagerlyAssume,





More information about the cfe-commits mailing list