]> granicus.if.org Git - clang/commitdiff
[analyzer] Remove recursive visitation in ExprEngine::VisitDeclStmt because it isn...
authorTed Kremenek <kremenek@apple.com>
Fri, 29 Jul 2011 21:18:41 +0000 (21:18 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 29 Jul 2011 21:18:41 +0000 (21:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136522 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/ExprEngine.cpp

index 82312d871d95764f482c4c871f94fd70cc763f6c..fb7bf9e246d0e0892c65c45fac0ab2b93bb9ab7b 100644 (file)
@@ -2163,35 +2163,32 @@ void ExprEngine::VisitCompoundLiteralExpr(const CompoundLiteralExpr* CL,
 void ExprEngine::VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
                                  ExplodedNodeSet& Dst) {
 
-  // The CFG has one DeclStmt per Decl.
+  // FIXME: static variables may have an initializer, but the second
+  //  time a function is called those values may not be current.
+  //  This may need to be reflected in the CFG.
+  
+  // Assumption: The CFG has one DeclStmt per Decl.
   const Decl* D = *DS->decl_begin();
 
   if (!D || !isa<VarDecl>(D))
     return;
 
-  const VarDecl* VD = dyn_cast<VarDecl>(D);
-  const Expr* InitEx = VD->getInit();
 
-  // FIXME: static variables may have an initializer, but the second
-  //  time a function is called those values may not be current.
-  ExplodedNodeSet Tmp;
-
-  if (InitEx)
-    Visit(InitEx, Pred, Tmp);
-  else
-    Tmp.Add(Pred);
+  ExplodedNodeSet dstPreVisit;
+  getCheckerManager().runCheckersForPreStmt(dstPreVisit, Pred, DS, *this);
 
-  ExplodedNodeSet Tmp2;
-  getCheckerManager().runCheckersForPreStmt(Tmp2, Tmp, DS, *this);
+  const VarDecl *VD = dyn_cast<VarDecl>(D);
 
-  for (ExplodedNodeSet::iterator I=Tmp2.begin(), E=Tmp2.end(); I!=E; ++I) {
+  for (ExplodedNodeSet::iterator I = dstPreVisit.begin(), E = dstPreVisit.end();
+       I!=E; ++I)
+  {
     ExplodedNode *N = *I;
     const GRState *state = GetState(N);
 
     // Decls without InitExpr are not initialized explicitly.
     const LocationContext *LC = N->getLocationContext();
 
-    if (InitEx) {
+    if (const Expr *InitEx = VD->getInit()) {
       SVal InitVal = state->getSVal(InitEx);
 
       // We bound the temp obj region to the CXXConstructExpr. Now recover
@@ -2211,12 +2208,11 @@ void ExprEngine::VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
                                                Builder->getCurrentBlockCount());
       }
 
-      evalBind(Dst, DS, *I, state,
+      evalBind(Dst, DS, N, state,
                loc::MemRegionVal(state->getRegion(VD, LC)), InitVal, true);
     }
     else {
-      state = state->bindDeclWithNoInit(state->getRegion(VD, LC));
-      MakeNode(Dst, DS, *I, state);
+      MakeNode(Dst, DS, N, state->bindDeclWithNoInit(state->getRegion(VD, LC)));
     }
   }
 }