[cfe-commits] r142829 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h lib/StaticAnalyzer/Core/ExprEngine.cpp lib/StaticAnalyzer/Core/ExprEngineC.cpp

Anna Zaks ganna at apple.com
Mon Oct 24 11:26:08 PDT 2011


Author: zaks
Date: Mon Oct 24 13:26:08 2011
New Revision: 142829

URL: http://llvm.org/viewvc/llvm-project?rev=142829&view=rev
Log:
[analyzer] Convert more functions (ex:evalBind()) to iterative builders

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h?rev=142829&r1=142828&r2=142829&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h Mon Oct 24 13:26:08 2011
@@ -301,6 +301,10 @@
                       const NodeBuilderContext &Ctx)
     : NodeBuilder(SrcNode, DstSet, Ctx) {}
 
+  PureStmtNodeBuilder(ExplodedNodeSet &SrcSet, ExplodedNodeSet &DstSet,
+                      const NodeBuilderContext &Ctx)
+    : NodeBuilder(SrcSet, DstSet, Ctx) {}
+
   ExplodedNode *generateNode(const Stmt *S,
                              ExplodedNode *Pred,
                              const ProgramState *St,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=142829&r1=142828&r2=142829&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Mon Oct 24 13:26:08 2011
@@ -1297,9 +1297,13 @@
   getCheckerManager().runCheckersForBind(CheckedSet, Pred, location, Val,
                                          StoreE, *this);
 
+  // TODO: Remove TmpDst after NB refactoring is done.                                        
+  ExplodedNodeSet TmpDst;
+  Builder->takeNodes(CheckedSet);
+  PureStmtNodeBuilder Bldr(CheckedSet, TmpDst, *currentBuilderContext);
+
   for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
        I!=E; ++I) {
-
     const ProgramState *state = (*I)->getState();
 
     if (atDeclInit) {
@@ -1311,8 +1315,10 @@
       state = state->bindLoc(location, Val);
     }
 
-    MakeNode(Dst, StoreE, *I, state);
+    Bldr.generateNode(StoreE, *I, state);
   }
+  Builder->addNodes(TmpDst);
+  Dst.insert(TmpDst);
 }
 
 /// evalStore - Handle the semantics of a store via an assignment.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=142829&r1=142828&r2=142829&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Mon Oct 24 13:26:08 2011
@@ -373,7 +373,9 @@
 
 void ExprEngine::VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
                                   ExplodedNodeSet &Dst) {
-  
+  Builder->takeNodes(Pred);
+  PureStmtNodeBuilder Bldr(Pred, Dst, *currentBuilderContext);
+
   assert(B->getOpcode() == BO_LAnd ||
          B->getOpcode() == BO_LOr);
   
@@ -389,7 +391,8 @@
     
     // Handle undefined values.
     if (X.isUndef()) {
-      MakeNode(Dst, B, Pred, state->BindExpr(B, X));
+      Bldr.generateNode(B, Pred, state->BindExpr(B, X));
+      Builder->addNodes(Dst);
       return;
     }
     
@@ -402,11 +405,11 @@
     // this right now, and since most logical expressions are used for branches,
     // the payoff is not likely to be large.  Instead, we do eager evaluation.
     if (const ProgramState *newState = state->assume(XD, true))
-      MakeNode(Dst, B, Pred,
+      Bldr.generateNode(B, Pred,
                newState->BindExpr(B, svalBuilder.makeIntVal(1U, B->getType())));
     
     if (const ProgramState *newState = state->assume(XD, false))
-      MakeNode(Dst, B, Pred,
+      Bldr.generateNode(B, Pred,
                newState->BindExpr(B, svalBuilder.makeIntVal(0U, B->getType())));
   }
   else {
@@ -415,13 +418,16 @@
     // the short-circuiting.
     X = svalBuilder.makeIntVal(B->getOpcode() == BO_LAnd ? 0U : 1U,
                                B->getType());
-    MakeNode(Dst, B, Pred, state->BindExpr(B, X));
+    Bldr.generateNode(B, Pred, state->BindExpr(B, X));
   }
+  Builder->addNodes(Dst);
 }
 
 void ExprEngine::VisitInitListExpr(const InitListExpr *IE,
                                    ExplodedNode *Pred,
                                    ExplodedNodeSet &Dst) {
+  Builder->takeNodes(Pred);
+  PureStmtNodeBuilder B(Pred, Dst, *currentBuilderContext);
 
   const ProgramState *state = Pred->getState();
   QualType T = getContext().getCanonicalType(IE->getType());
@@ -434,7 +440,8 @@
     // e.g: static int* myArray[] = {};
     if (NumInitElements == 0) {
       SVal V = svalBuilder.makeCompoundVal(T, vals);
-      MakeNode(Dst, IE, Pred, state->BindExpr(IE, V));
+      B.generateNode(IE, Pred, state->BindExpr(IE, V));
+      Builder->addNodes(Dst);
       return;
     }
     
@@ -443,15 +450,17 @@
       vals = getBasicVals().consVals(state->getSVal(cast<Expr>(*it)), vals);
     }
     
-    MakeNode(Dst, IE, Pred,
-             state->BindExpr(IE, svalBuilder.makeCompoundVal(T, vals)));
+    B.generateNode(IE, Pred,
+                   state->BindExpr(IE, svalBuilder.makeCompoundVal(T, vals)));
+    Builder->addNodes(Dst);
     return;
   }
   
   if (Loc::isLocType(T) || T->isIntegerType()) {
     assert(IE->getNumInits() == 1);
     const Expr *initEx = IE->getInit(0);
-    MakeNode(Dst, IE, Pred, state->BindExpr(IE, state->getSVal(initEx)));
+    B.generateNode(IE, Pred, state->BindExpr(IE, state->getSVal(initEx)));
+    Builder->addNodes(Dst);
     return;
   }
   
@@ -463,6 +472,8 @@
                                   const Expr *R,
                                   ExplodedNode *Pred,
                                   ExplodedNodeSet &Dst) {
+  Builder->takeNodes(Pred);
+  PureStmtNodeBuilder B(Pred, Dst, *currentBuilderContext);
   
   const ProgramState *state = Pred->getState();
   SVal X = state->getSVal(Ex);  
@@ -472,12 +483,15 @@
   X = state->getSVal(SE);
   
   // Make sure that we invalidate the previous binding.
-  MakeNode(Dst, Ex, Pred, state->BindExpr(Ex, X, true));
+  B.generateNode(Ex, Pred, state->BindExpr(Ex, X, true));
+  Builder->addNodes(Dst);
 }
 
 void ExprEngine::
 VisitOffsetOfExpr(const OffsetOfExpr *OOE, 
                   ExplodedNode *Pred, ExplodedNodeSet &Dst) {
+  Builder->takeNodes(Pred);
+  PureStmtNodeBuilder B(Pred, Dst, *currentBuilderContext);
   Expr::EvalResult Res;
   if (OOE->Evaluate(Res, getContext()) && Res.Val.isInt()) {
     const APSInt &IV = Res.Val.getInt();
@@ -485,11 +499,10 @@
     assert(OOE->getType()->isIntegerType());
     assert(IV.isSigned() == OOE->getType()->isSignedIntegerOrEnumerationType());
     SVal X = svalBuilder.makeIntVal(IV);
-    MakeNode(Dst, OOE, Pred, Pred->getState()->BindExpr(OOE, X));
-    return;
+    B.generateNode(OOE, Pred, Pred->getState()->BindExpr(OOE, X));
   }
   // FIXME: Handle the case where __builtin_offsetof is not a constant.
-  Dst.Add(Pred);
+  Builder->addNodes(Dst);
 }
 
 





More information about the cfe-commits mailing list