[cfe-commits] r81433 - in /cfe/trunk: include/clang/Analysis/LocalCheckers.h include/clang/Analysis/PathSensitive/AnalysisContext.h include/clang/Analysis/PathSensitive/AnalysisManager.h include/clang/Analysis/PathSensitive/BugReporter.h include/clang/Analysis/PathSensitive/ExplodedGraph.h lib/Analysis/AnalysisManager.cpp lib/Analysis/BugReporter.cpp lib/Analysis/CFRefCount.cpp lib/Analysis/CheckDeadStores.cpp lib/Analysis/GRExprEngine.cpp lib/Frontend/AnalysisConsumer.cpp

Zhongxing Xu xuzhongxing at gmail.com
Wed Sep 9 22:44:12 PDT 2009


Author: zhongxingxu
Date: Thu Sep 10 00:44:00 2009
New Revision: 81433

URL: http://llvm.org/viewvc/llvm-project?rev=81433&view=rev
Log:
Make AnalysisManager stateless. Now other analyzer components only depends on
local node information.

Modified:
    cfe/trunk/include/clang/Analysis/LocalCheckers.h
    cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h
    cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h
    cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
    cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h
    cfe/trunk/lib/Analysis/AnalysisManager.cpp
    cfe/trunk/lib/Analysis/BugReporter.cpp
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/lib/Analysis/CheckDeadStores.cpp
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Frontend/AnalysisConsumer.cpp

Modified: cfe/trunk/include/clang/Analysis/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LocalCheckers.h?rev=81433&r1=81432&r2=81433&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Analysis/LocalCheckers.h Thu Sep 10 00:44:00 2009
@@ -32,7 +32,8 @@
 class LangOptions;
 class GRExprEngine;
 
-void CheckDeadStores(LiveVariables& L, BugReporter& BR);
+void CheckDeadStores(CFG &cfg, LiveVariables &L, ParentMap &map, 
+                     BugReporter& BR);
 
 void CheckUninitializedValues(CFG& cfg, ASTContext& Ctx, Diagnostic& Diags,
                               bool FullUninitTaint=false);

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h Thu Sep 10 00:44:00 2009
@@ -91,6 +91,10 @@
     return getAnalysisContext()->getLiveVariables();
   }
 
+  ParentMap &getParentMap() const { 
+    return getAnalysisContext()->getParentMap();
+  }
+
   const ImplicitParamDecl *getSelfDecl() const {
     return Ctx->getSelfDecl();
   }

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=81433&r1=81432&r2=81433&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h Thu Sep 10 00:44:00 2009
@@ -22,9 +22,7 @@
 namespace clang {
 
 class AnalysisManager : public BugReporterData {
-  AnalysisContextManager ContextMgr;
-  AnalysisContext *EntryContext;
-
+  AnalysisContextManager AnaCtxMgr;
   LocationContextManager LocCtxMgr;
 
   ASTContext &Ctx;
@@ -55,22 +53,7 @@
   bool TrimGraph;
 
 public:
-  AnalysisManager(Decl *d, ASTContext &ctx, Diagnostic &diags,
-                  const LangOptions &lang, PathDiagnosticClient *pd,
-                  StoreManagerCreator storemgr,
-                  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),
-      VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
-      EagerlyAssume(eager), TrimGraph(trim) {
-
-    EntryContext = ContextMgr.getContext(d);
-  }
-
-  AnalysisManager(ASTContext &ctx, Diagnostic &diags,
+  AnalysisManager(ASTContext &ctx, Diagnostic &diags, 
                   const LangOptions &lang, PathDiagnosticClient *pd,
                   StoreManagerCreator storemgr,
                   ConstraintManagerCreator constraintmgr,
@@ -81,25 +64,7 @@
       CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
       AScope(ScopeDecl), DisplayedFunction(!displayProgress),
       VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
-      EagerlyAssume(eager), TrimGraph(trim) {
-
-    EntryContext = 0;
-  }
-
-  void setEntryContext(Decl *D) {
-    EntryContext = ContextMgr.getContext(D);
-    DisplayedFunction = false;
-  }
-
-  const Decl *getCodeDecl() const {
-    assert (AScope == ScopeDecl);
-    return EntryContext->getDecl();
-  }
-
-  Stmt *getBody() const {
-    assert (AScope == ScopeDecl);
-    return EntryContext->getBody();
-  }
+      EagerlyAssume(eager), TrimGraph(trim) {}
 
   StoreManagerCreator getStoreManagerCreator() {
     return CreateStoreMgr;
@@ -109,18 +74,6 @@
     return CreateConstraintMgr;
   }
 
-  virtual CFG *getCFG() {
-    return EntryContext->getCFG();
-  }
-
-  virtual ParentMap &getParentMap() {
-    return EntryContext->getParentMap();
-  }
-
-  virtual LiveVariables *getLiveVariables() {
-    return EntryContext->getLiveVariables();
-  }
-
   virtual ASTContext &getASTContext() {
     return Ctx;
   }
@@ -141,10 +94,6 @@
     return PD.get();
   }
 
-  StackFrameContext *getEntryStackFrame() {
-    return LocCtxMgr.getStackFrame(EntryContext, 0, 0);
-  }
-
   bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
 
   bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
@@ -159,7 +108,23 @@
 
   bool shouldEagerlyAssume() const { return EagerlyAssume; }
 
-  void DisplayFunction();
+  void DisplayFunction(Decl *D);
+
+  CFG *getCFG(Decl const *D) {
+    return AnaCtxMgr.getContext(D)->getCFG();
+  }
+
+  LiveVariables *getLiveVariables(Decl const *D) {
+    return AnaCtxMgr.getContext(D)->getLiveVariables();
+  }
+
+  ParentMap &getParentMap(Decl const *D) {
+    return AnaCtxMgr.getContext(D)->getParentMap();
+  }
+
+  StackFrameContext *getStackFrame(Decl const *D) {
+    return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D), 0, 0);
+  }
 };
 
 }

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Thu Sep 10 00:44:00 2009
@@ -282,9 +282,6 @@
   virtual PathDiagnosticClient* getPathDiagnosticClient() = 0;
   virtual ASTContext& getASTContext() = 0;
   virtual SourceManager& getSourceManager() = 0;
-  virtual CFG* getCFG() = 0;
-  virtual ParentMap& getParentMap() = 0;
-  virtual LiveVariables* getLiveVariables() = 0;
 };
 
 class BugReporter {
@@ -328,12 +325,6 @@
 
   SourceManager& getSourceManager() { return D.getSourceManager(); }
 
-  CFG* getCFG() { return D.getCFG(); }
-
-  ParentMap& getParentMap() { return D.getParentMap(); }
-
-  LiveVariables* getLiveVariables() { return D.getLiveVariables(); }
-
   virtual void GeneratePathDiagnostic(PathDiagnostic& PD,
                                       BugReportEquivClass& EQ) {}
 
@@ -457,8 +448,6 @@
     return BR.getSourceManager();
   }
 
-  const Decl &getCodeDecl();
-  const CFG &getCFG();
   virtual BugReport::NodeResolver& getNodeResolver() = 0;
 };
 

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h Thu Sep 10 00:44:00 2009
@@ -119,10 +119,14 @@
 
   CFG &getCFG() const { return *getLocationContext()->getCFG(); }
 
-  const GRState* getState() const {
-    return State;
+  ParentMap &getParentMap() const {return getLocationContext()->getParentMap();}
+
+  LiveVariables &getLiveVariables() const { 
+    return *getLocationContext()->getLiveVariables(); 
   }
 
+  const GRState* getState() const { return State; }
+
   template <typename T>
   const T* getLocationAs() const { return llvm::dyn_cast<T>(&Location); }
 

Modified: cfe/trunk/lib/Analysis/AnalysisManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisManager.cpp?rev=81433&r1=81432&r2=81433&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisManager.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisManager.cpp Thu Sep 10 00:44:00 2009
@@ -16,7 +16,7 @@
 
 using namespace clang;
 
-void AnalysisManager::DisplayFunction() {
+void AnalysisManager::DisplayFunction(Decl *D) {
 
   if (DisplayedFunction)
     return;
@@ -24,12 +24,12 @@
   DisplayedFunction = true;
 
   // FIXME: Is getCodeDecl() always a named decl?
-  if (isa<FunctionDecl>(getCodeDecl()) ||
-      isa<ObjCMethodDecl>(getCodeDecl())) {
-    const NamedDecl *ND = cast<NamedDecl>(getCodeDecl());
+  if (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)) {
+    const NamedDecl *ND = cast<NamedDecl>(D);
     SourceManager &SM = getASTContext().getSourceManager();
     llvm::errs() << "ANALYZE: "
                  << SM.getPresumedLoc(ND->getLocation()).getFilename()
                  << ' ' << ND->getNameAsString() << '\n';
   }
 }
+

Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=81433&r1=81432&r2=81433&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Thu Sep 10 00:44:00 2009
@@ -36,14 +36,6 @@
     if ((*I)->isOwnedByReporterContext()) delete *I;
 }
 
-const Decl& BugReporterContext::getCodeDecl() {
-  return *BR.getEngine().getAnalysisManager().getCodeDecl();
-}
-
-const CFG& BugReporterContext::getCFG() {
-  return *BR.getEngine().getAnalysisManager().getCFG();
-}
-
 //===----------------------------------------------------------------------===//
 // Helper routines for walking the ExplodedGraph and fetching statements.
 //===----------------------------------------------------------------------===//
@@ -158,11 +150,9 @@
   PathDiagnosticLocation ExecutionContinues(llvm::raw_string_ostream& os,
                                             const ExplodedNode* N);
 
-  ParentMap& getParentMap() {
-    if (PM.get() == 0)
-      PM.reset(new ParentMap(getCodeDecl().getBody()));
-    return *PM.get();
-  }
+  Decl const &getCodeDecl() { return R->getEndNode()->getCodeDecl(); }
+
+  ParentMap& getParentMap() { return R->getEndNode()->getParentMap(); }
 
   const Stmt *getParent(const Stmt *S) {
     return getParentMap().getParent(S);

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=81433&r1=81432&r2=81433&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Thu Sep 10 00:44:00 2009
@@ -2641,7 +2641,7 @@
   }
 
   if (!L.isValid()) {
-    const Decl &D = BRC.getCodeDecl();
+    const Decl &D = EndN->getCodeDecl();
     L = PathDiagnosticLocation(D.getBodyRBrace(), SMgr);
   }
 
@@ -2660,7 +2660,7 @@
     // FIXME: Per comments in rdar://6320065, "create" only applies to CF
     // ojbects.  Only "copy", "alloc", "retain" and "new" transfer ownership
     // to the caller for NS objects.
-    ObjCMethodDecl& MD = cast<ObjCMethodDecl>(BRC.getCodeDecl());
+    ObjCMethodDecl& MD = cast<ObjCMethodDecl>(EndN->getCodeDecl());
     os << " is returned from a method whose name ('"
        << MD.getSelector().getAsString()
     << "') does not contain 'copy' or otherwise starts with"
@@ -2668,7 +2668,7 @@
     " in the Memory Management Guide for Cocoa (object leaked)";
   }
   else if (RV->getKind() == RefVal::ErrorGCLeakReturned) {
-    ObjCMethodDecl& MD = cast<ObjCMethodDecl>(BRC.getCodeDecl());
+    ObjCMethodDecl& MD = cast<ObjCMethodDecl>(EndN->getCodeDecl());
     os << " and returned from method '" << MD.getSelector().getAsString()
        << "' is potentially leaked when using garbage collection.  Callers "
           "of this method do not expect a returned object with a +1 retain "
@@ -3186,7 +3186,7 @@
 
   // Any leaks or other errors?
   if (X.isReturnedOwned() && X.getCount() == 0) {
-    const Decl *CD = Eng.getAnalysisManager().getCodeDecl();
+    Decl const *CD = &Pred->getCodeDecl();
     if (const ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(CD)) {
       const RetainSummary &Summ = *Summaries.getMethodSummary(MD);
       RetEffect RE = Summ.getRetEffect();
@@ -3229,7 +3229,7 @@
     }
   }
   else if (X.isReturnedNotOwned()) {
-    const Decl *CD = Eng.getAnalysisManager().getCodeDecl();
+    Decl const *CD = &Pred->getCodeDecl();
     if (const ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(CD)) {
       const RetainSummary &Summ = *Summaries.getMethodSummary(MD);
       if (Summ.getRetEffect().isOwned()) {

Modified: cfe/trunk/lib/Analysis/CheckDeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckDeadStores.cpp?rev=81433&r1=81432&r2=81433&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckDeadStores.cpp Thu Sep 10 00:44:00 2009
@@ -251,9 +251,10 @@
 } // end anonymous namespace
 
 
-void clang::CheckDeadStores(LiveVariables& L, BugReporter& BR) {
-  FindEscaped FS(BR.getCFG());
+void clang::CheckDeadStores(CFG &cfg, LiveVariables &L, ParentMap &pmap, 
+                            BugReporter& BR) {
+  FindEscaped FS(&cfg);
   FS.getCFG().VisitBlockStmts(FS);
-  DeadStoreObs A(BR.getContext(), BR, BR.getParentMap(), FS.Escaped);
-  L.runOnAllBlocks(*BR.getCFG(), &A);
+  DeadStoreObs A(BR.getContext(), BR, pmap, FS.Escaped);
+  L.runOnAllBlocks(cfg, &A);
 }

Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=81433&r1=81432&r2=81433&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Thu Sep 10 00:44:00 2009
@@ -262,7 +262,8 @@
     Builder->setAuditor(BatchAuditor.get());
 
   // Create the cleaned state.
-  SymbolReaper SymReaper(*AMgr.getLiveVariables(), SymMgr);
+  SymbolReaper SymReaper(Builder->getBasePredecessor()->getLiveVariables(), 
+                         SymMgr);
   CleanedState = AMgr.shouldPurgeDead()
     ? StateMgr.RemoveDeadBindings(EntryNode->getState(), CurrentStmt, SymReaper)
     : EntryNode->getState();
@@ -1670,7 +1671,8 @@
 static std::pair<const void*,const void*> EagerlyAssumeTag
   = std::pair<const void*,const void*>(&EagerlyAssumeTag,0);
 
-void GRExprEngine::EvalEagerlyAssume(ExplodedNodeSet &Dst, ExplodedNodeSet &Src, Expr *Ex) {
+void GRExprEngine::EvalEagerlyAssume(ExplodedNodeSet &Dst, ExplodedNodeSet &Src,
+                                     Expr *Ex) {
   for (ExplodedNodeSet::iterator I=Src.begin(), E=Src.end(); I!=E; ++I) {
     ExplodedNode *Pred = *I;
 
@@ -1713,9 +1715,8 @@
 // Transfer function: Objective-C ivar references.
 //===----------------------------------------------------------------------===//
 
-void GRExprEngine::VisitObjCIvarRefExpr(ObjCIvarRefExpr* Ex,
-                                            ExplodedNode* Pred, ExplodedNodeSet& Dst,
-                                            bool asLValue) {
+void GRExprEngine::VisitObjCIvarRefExpr(ObjCIvarRefExpr* Ex, ExplodedNode* Pred,
+                                        ExplodedNodeSet& Dst, bool asLValue) {
 
   Expr* Base = cast<Expr>(Ex->getBase());
   ExplodedNodeSet Tmp;
@@ -1738,7 +1739,7 @@
 //===----------------------------------------------------------------------===//
 
 void GRExprEngine::VisitObjCForCollectionStmt(ObjCForCollectionStmt* S,
-                                              ExplodedNode* Pred, ExplodedNodeSet& Dst) {
+                                     ExplodedNode* Pred, ExplodedNodeSet& Dst) {
 
   // ObjCForCollectionStmts are processed in two places.  This method
   // handles the case where an ObjCForCollectionStmt* occurs as one of the
@@ -1786,7 +1787,7 @@
 }
 
 void GRExprEngine::VisitObjCForCollectionStmtAux(ObjCForCollectionStmt* S,
-                                                 ExplodedNode* Pred, ExplodedNodeSet& Dst,
+                                       ExplodedNode* Pred, ExplodedNodeSet& Dst,
                                                  SVal ElementV) {
 
 
@@ -1845,7 +1846,7 @@
 void GRExprEngine::VisitObjCMessageExprArgHelper(ObjCMessageExpr* ME,
                                               ObjCMessageExpr::arg_iterator AI,
                                               ObjCMessageExpr::arg_iterator AE,
-                                              ExplodedNode* Pred, ExplodedNodeSet& Dst) {
+                                     ExplodedNode* Pred, ExplodedNodeSet& Dst) {
   if (AI == AE) {
 
     // Process the receiver.
@@ -1854,7 +1855,8 @@
       ExplodedNodeSet Tmp;
       Visit(Receiver, Pred, Tmp);
 
-      for (ExplodedNodeSet::iterator NI = Tmp.begin(), NE = Tmp.end(); NI != NE; ++NI)
+      for (ExplodedNodeSet::iterator NI = Tmp.begin(), NE = Tmp.end(); NI != NE;
+           ++NI)
         VisitObjCMessageExprDispatchHelper(ME, *NI, Dst);
 
       return;
@@ -1869,7 +1871,7 @@
 
   ++AI;
 
-  for (ExplodedNodeSet::iterator NI = Tmp.begin(), NE = Tmp.end(); NI != NE; ++NI)
+  for (ExplodedNodeSet::iterator NI = Tmp.begin(), NE = Tmp.end();NI != NE;++NI)
     VisitObjCMessageExprArgHelper(ME, AI, AE, *NI, Dst);
 }
 
@@ -1910,7 +1912,7 @@
 
       // Check if the receiver was nil and the return value a struct.
       if (RetTy->isRecordType()) {
-        if (BR.getParentMap().isConsumedExpr(ME)) {
+        if (Pred->getParentMap().isConsumedExpr(ME)) {
           // The [0 ...] expressions will return garbage.  Flag either an
           // explicit or implicit error.  Because of the structure of this
           // function we currently do not bifurfacte the state graph at
@@ -1929,7 +1931,7 @@
       else {
         ASTContext& Ctx = getContext();
         if (RetTy != Ctx.VoidTy) {
-          if (BR.getParentMap().isConsumedExpr(ME)) {
+          if (Pred->getParentMap().isConsumedExpr(ME)) {
             // sizeof(void *)
             const uint64_t voidPtrSize = Ctx.getTypeSize(Ctx.VoidPtrTy);
             // sizeof(return type)

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

==============================================================================
--- cfe/trunk/lib/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/AnalysisConsumer.cpp Thu Sep 10 00:44:00 2009
@@ -45,7 +45,7 @@
 //===----------------------------------------------------------------------===//
 
 namespace {
-  typedef void (*CodeAction)(AnalysisManager& Mgr);
+  typedef void (*CodeAction)(AnalysisManager& Mgr, Decl *D);
 } // end anonymous namespace
 
 //===----------------------------------------------------------------------===//
@@ -223,10 +223,23 @@
 }
 
 void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
-  if (!TranslationUnitActions.empty()) {
-    for (Actions::iterator I = TranslationUnitActions.begin(),
+  // Find the entry function definition.
+  FunctionDecl *FD = 0;
+  TranslationUnitDecl *TU = Ctx->getTranslationUnitDecl();
+  for (DeclContext::decl_iterator I = TU->decls_begin(), E = TU->decls_end();
+       I != E; ++I) {
+    if (FunctionDecl *fd = dyn_cast<FunctionDecl>(*I))
+      if (fd->isThisDeclarationADefinition() &&
+          fd->getNameAsString() == Opts.AnalyzeSpecificFunction) {
+        FD = fd;
+        break;
+      }
+  }
+
+  if(!TranslationUnitActions.empty()) {
+    for (Actions::iterator I = TranslationUnitActions.begin(), 
          E = TranslationUnitActions.end(); I != E; ++I)
-      (*I)(*Mgr);
+      (*I)(*Mgr, FD);  
   }
 
   if (!ObjCImplementationActions.empty()) {
@@ -245,7 +258,7 @@
   Mgr.reset(NULL);
 }
 
-void AnalysisConsumer::HandleCode(Decl* D, Stmt* Body, Actions& actions) {
+void AnalysisConsumer::HandleCode(Decl *D, Stmt* Body, Actions& actions) {
 
   // Don't run the actions if an error has occured with parsing the file.
   if (Diags.hasErrorOccurred())
@@ -257,41 +270,40 @@
       !Ctx->getSourceManager().isFromMainFile(D->getLocation()))
     return;
 
-  Mgr->setEntryContext(D);
-
   // Dispatch on the actions.
   for (Actions::iterator I = actions.begin(), E = actions.end(); I != E; ++I)
-    (*I)(*Mgr);
+    (*I)(*Mgr, D);  
 }
 
 //===----------------------------------------------------------------------===//
 // Analyses
 //===----------------------------------------------------------------------===//
 
-static void ActionWarnDeadStores(AnalysisManager& mgr) {
-  if (LiveVariables* L = mgr.getLiveVariables()) {
+static void ActionWarnDeadStores(AnalysisManager& mgr, Decl *D) {
+  if (LiveVariables *L = mgr.getLiveVariables(D)) {
     BugReporter BR(mgr);
-    CheckDeadStores(*L, BR);
+    CheckDeadStores(*mgr.getCFG(D), *L, mgr.getParentMap(D), BR);
   }
 }
 
-static void ActionWarnUninitVals(AnalysisManager& mgr) {
-  if (CFG* c = mgr.getCFG())
+static void ActionWarnUninitVals(AnalysisManager& mgr, Decl *D) {
+  if (CFG* c = mgr.getCFG(D))
     CheckUninitializedValues(*c, mgr.getASTContext(), mgr.getDiagnostic());
 }
 
 
-static void ActionGRExprEngine(AnalysisManager& mgr, GRTransferFuncs* tf,
+static void ActionGRExprEngine(AnalysisManager& mgr, Decl *D, 
+                               GRTransferFuncs* tf,
                                bool StandardWarnings = true) {
 
 
   llvm::OwningPtr<GRTransferFuncs> TF(tf);
 
   // Display progress.
-  mgr.DisplayFunction();
+  mgr.DisplayFunction(D);
 
   // Construct the analysis engine.
-  LiveVariables* L = mgr.getLiveVariables();
+  LiveVariables* L = mgr.getLiveVariables(D);
   if (!L) return;
 
   GRExprEngine Eng(mgr);
@@ -300,7 +312,7 @@
 
   if (StandardWarnings) {
     Eng.RegisterInternalChecks();
-    RegisterAppleChecks(Eng, *mgr.getCodeDecl());
+    RegisterAppleChecks(Eng, *D);
   }
 
   // Set the graph auditor.
@@ -311,7 +323,7 @@
   }
 
   // Execute the worklist algorithm.
-  Eng.ExecuteWorkList(mgr.getEntryStackFrame());
+  Eng.ExecuteWorkList(mgr.getStackFrame(D));
 
   // Release the auditor (if any) so that it doesn't monitor the graph
   // created BugReporter.
@@ -325,82 +337,79 @@
   Eng.getBugReporter().FlushReports();
 }
 
-static void ActionCheckerCFRefAux(AnalysisManager& mgr, bool GCEnabled,
-                                  bool StandardWarnings) {
+static void ActionCheckerCFRefAux(AnalysisManager& mgr, Decl *D,
+                                  bool GCEnabled, bool StandardWarnings) {
 
   GRTransferFuncs* TF = MakeCFRefCountTF(mgr.getASTContext(),
                                          GCEnabled,
                                          mgr.getLangOptions());
 
-  ActionGRExprEngine(mgr, TF, StandardWarnings);
+  ActionGRExprEngine(mgr, D, TF, StandardWarnings);
 }
 
-static void ActionCheckerCFRef(AnalysisManager& mgr) {
+static void ActionCheckerCFRef(AnalysisManager& mgr, Decl *D) {
 
  switch (mgr.getLangOptions().getGCMode()) {
    default:
      assert (false && "Invalid GC mode.");
    case LangOptions::NonGC:
-     ActionCheckerCFRefAux(mgr, false, true);
+     ActionCheckerCFRefAux(mgr, D, false, true);
      break;
 
    case LangOptions::GCOnly:
-     ActionCheckerCFRefAux(mgr, true, true);
+     ActionCheckerCFRefAux(mgr, D, true, true);
      break;
 
    case LangOptions::HybridGC:
-     ActionCheckerCFRefAux(mgr, false, true);
-     ActionCheckerCFRefAux(mgr, true, false);
+     ActionCheckerCFRefAux(mgr, D, false, true);
+     ActionCheckerCFRefAux(mgr, D, true, false);
      break;
  }
 }
 
-static void ActionDisplayLiveVariables(AnalysisManager& mgr) {
-  if (LiveVariables* L = mgr.getLiveVariables()) {
-    mgr.DisplayFunction();
+static void ActionDisplayLiveVariables(AnalysisManager& mgr, Decl *D) {
+  if (LiveVariables* L = mgr.getLiveVariables(D)) {
+    mgr.DisplayFunction(D);
     L->dumpBlockLiveness(mgr.getSourceManager());
   }
 }
 
-static void ActionCFGDump(AnalysisManager& mgr) {
-  if (CFG* c = mgr.getCFG()) {
-    mgr.DisplayFunction();
+static void ActionCFGDump(AnalysisManager& mgr, Decl *D) {
+  if (CFG* c = mgr.getCFG(D)) {
+    mgr.DisplayFunction(D);
     c->dump(mgr.getLangOptions());
   }
 }
 
-static void ActionCFGView(AnalysisManager& mgr) {
-  if (CFG* c = mgr.getCFG()) {
-    mgr.DisplayFunction();
+static void ActionCFGView(AnalysisManager& mgr, Decl *D) {
+  if (CFG* c = mgr.getCFG(D)) {
+    mgr.DisplayFunction(D);
     c->viewCFG(mgr.getLangOptions());
   }
 }
 
-static void ActionSecuritySyntacticChecks(AnalysisManager &mgr) {
+static void ActionSecuritySyntacticChecks(AnalysisManager &mgr, Decl *D) {
   BugReporter BR(mgr);
-  CheckSecuritySyntaxOnly(mgr.getCodeDecl(), BR);
+  CheckSecuritySyntaxOnly(D, BR);
 }
 
-static void ActionWarnObjCDealloc(AnalysisManager& mgr) {
+static void ActionWarnObjCDealloc(AnalysisManager& mgr, Decl *D) {
   if (mgr.getLangOptions().getGCMode() == LangOptions::GCOnly)
     return;
 
   BugReporter BR(mgr);
-
-  CheckObjCDealloc(cast<ObjCImplementationDecl>(mgr.getCodeDecl()),
-                   mgr.getLangOptions(), BR);
+  CheckObjCDealloc(cast<ObjCImplementationDecl>(D), mgr.getLangOptions(), BR);  
 }
 
-static void ActionWarnObjCUnusedIvars(AnalysisManager& mgr) {
+static void ActionWarnObjCUnusedIvars(AnalysisManager& mgr, Decl *D) {
   BugReporter BR(mgr);
-  CheckObjCUnusedIvar(cast<ObjCImplementationDecl>(mgr.getCodeDecl()), BR);
+  CheckObjCUnusedIvar(cast<ObjCImplementationDecl>(D), BR);  
 }
 
-static void ActionWarnObjCMethSigs(AnalysisManager& mgr) {
+static void ActionWarnObjCMethSigs(AnalysisManager& mgr, Decl *D) {
   BugReporter BR(mgr);
 
-  CheckObjCInstMethSignature(cast<ObjCImplementationDecl>(mgr.getCodeDecl()),
-                             BR);
+  CheckObjCInstMethSignature(cast<ObjCImplementationDecl>(D), BR);
 }
 
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list