aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2011-10-18 23:06:16 +0000
committerAnna Zaks <ganna@apple.com>2011-10-18 23:06:16 +0000
commitad62deeb70e97da6bd514dd390ea1ce6af6ad81d (patch)
treede9011c7bcae1cb16430e5c427242d4220dda1ae
parent8c90aadce33152b03e3d1d5c7e9c468c7b939c96 (diff)
downloadclang-ad62deeb70e97da6bd514dd390ea1ce6af6ad81d.tar.gz
[analyzer] Pull Pred out of NodeBuilderContext.
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
-rw-r--r--include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h4
-rw-r--r--include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h31
-rw-r--r--include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h1
-rw-r--r--include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h1
-rw-r--r--lib/StaticAnalyzer/Core/CoreEngine.cpp13
-rw-r--r--lib/StaticAnalyzer/Core/ExprEngine.cpp5
6 files changed, 31 insertions, 24 deletions
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
index aa4e0f722d..e366b065c0 100644
--- a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -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()));
}
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 22f5d3d951..7629ac4a67 100644
--- a/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -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) {
}
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index b57bc4be5e..bc84e2f7d5 100644
--- a/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -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);
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
index 6f480359bf..38b7538b6b 100644
--- a/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
+++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
@@ -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;
diff --git a/lib/StaticAnalyzer/Core/CoreEngine.cpp b/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 0078922d69..d1c1e39d59 100644
--- a/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -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);
diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp
index cc170bc1e6..dba1ce10bd 100644
--- a/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -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;