Added boilerplate logic in GREngine for processing branches.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46532 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp
index 6d89b29..2c6c7f7 100644
--- a/Analysis/GRConstants.cpp
+++ b/Analysis/GRConstants.cpp
@@ -730,7 +730,8 @@
public:
typedef ValueMapTy StateTy;
- typedef GRStmtNodeBuilder<GRConstants> NodeBuilder;
+ typedef GRStmtNodeBuilder<GRConstants> StmtNodeBuilder;
+ typedef GRBranchNodeBuilder<GRConstants> BranchNodeBuilder;
typedef ExplodedGraph<GRConstants> GraphTy;
typedef GraphTy::NodeTy NodeTy;
@@ -767,8 +768,8 @@
/// Builder - The current GRStmtNodeBuilder which is used when building the nodes
/// for a given statement.
- NodeBuilder* Builder;
-
+ StmtNodeBuilder* Builder;
+
/// StateMgr - Object that manages the data for all created states.
ValueMapTy::Factory StateMgr;
@@ -826,7 +827,12 @@
/// ProcessStmt - Called by GREngine. Used to generate new successor
/// nodes by processing the 'effects' of a block-level statement.
- void ProcessStmt(Stmt* S, NodeBuilder& builder);
+ void ProcessStmt(Stmt* S, StmtNodeBuilder& builder);
+
+ /// ProcessBranch - Called by GREngine. Used to generate successor
+ /// nodes by processing the 'effects' of a branch condition.
+ void ProcessBranch(Stmt* Condition, Stmt* Term, BranchNodeBuilder& builder)
+ {}
/// RemoveDeadBindings - Return a new state that is the same as 'M' except
/// that all subexpression mappings are removed and that any
@@ -871,7 +877,7 @@
} // end anonymous namespace
-void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) {
+void GRConstants::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) {
Builder = &builder;
StmtEntryNode = builder.getLastNode();
diff --git a/Analysis/GREngine.cpp b/Analysis/GREngine.cpp
index 6aaf0d8..35101a9 100644
--- a/Analysis/GREngine.cpp
+++ b/Analysis/GREngine.cpp
@@ -149,8 +149,29 @@
void GREngineImpl::HandleBlockExit(CFGBlock * B, ExplodedNodeImpl* Pred) {
- if (Stmt* Terminator = B->getTerminator())
- ProcessTerminator(Terminator, B, Pred);
+ if (Stmt* Term = B->getTerminator()) {
+ switch (Term->getStmtClass()) {
+ default:
+ assert(false && "Analysis for this terminator not implemented.");
+ break;
+
+ case Stmt::IfStmtClass:
+ HandleBranch(cast<IfStmt>(Term)->getCond(), Term, B, Pred);
+ break;
+
+ case Stmt::ForStmtClass:
+ HandleBranch(cast<ForStmt>(Term)->getCond(), Term, B, Pred);
+ break;
+
+ case Stmt::WhileStmtClass:
+ HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred);
+ break;
+
+ case Stmt::DoStmtClass:
+ HandleBranch(cast<DoStmt>(Term)->getCond(), Term, B, Pred);
+ break;
+ }
+ }
else {
assert (B->succ_size() == 1 &&
"Blocks with no terminator should have at most 1 successor.");
@@ -159,6 +180,16 @@
}
}
+void GREngineImpl::HandleBranch(Stmt* Cond, Stmt* Term, CFGBlock * B,
+ ExplodedNodeImpl* Pred) {
+ assert (B->succ_size() == 2);
+
+ GRBranchNodeBuilderImpl Builder(B, *(B->succ_begin()), *(B->succ_begin()+1),
+ Pred, this);
+
+ ProcessBranch(Cond, Term, Builder);
+}
+
void GREngineImpl::HandlePostStmt(const PostStmt& L, CFGBlock* B,
unsigned StmtIdx, ExplodedNodeImpl* Pred) {
@@ -255,3 +286,16 @@
LastNode = NULL;
return NULL;
}
+
+void GRBranchNodeBuilderImpl::generateNodeImpl(void* State, bool branch) {
+ bool IsNew;
+
+ ExplodedNodeImpl* Succ =
+ Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, branch ? DstT : DstF),
+ State, &IsNew);
+
+ Succ->addPredecessor(Pred);
+
+ if (IsNew)
+ Eng.WList->Enqueue(GRWorkListUnit(Succ));
+}