]> granicus.if.org Git - clang/commitdiff
[analyzer] Pull Pred out of NodeBuilderContext.
authorAnna Zaks <ganna@apple.com>
Tue, 18 Oct 2011 23:06:16 +0000 (23:06 +0000)
committerAnna Zaks <ganna@apple.com>
Tue, 18 Oct 2011 23:06:16 +0000 (23:06 +0000)
Each builder will have a different one, so it doesn't make sense to keep it in the context.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142447 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
lib/StaticAnalyzer/Core/CoreEngine.cpp
lib/StaticAnalyzer/Core/ExprEngine.cpp

index aa4e0f722d90eecd8740f6d10376ec39fc5a59f2..e366b065c0bf13fcc57b6ec89b199b31750a0365 100644 (file)
@@ -50,8 +50,8 @@ public:
       Location(loc),
       ST(st),
       size(Dst.size()),
-      Ctx(builder.Eng, pred, builder.getBlock()),
-      NB(Ctx),
+      Ctx(builder.Eng, builder.getBlock()),
+      NB(Ctx, pred),
       respondsToCallback(respondsToCB) {
     assert(!(ST && ST != Pred->getState()));
   }
index 22f5d3d951fe7d29ba5417448d57a0ac6fe71527..7629ac4a67f3586cf766d6472582c34d86c238a7 100644 (file)
@@ -170,10 +170,9 @@ public:
 
 struct NodeBuilderContext {
   CoreEngine &Eng;
-  ExplodedNode *Pred;
   const CFGBlock *Block;
-  NodeBuilderContext(CoreEngine &E, ExplodedNode *N, const CFGBlock *B)
-    : Eng(E), Pred(N), Block(B) { assert(B); assert(!N->isSink()); }
+  NodeBuilderContext(CoreEngine &E, const CFGBlock *B)
+    : Eng(E), Block(B) { assert(B); }
 };
 
 /// This is the simplest builder which generates nodes in the ExplodedGraph.
@@ -181,6 +180,7 @@ class NodeBuilder {
 protected:
   friend class StmtNodeBuilder;
 
+  ExplodedNode *BuilderPred;
   NodeBuilderContext &C;
   bool Finalized;
 
@@ -212,8 +212,11 @@ protected:
                                  bool MarkAsSink = false);
 
 public:
-  NodeBuilder(NodeBuilderContext &Ctx)
-    : C(Ctx), Finalized(false) { Deferred.insert(C.Pred); }
+  NodeBuilder(NodeBuilderContext &Ctx, ExplodedNode *N)
+    : BuilderPred(N), C(Ctx), Finalized(false) {
+    assert(!N->isSink());
+    Deferred.insert(N);
+  }
 
   virtual ~NodeBuilder() {}
 
@@ -229,10 +232,10 @@ public:
   }
 
   // \brief Get the builder's predecessor - the parent to all the other nodes.
-  const ExplodedNode *getPred() const { return C.Pred; }
+  const ExplodedNode *getPred() const { return BuilderPred; }
 
   bool hasGeneratedNodes() const {
-    return (!Deferred.count(C.Pred));
+    return (!Deferred.count(BuilderPred));
   }
 
   typedef DeferredTy::iterator iterator;
@@ -251,11 +254,11 @@ public:
   /// visited on the exploded graph path.
   unsigned getCurrentBlockCount() const {
     return getBlockCounter().getNumVisited(
-                         C.Pred->getLocationContext()->getCurrentStackFrame(),
+                         BuilderPred->getLocationContext()->getCurrentStackFrame(),
                          C.Block->getBlockID());
   }
 
-  ExplodedNode *getPredecessor() const { return C.Pred; }
+  ExplodedNode *getPredecessor() const { return BuilderPred; }
 };
 
 class CommonNodeBuilder {
@@ -400,15 +403,15 @@ class BranchNodeBuilder: public NodeBuilder {
   void finalizeResults() {
     if (Finalized)
       return;
-    if (!GeneratedTrue) generateNode(C.Pred->State, true);
-    if (!GeneratedFalse) generateNode(C.Pred->State, false);
+    if (!GeneratedTrue) generateNode(BuilderPred->State, true);
+    if (!GeneratedFalse) generateNode(BuilderPred->State, false);
     Finalized = true;
   }
 
 public:
-  BranchNodeBuilder(NodeBuilderContext &C, const CFGBlock *dstT,
-                    const CFGBlock *dstF)
-  : NodeBuilder(C), DstT(dstT), DstF(dstF),
+  BranchNodeBuilder(NodeBuilderContext &C, ExplodedNode *Pred,
+                    const CFGBlock *dstT, const CFGBlock *dstF)
+  : NodeBuilder(C, Pred), DstT(dstT), DstF(dstF),
     GeneratedTrue(false), GeneratedFalse(false),
     InFeasibleTrue(!DstT), InFeasibleFalse(!DstF) {
   }
index b57bc4be5efcddccd177bcf9fa2b568437213ff3..bc84e2f7d5ddeabd3d6e7b8d0bc02afdfe9382ec 100644 (file)
@@ -155,6 +155,7 @@ public:
   ///  nodes by processing the 'effects' of a branch condition.
   void processBranch(const Stmt *Condition, const Stmt *Term, 
                      NodeBuilderContext& BuilderCtx,
+                     ExplodedNode *Pred,
                      const CFGBlock *DstT,
                      const CFGBlock *DstF);
 
index 6f480359bfe497dc8de7d5d3dc853926eafda4b0..38b7538b6b6be1f0b28d5d85da22ac362a8e9575 100644 (file)
@@ -67,6 +67,7 @@ public:
   ///  nodes by processing the 'effects' of a branch condition.
   virtual void processBranch(const Stmt *Condition, const Stmt *Term,
                              NodeBuilderContext& BuilderCtx,
+                             ExplodedNode *Pred,
                              const CFGBlock *DstT,
                              const CFGBlock *DstF) = 0;
 
index 0078922d69f39817fc301c3dacfde794cc9dac98..d1c1e39d59c8c1161c92aec6d182fdee79cc43fe 100644 (file)
@@ -417,8 +417,8 @@ void CoreEngine::HandleBlockExit(const CFGBlock * B, ExplodedNode *Pred) {
 void CoreEngine::HandleBranch(const Stmt *Cond, const Stmt *Term, 
                                 const CFGBlock * B, ExplodedNode *Pred) {
   assert(B->succ_size() == 2);
-  NodeBuilderContext Ctx(*this, Pred, B);
-  SubEng.processBranch(Cond, Term, Ctx,
+  NodeBuilderContext Ctx(*this, B);
+  SubEng.processBranch(Cond, Term, Ctx, Pred,
                        *(B->succ_begin()), *(B->succ_begin()+1));
 }
 
@@ -608,11 +608,12 @@ ExplodedNode *BranchNodeBuilder::generateNode(const Stmt *Condition,
                                               const ProgramState *State,
                                               const ProgramPointTag *Tag,
                                               bool MarkAsSink) {
-  ProgramPoint PP = PostCondition(Condition, C.Pred->getLocationContext(), Tag);
-  ExplodedNode *N = generateNodeImpl(PP, State, C.Pred, MarkAsSink);
+  ProgramPoint PP = PostCondition(Condition,
+                                  BuilderPred->getLocationContext(), Tag);
+  ExplodedNode *N = generateNodeImpl(PP, State, BuilderPred, MarkAsSink);
   assert(N);
   // TODO: This needs to go - we should not change Pred!!!
-  C.Pred = N;
+  BuilderPred = N;
   return N;
 }
 
@@ -625,7 +626,7 @@ ExplodedNode *BranchNodeBuilder::generateNode(const ProgramState *State,
     return NULL;
 
   if (!NodePred)
-    NodePred = C.Pred;
+    NodePred = BuilderPred;
   ProgramPoint Loc = BlockEdge(C.Block, branch ? DstT:DstF,
                                NodePred->getLocationContext());
   ExplodedNode *Succ = generateNodeImpl(Loc, State, NodePred);
index cc170bc1e644deff940746ba3e65909b5215cc9b..dba1ce10bd37d20622c39c46ff893b8637380991 100644 (file)
@@ -941,14 +941,15 @@ static SVal RecoverCastedSymbol(ProgramStateManager& StateMgr,
 
 void ExprEngine::processBranch(const Stmt *Condition, const Stmt *Term,
                                NodeBuilderContext& BldCtx,
+                               ExplodedNode *Pred,
                                const CFGBlock *DstT,
                                const CFGBlock *DstF) {
 
-  BranchNodeBuilder builder(BldCtx, DstT, DstF);
+  BranchNodeBuilder builder(BldCtx, Pred, DstT, DstF);
 
   // Check for NULL conditions; e.g. "for(;;)"
   if (!Condition) {
-    BranchNodeBuilder NullCondBldr(BldCtx, DstT, DstF);
+    BranchNodeBuilder NullCondBldr(BldCtx, Pred, DstT, DstF);
     NullCondBldr.markInfeasible(false);
     Engine.enqueue(NullCondBldr);
     return;