2008-02-14 01:41:41 +08:00
|
|
|
//==- GRCoreEngine.cpp - Path-Sensitive Dataflow Engine ----------------*- C++ -*-//
|
2008-01-15 07:24:37 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a generic engine for intraprocedural, path-sensitive,
|
|
|
|
// dataflow analysis via graph reachability engine.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
#include "clang/Analysis/PathSensitive/GRCoreEngine.h"
|
2008-01-15 07:24:37 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using llvm::cast;
|
|
|
|
using llvm::isa;
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class VISIBILITY_HIDDEN DFS : public GRWorkList {
|
|
|
|
llvm::SmallVector<GRWorkListUnit,20> Stack;
|
|
|
|
public:
|
|
|
|
virtual bool hasWork() const {
|
|
|
|
return !Stack.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Enqueue(const GRWorkListUnit& U) {
|
|
|
|
Stack.push_back(U);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual GRWorkListUnit Dequeue() {
|
|
|
|
assert (!Stack.empty());
|
|
|
|
const GRWorkListUnit& U = Stack.back();
|
|
|
|
Stack.pop_back(); // This technically "invalidates" U, but we are fine.
|
|
|
|
return U;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2008-01-17 02:18:48 +08:00
|
|
|
// Place the dstor for GRWorkList here because it contains virtual member
|
|
|
|
// functions, and we the code for the dstor generated in one compilation unit.
|
|
|
|
GRWorkList::~GRWorkList() {}
|
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
GRWorkList* GRWorkList::MakeDFS() { return new DFS(); }
|
|
|
|
|
|
|
|
/// ExecuteWorkList - Run the worklist algorithm for a maximum number of steps.
|
2008-02-14 01:41:41 +08:00
|
|
|
bool GRCoreEngineImpl::ExecuteWorkList(unsigned Steps) {
|
2008-01-15 07:24:37 +08:00
|
|
|
|
|
|
|
if (G->num_roots() == 0) { // Initialize the analysis by constructing
|
|
|
|
// the root if none exists.
|
|
|
|
|
2008-01-29 08:33:40 +08:00
|
|
|
CFGBlock* Entry = &getCFG().getEntry();
|
2008-01-15 07:24:37 +08:00
|
|
|
|
|
|
|
assert (Entry->empty() &&
|
|
|
|
"Entry block must be empty.");
|
|
|
|
|
|
|
|
assert (Entry->succ_size() == 1 &&
|
|
|
|
"Entry block must have 1 successor.");
|
|
|
|
|
|
|
|
// Get the solitary successor.
|
|
|
|
CFGBlock* Succ = *(Entry->succ_begin());
|
|
|
|
|
|
|
|
// Construct an edge representing the
|
|
|
|
// starting location in the function.
|
2008-01-29 08:33:40 +08:00
|
|
|
BlockEdge StartLoc(getCFG(), Entry, Succ);
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2008-02-13 02:08:17 +08:00
|
|
|
// Set the current block counter to being empty.
|
|
|
|
WList->setBlockCounter(BCounterFactory.GetEmptyCounter());
|
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
// Generate the root.
|
|
|
|
GenerateNode(StartLoc, getInitialState());
|
|
|
|
}
|
|
|
|
|
|
|
|
while (Steps && WList->hasWork()) {
|
|
|
|
--Steps;
|
|
|
|
const GRWorkListUnit& WU = WList->Dequeue();
|
2008-02-13 02:08:17 +08:00
|
|
|
|
|
|
|
// Set the current block counter.
|
|
|
|
WList->setBlockCounter(WU.getBlockCounter());
|
|
|
|
|
|
|
|
// Retrieve the node.
|
2008-01-15 07:24:37 +08:00
|
|
|
ExplodedNodeImpl* Node = WU.getNode();
|
|
|
|
|
|
|
|
// Dispatch on the location type.
|
|
|
|
switch (Node->getLocation().getKind()) {
|
|
|
|
default:
|
|
|
|
assert (isa<BlockEdge>(Node->getLocation()));
|
|
|
|
HandleBlockEdge(cast<BlockEdge>(Node->getLocation()), Node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::BlockEntranceKind:
|
|
|
|
HandleBlockEntrance(cast<BlockEntrance>(Node->getLocation()), Node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::BlockExitKind:
|
2008-01-15 08:24:08 +08:00
|
|
|
assert (false && "BlockExit location never occur in forward analysis.");
|
2008-01-15 07:24:37 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::PostStmtKind:
|
|
|
|
HandlePostStmt(cast<PostStmt>(Node->getLocation()), WU.getBlock(),
|
|
|
|
WU.getIndex(), Node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return WList->hasWork();
|
|
|
|
}
|
|
|
|
|
2008-03-06 03:08:15 +08:00
|
|
|
void GRCoreEngineImpl::HandleBlockEdge(const BlockEdge& L,
|
|
|
|
ExplodedNodeImpl* Pred) {
|
2008-01-15 07:24:37 +08:00
|
|
|
|
|
|
|
CFGBlock* Blk = L.getDst();
|
|
|
|
|
|
|
|
// Check if we are entering the EXIT block.
|
2008-01-29 08:33:40 +08:00
|
|
|
if (Blk == &getCFG().getExit()) {
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2008-01-29 08:33:40 +08:00
|
|
|
assert (getCFG().getExit().size() == 0
|
|
|
|
&& "EXIT block cannot contain Stmts.");
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2008-04-12 06:03:04 +08:00
|
|
|
// Process the final state transition.
|
|
|
|
GREndPathNodeBuilderImpl Builder(Blk, Pred, this);
|
|
|
|
ProcessEndPath(Builder);
|
2008-01-15 07:24:37 +08:00
|
|
|
|
|
|
|
// This path is done. Don't enqueue any more nodes.
|
|
|
|
return;
|
|
|
|
}
|
2008-03-01 04:27:50 +08:00
|
|
|
|
|
|
|
// FIXME: Should we allow ProcessBlockEntrance to also manipulate state?
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2008-03-01 04:27:50 +08:00
|
|
|
if (ProcessBlockEntrance(Blk, Pred->State, WList->getBlockCounter()))
|
|
|
|
GenerateNode(BlockEntrance(Blk), Pred->State, Pred);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRCoreEngineImpl::HandleBlockEntrance(const BlockEntrance& L,
|
2008-03-06 03:08:15 +08:00
|
|
|
ExplodedNodeImpl* Pred) {
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2008-02-13 02:08:17 +08:00
|
|
|
// Increment the block counter.
|
|
|
|
GRBlockCounter Counter = WList->getBlockCounter();
|
|
|
|
Counter = BCounterFactory.IncrementCount(Counter, L.getBlock()->getBlockID());
|
|
|
|
WList->setBlockCounter(Counter);
|
|
|
|
|
|
|
|
// Process the entrance of the block.
|
2008-01-15 07:24:37 +08:00
|
|
|
if (Stmt* S = L.getFirstStmt()) {
|
2008-01-30 06:11:49 +08:00
|
|
|
GRStmtNodeBuilderImpl Builder(L.getBlock(), 0, Pred, this);
|
2008-01-15 07:24:37 +08:00
|
|
|
ProcessStmt(S, Builder);
|
|
|
|
}
|
2008-01-15 08:24:08 +08:00
|
|
|
else
|
|
|
|
HandleBlockExit(L.getBlock(), Pred);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRCoreEngineImpl::HandleBlockExit(CFGBlock * B, ExplodedNodeImpl* Pred) {
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2008-01-30 06:56:11 +08:00
|
|
|
if (Stmt* Term = B->getTerminator()) {
|
|
|
|
switch (Term->getStmtClass()) {
|
|
|
|
default:
|
|
|
|
assert(false && "Analysis for this terminator not implemented.");
|
|
|
|
break;
|
2008-02-13 05:51:20 +08:00
|
|
|
|
|
|
|
case Stmt::BinaryOperatorClass: // '&&' and '||'
|
|
|
|
HandleBranch(cast<BinaryOperator>(Term)->getLHS(), Term, B, Pred);
|
|
|
|
return;
|
2008-01-30 06:56:11 +08:00
|
|
|
|
2008-02-05 08:26:40 +08:00
|
|
|
case Stmt::ConditionalOperatorClass:
|
|
|
|
HandleBranch(cast<ConditionalOperator>(Term)->getCond(), Term, B, Pred);
|
2008-02-13 05:51:20 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// FIXME: Use constant-folding in CFG construction to simplify this
|
|
|
|
// case.
|
2008-02-05 08:26:40 +08:00
|
|
|
|
|
|
|
case Stmt::ChooseExprClass:
|
|
|
|
HandleBranch(cast<ChooseExpr>(Term)->getCond(), Term, B, Pred);
|
2008-02-13 05:51:20 +08:00
|
|
|
return;
|
2008-02-05 08:26:40 +08:00
|
|
|
|
2008-02-13 05:51:20 +08:00
|
|
|
case Stmt::DoStmtClass:
|
|
|
|
HandleBranch(cast<DoStmt>(Term)->getCond(), Term, B, Pred);
|
|
|
|
return;
|
2008-01-30 06:56:11 +08:00
|
|
|
|
|
|
|
case Stmt::ForStmtClass:
|
|
|
|
HandleBranch(cast<ForStmt>(Term)->getCond(), Term, B, Pred);
|
2008-02-13 05:51:20 +08:00
|
|
|
return;
|
2008-02-14 00:56:51 +08:00
|
|
|
|
|
|
|
case Stmt::ContinueStmtClass:
|
|
|
|
case Stmt::BreakStmtClass:
|
|
|
|
case Stmt::GotoStmtClass:
|
2008-01-30 06:56:11 +08:00
|
|
|
break;
|
|
|
|
|
2008-02-13 05:51:20 +08:00
|
|
|
case Stmt::IfStmtClass:
|
|
|
|
HandleBranch(cast<IfStmt>(Term)->getCond(), Term, B, Pred);
|
|
|
|
return;
|
2008-02-13 08:24:44 +08:00
|
|
|
|
|
|
|
case Stmt::IndirectGotoStmtClass: {
|
|
|
|
// Only 1 successor: the indirect goto dispatch block.
|
|
|
|
assert (B->succ_size() == 1);
|
|
|
|
|
|
|
|
GRIndirectGotoNodeBuilderImpl
|
|
|
|
builder(Pred, B, cast<IndirectGotoStmt>(Term)->getTarget(),
|
|
|
|
*(B->succ_begin()), this);
|
|
|
|
|
|
|
|
ProcessIndirectGoto(builder);
|
|
|
|
return;
|
|
|
|
}
|
2008-02-13 05:51:20 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
case Stmt::SwitchStmtClass: {
|
|
|
|
GRSwitchNodeBuilderImpl builder(Pred, B,
|
|
|
|
cast<SwitchStmt>(Term)->getCond(),
|
|
|
|
this);
|
|
|
|
|
|
|
|
ProcessSwitch(builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-30 06:56:11 +08:00
|
|
|
case Stmt::WhileStmtClass:
|
|
|
|
HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred);
|
2008-02-13 05:51:20 +08:00
|
|
|
return;
|
2008-01-30 06:56:11 +08:00
|
|
|
}
|
|
|
|
}
|
2008-02-13 05:51:20 +08:00
|
|
|
|
|
|
|
assert (B->succ_size() == 1 &&
|
|
|
|
"Blocks with no terminator should have at most 1 successor.");
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2008-02-13 05:51:20 +08:00
|
|
|
GenerateNode(BlockEdge(getCFG(),B,*(B->succ_begin())), Pred->State, Pred);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRCoreEngineImpl::HandleBranch(Expr* Cond, Stmt* Term, CFGBlock * B,
|
2008-01-30 06:56:11 +08:00
|
|
|
ExplodedNodeImpl* Pred) {
|
|
|
|
assert (B->succ_size() == 2);
|
|
|
|
|
2008-02-13 02:08:17 +08:00
|
|
|
GRBranchNodeBuilderImpl Builder(B, *(B->succ_begin()), *(B->succ_begin()+1),
|
2008-01-30 06:56:11 +08:00
|
|
|
Pred, this);
|
|
|
|
|
|
|
|
ProcessBranch(Cond, Term, Builder);
|
|
|
|
}
|
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRCoreEngineImpl::HandlePostStmt(const PostStmt& L, CFGBlock* B,
|
2008-01-15 07:24:37 +08:00
|
|
|
unsigned StmtIdx, ExplodedNodeImpl* Pred) {
|
|
|
|
|
|
|
|
assert (!B->empty());
|
|
|
|
|
2008-01-15 08:24:08 +08:00
|
|
|
if (StmtIdx == B->size())
|
|
|
|
HandleBlockExit(B, Pred);
|
2008-01-15 07:24:37 +08:00
|
|
|
else {
|
2008-01-30 06:11:49 +08:00
|
|
|
GRStmtNodeBuilderImpl Builder(B, StmtIdx, Pred, this);
|
2008-01-17 06:13:19 +08:00
|
|
|
ProcessStmt((*B)[StmtIdx], Builder);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef llvm::DenseMap<Stmt*,Stmt*> ParentMapTy;
|
|
|
|
/// PopulateParentMap - Recurse the AST starting at 'Parent' and add the
|
|
|
|
/// mappings between child and parent to ParentMap.
|
|
|
|
static void PopulateParentMap(Stmt* Parent, ParentMapTy& M) {
|
|
|
|
for (Stmt::child_iterator I=Parent->child_begin(),
|
|
|
|
E=Parent->child_end(); I!=E; ++I) {
|
|
|
|
|
|
|
|
assert (M.find(*I) == M.end());
|
|
|
|
M[*I] = Parent;
|
|
|
|
PopulateParentMap(*I, M);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GenerateNode - Utility method to generate nodes, hook up successors,
|
|
|
|
/// and add nodes to the worklist.
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRCoreEngineImpl::GenerateNode(const ProgramPoint& Loc, void* State,
|
2008-01-15 07:24:37 +08:00
|
|
|
ExplodedNodeImpl* Pred) {
|
|
|
|
|
|
|
|
bool IsNew;
|
|
|
|
ExplodedNodeImpl* Node = G->getNodeImpl(Loc, State, &IsNew);
|
|
|
|
|
|
|
|
if (Pred)
|
|
|
|
Node->addPredecessor(Pred); // Link 'Node' with its predecessor.
|
|
|
|
else {
|
|
|
|
assert (IsNew);
|
|
|
|
G->addRoot(Node); // 'Node' has no predecessor. Make it a root.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only add 'Node' to the worklist if it was freshly generated.
|
2008-02-13 02:08:17 +08:00
|
|
|
if (IsNew) WList->Enqueue(Node);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
|
2008-01-30 06:11:49 +08:00
|
|
|
GRStmtNodeBuilderImpl::GRStmtNodeBuilderImpl(CFGBlock* b, unsigned idx,
|
2008-02-14 01:41:41 +08:00
|
|
|
ExplodedNodeImpl* N, GRCoreEngineImpl* e)
|
2008-03-10 12:45:00 +08:00
|
|
|
: Eng(*e), B(*b), Idx(idx), Pred(N), LastNode(N), Populated(false) {
|
2008-01-15 07:24:37 +08:00
|
|
|
Deferred.insert(N);
|
|
|
|
}
|
|
|
|
|
2008-01-30 06:11:49 +08:00
|
|
|
GRStmtNodeBuilderImpl::~GRStmtNodeBuilderImpl() {
|
2008-01-15 07:24:37 +08:00
|
|
|
for (DeferredTy::iterator I=Deferred.begin(), E=Deferred.end(); I!=E; ++I)
|
2008-01-31 07:03:39 +08:00
|
|
|
if (!(*I)->isSink())
|
2008-01-15 07:24:37 +08:00
|
|
|
GenerateAutoTransition(*I);
|
|
|
|
}
|
|
|
|
|
2008-01-30 06:11:49 +08:00
|
|
|
void GRStmtNodeBuilderImpl::GenerateAutoTransition(ExplodedNodeImpl* N) {
|
2008-01-31 07:03:39 +08:00
|
|
|
assert (!N->isSink());
|
2008-01-15 07:24:37 +08:00
|
|
|
|
|
|
|
PostStmt Loc(getStmt());
|
|
|
|
|
|
|
|
if (Loc == N->getLocation()) {
|
|
|
|
// Note: 'N' should be a fresh node because otherwise it shouldn't be
|
|
|
|
// a member of Deferred.
|
|
|
|
Eng.WList->Enqueue(N, B, Idx+1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsNew;
|
|
|
|
ExplodedNodeImpl* Succ = Eng.G->getNodeImpl(Loc, N->State, &IsNew);
|
|
|
|
Succ->addPredecessor(N);
|
|
|
|
|
|
|
|
if (IsNew)
|
|
|
|
Eng.WList->Enqueue(Succ, B, Idx+1);
|
|
|
|
}
|
|
|
|
|
2008-01-30 06:11:49 +08:00
|
|
|
ExplodedNodeImpl* GRStmtNodeBuilderImpl::generateNodeImpl(Stmt* S, void* State,
|
2008-01-15 07:24:37 +08:00
|
|
|
ExplodedNodeImpl* Pred) {
|
|
|
|
|
|
|
|
bool IsNew;
|
|
|
|
ExplodedNodeImpl* N = Eng.G->getNodeImpl(PostStmt(S), State, &IsNew);
|
|
|
|
N->addPredecessor(Pred);
|
|
|
|
Deferred.erase(Pred);
|
|
|
|
|
|
|
|
HasGeneratedNode = true;
|
|
|
|
|
|
|
|
if (IsNew) {
|
|
|
|
Deferred.insert(N);
|
|
|
|
LastNode = N;
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
|
|
|
LastNode = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-01-30 06:56:11 +08:00
|
|
|
|
2008-01-31 07:03:39 +08:00
|
|
|
ExplodedNodeImpl* GRBranchNodeBuilderImpl::generateNodeImpl(void* State,
|
|
|
|
bool branch) {
|
2008-01-30 06:56:11 +08:00
|
|
|
bool IsNew;
|
|
|
|
|
|
|
|
ExplodedNodeImpl* Succ =
|
|
|
|
Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, branch ? DstT : DstF),
|
|
|
|
State, &IsNew);
|
|
|
|
|
|
|
|
Succ->addPredecessor(Pred);
|
|
|
|
|
2008-01-30 07:32:35 +08:00
|
|
|
if (branch) GeneratedTrue = true;
|
|
|
|
else GeneratedFalse = true;
|
|
|
|
|
2008-01-31 07:03:39 +08:00
|
|
|
if (IsNew) {
|
2008-01-31 07:24:39 +08:00
|
|
|
Deferred.push_back(Succ);
|
2008-01-31 07:03:39 +08:00
|
|
|
return Succ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2008-01-30 06:56:11 +08:00
|
|
|
}
|
2008-01-30 07:32:35 +08:00
|
|
|
|
|
|
|
GRBranchNodeBuilderImpl::~GRBranchNodeBuilderImpl() {
|
|
|
|
if (!GeneratedTrue) generateNodeImpl(Pred->State, true);
|
|
|
|
if (!GeneratedFalse) generateNodeImpl(Pred->State, false);
|
2008-01-31 07:24:39 +08:00
|
|
|
|
|
|
|
for (DeferredTy::iterator I=Deferred.begin(), E=Deferred.end(); I!=E; ++I)
|
2008-02-13 02:08:17 +08:00
|
|
|
if (!(*I)->isSink()) Eng.WList->Enqueue(*I);
|
2008-01-30 07:32:35 +08:00
|
|
|
}
|
2008-02-13 08:24:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
ExplodedNodeImpl*
|
2008-02-14 01:27:37 +08:00
|
|
|
GRIndirectGotoNodeBuilderImpl::generateNodeImpl(const Iterator& I,
|
2008-02-13 08:24:44 +08:00
|
|
|
void* St,
|
|
|
|
bool isSink) {
|
|
|
|
bool IsNew;
|
|
|
|
|
|
|
|
ExplodedNodeImpl* Succ =
|
2008-02-14 01:27:37 +08:00
|
|
|
Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, I.getBlock(), true),
|
2008-02-13 08:24:44 +08:00
|
|
|
St, &IsNew);
|
|
|
|
|
|
|
|
Succ->addPredecessor(Pred);
|
|
|
|
|
|
|
|
if (IsNew) {
|
|
|
|
|
|
|
|
if (isSink)
|
|
|
|
Succ->markAsSink();
|
|
|
|
else
|
|
|
|
Eng.WList->Enqueue(Succ);
|
|
|
|
|
|
|
|
return Succ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-02-14 07:08:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
ExplodedNodeImpl*
|
|
|
|
GRSwitchNodeBuilderImpl::generateCaseStmtNodeImpl(const Iterator& I, void* St) {
|
|
|
|
|
|
|
|
bool IsNew;
|
|
|
|
|
|
|
|
ExplodedNodeImpl* Succ = Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src,
|
|
|
|
I.getBlock()),
|
|
|
|
St, &IsNew);
|
|
|
|
Succ->addPredecessor(Pred);
|
|
|
|
|
|
|
|
if (IsNew) {
|
|
|
|
Eng.WList->Enqueue(Succ);
|
|
|
|
return Succ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExplodedNodeImpl*
|
|
|
|
GRSwitchNodeBuilderImpl::generateDefaultCaseNodeImpl(void* St, bool isSink) {
|
|
|
|
|
|
|
|
// Get the block for the default case.
|
|
|
|
assert (Src->succ_rbegin() != Src->succ_rend());
|
|
|
|
CFGBlock* DefaultBlock = *Src->succ_rbegin();
|
|
|
|
|
|
|
|
bool IsNew;
|
|
|
|
|
|
|
|
ExplodedNodeImpl* Succ = Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src,
|
|
|
|
DefaultBlock),
|
|
|
|
St, &IsNew);
|
|
|
|
Succ->addPredecessor(Pred);
|
|
|
|
|
|
|
|
if (IsNew) {
|
|
|
|
if (isSink)
|
|
|
|
Succ->markAsSink();
|
|
|
|
else
|
|
|
|
Eng.WList->Enqueue(Succ);
|
|
|
|
|
|
|
|
return Succ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-04-12 06:03:04 +08:00
|
|
|
|
|
|
|
GREndPathNodeBuilderImpl::~GREndPathNodeBuilderImpl() {
|
|
|
|
// Auto-generate an EOP node if one has not been generated.
|
|
|
|
if (!HasGeneratedNode) generateNodeImpl(Pred->State);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExplodedNodeImpl* GREndPathNodeBuilderImpl::generateNodeImpl(void* State) {
|
|
|
|
HasGeneratedNode = true;
|
|
|
|
|
|
|
|
bool IsNew;
|
|
|
|
|
|
|
|
ExplodedNodeImpl* Node =
|
2008-04-17 06:30:40 +08:00
|
|
|
Eng.G->getNodeImpl(BlockEntrance(&B), State, &IsNew);
|
2008-04-12 06:03:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
Node->addPredecessor(Pred);
|
|
|
|
|
|
|
|
if (IsNew) {
|
|
|
|
Node->markAsSink();
|
|
|
|
Eng.G->addEndOfPath(Node);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Node;
|
|
|
|
}
|