opnsense-src/lib/Checker/GRCoreEngine.cpp

600 lines
17 KiB
C++
Raw Normal View History

2009-06-02 13:58:47 -04:00
//==- GRCoreEngine.cpp - Path-Sensitive Dataflow Engine ------------*- C++ -*-//
2009-10-14 14:03:49 -04:00
//
2009-06-02 13:58:47 -04: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.
//
//===----------------------------------------------------------------------===//
2010-02-16 04:31:36 -05:00
#include "clang/Checker/PathSensitive/GRCoreEngine.h"
#include "clang/Checker/PathSensitive/GRExprEngine.h"
2009-06-02 13:58:47 -04:00
#include "clang/AST/Expr.h"
#include "llvm/Support/Casting.h"
#include "llvm/ADT/DenseMap.h"
#include <vector>
#include <queue>
using llvm::cast;
using llvm::isa;
using namespace clang;
//===----------------------------------------------------------------------===//
// Worklist classes for exploration of reachable states.
//===----------------------------------------------------------------------===//
namespace {
2009-12-01 06:08:04 -05:00
class DFS : public GRWorkList {
2009-06-02 13:58:47 -04:00
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;
}
};
2009-10-14 14:03:49 -04:00
2009-12-01 06:08:04 -05:00
class BFS : public GRWorkList {
2009-06-02 13:58:47 -04:00
std::queue<GRWorkListUnit> Queue;
public:
virtual bool hasWork() const {
return !Queue.empty();
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
virtual void Enqueue(const GRWorkListUnit& U) {
Queue.push(U);
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
virtual GRWorkListUnit Dequeue() {
// Don't use const reference. The subsequent pop_back() might make it
// unsafe.
2009-10-14 14:03:49 -04:00
GRWorkListUnit U = Queue.front();
2009-06-02 13:58:47 -04:00
Queue.pop();
return U;
}
};
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
} // end anonymous namespace
// 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() {}
GRWorkList *GRWorkList::MakeDFS() { return new DFS(); }
GRWorkList *GRWorkList::MakeBFS() { return new BFS(); }
namespace {
2009-12-01 06:08:04 -05:00
class BFSBlockDFSContents : public GRWorkList {
2009-06-02 13:58:47 -04:00
std::queue<GRWorkListUnit> Queue;
llvm::SmallVector<GRWorkListUnit,20> Stack;
public:
virtual bool hasWork() const {
return !Queue.empty() || !Stack.empty();
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
virtual void Enqueue(const GRWorkListUnit& U) {
if (isa<BlockEntrance>(U.getNode()->getLocation()))
Queue.push(U);
else
Stack.push_back(U);
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
virtual GRWorkListUnit Dequeue() {
// Process all basic blocks to completion.
if (!Stack.empty()) {
const GRWorkListUnit& U = Stack.back();
Stack.pop_back(); // This technically "invalidates" U, but we are fine.
return U;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
assert(!Queue.empty());
// Don't use const reference. The subsequent pop_back() might make it
// unsafe.
2009-10-14 14:03:49 -04:00
GRWorkListUnit U = Queue.front();
2009-06-02 13:58:47 -04:00
Queue.pop();
2009-10-14 14:03:49 -04:00
return U;
2009-06-02 13:58:47 -04:00
}
};
} // end anonymous namespace
GRWorkList* GRWorkList::MakeBFSBlockDFSContents() {
return new BFSBlockDFSContents();
}
//===----------------------------------------------------------------------===//
// Core analysis engine.
//===----------------------------------------------------------------------===//
2009-10-14 14:03:49 -04:00
void GRCoreEngine::ProcessEndPath(GREndPathNodeBuilder& Builder) {
SubEngine.ProcessEndPath(Builder);
}
2010-01-01 05:34:51 -05:00
void GRCoreEngine::ProcessStmt(CFGElement E, GRStmtNodeBuilder& Builder) {
SubEngine.ProcessStmt(E, Builder);
2009-10-14 14:03:49 -04:00
}
bool GRCoreEngine::ProcessBlockEntrance(CFGBlock* Blk, const GRState* State,
GRBlockCounter BC) {
return SubEngine.ProcessBlockEntrance(Blk, State, BC);
}
void GRCoreEngine::ProcessBranch(Stmt* Condition, Stmt* Terminator,
GRBranchNodeBuilder& Builder) {
SubEngine.ProcessBranch(Condition, Terminator, Builder);
}
void GRCoreEngine::ProcessIndirectGoto(GRIndirectGotoNodeBuilder& Builder) {
SubEngine.ProcessIndirectGoto(Builder);
}
void GRCoreEngine::ProcessSwitch(GRSwitchNodeBuilder& Builder) {
SubEngine.ProcessSwitch(Builder);
}
2009-06-02 13:58:47 -04:00
/// ExecuteWorkList - Run the worklist algorithm for a maximum number of steps.
2009-10-14 14:03:49 -04:00
bool GRCoreEngine::ExecuteWorkList(const LocationContext *L, unsigned Steps) {
2009-06-02 13:58:47 -04:00
if (G->num_roots() == 0) { // Initialize the analysis by constructing
// the root if none exists.
2009-10-14 14:03:49 -04:00
CFGBlock* Entry = &(L->getCFG()->getEntry());
assert (Entry->empty() &&
2009-06-02 13:58:47 -04:00
"Entry block must be empty.");
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
assert (Entry->succ_size() == 1 &&
"Entry block must have 1 successor.");
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
// Get the solitary successor.
2009-10-14 14:03:49 -04:00
CFGBlock* Succ = *(Entry->succ_begin());
2009-06-02 13:58:47 -04:00
// Construct an edge representing the
// starting location in the function.
2009-10-14 14:03:49 -04:00
BlockEdge StartLoc(Entry, Succ, L);
2009-06-02 13:58:47 -04:00
// Set the current block counter to being empty.
WList->setBlockCounter(BCounterFactory.GetEmptyCounter());
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
// Generate the root.
2009-10-14 14:03:49 -04:00
GenerateNode(StartLoc, getInitialState(L), 0);
2009-06-02 13:58:47 -04:00
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
while (Steps && WList->hasWork()) {
--Steps;
const GRWorkListUnit& WU = WList->Dequeue();
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
// Set the current block counter.
WList->setBlockCounter(WU.getBlockCounter());
// Retrieve the node.
2009-10-14 14:03:49 -04:00
ExplodedNode* Node = WU.getNode();
2009-06-02 13:58:47 -04:00
// Dispatch on the location type.
switch (Node->getLocation().getKind()) {
case ProgramPoint::BlockEdgeKind:
HandleBlockEdge(cast<BlockEdge>(Node->getLocation()), Node);
break;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case ProgramPoint::BlockEntranceKind:
HandleBlockEntrance(cast<BlockEntrance>(Node->getLocation()), Node);
break;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case ProgramPoint::BlockExitKind:
assert (false && "BlockExit location never occur in forward analysis.");
break;
default:
assert(isa<PostStmt>(Node->getLocation()));
HandlePostStmt(cast<PostStmt>(Node->getLocation()), WU.getBlock(),
WU.getIndex(), Node);
2009-10-14 14:03:49 -04:00
break;
2009-06-02 13:58:47 -04:00
}
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
return WList->hasWork();
}
2009-10-14 14:03:49 -04:00
void GRCoreEngine::HandleBlockEdge(const BlockEdge& L, ExplodedNode* Pred) {
2009-06-02 13:58:47 -04:00
CFGBlock* Blk = L.getDst();
2009-10-14 14:03:49 -04:00
// Check if we are entering the EXIT block.
2010-01-01 05:34:51 -05:00
if (Blk == &(L.getLocationContext()->getCFG()->getExit())) {
2009-10-14 14:03:49 -04:00
2010-01-01 05:34:51 -05:00
assert (L.getLocationContext()->getCFG()->getExit().size() == 0
2009-06-02 13:58:47 -04:00
&& "EXIT block cannot contain Stmts.");
// Process the final state transition.
2009-10-14 14:03:49 -04:00
GREndPathNodeBuilder Builder(Blk, Pred, this);
2009-06-02 13:58:47 -04:00
ProcessEndPath(Builder);
// This path is done. Don't enqueue any more nodes.
return;
}
// FIXME: Should we allow ProcessBlockEntrance to also manipulate state?
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
if (ProcessBlockEntrance(Blk, Pred->State, WList->getBlockCounter()))
2009-10-14 14:03:49 -04:00
GenerateNode(BlockEntrance(Blk, Pred->getLocationContext()), Pred->State, Pred);
2009-06-02 13:58:47 -04:00
}
2009-10-14 14:03:49 -04:00
void GRCoreEngine::HandleBlockEntrance(const BlockEntrance& L,
ExplodedNode* Pred) {
2009-06-02 13:58:47 -04:00
// Increment the block counter.
GRBlockCounter Counter = WList->getBlockCounter();
Counter = BCounterFactory.IncrementCount(Counter, L.getBlock()->getBlockID());
WList->setBlockCounter(Counter);
2009-10-14 14:03:49 -04:00
// Process the entrance of the block.
2010-01-01 05:34:51 -05:00
if (CFGElement E = L.getFirstElement()) {
2009-10-14 14:03:49 -04:00
GRStmtNodeBuilder Builder(L.getBlock(), 0, Pred, this,
SubEngine.getStateManager());
2010-01-01 05:34:51 -05:00
ProcessStmt(E, Builder);
2009-06-02 13:58:47 -04:00
}
2009-10-14 14:03:49 -04:00
else
2009-06-02 13:58:47 -04:00
HandleBlockExit(L.getBlock(), Pred);
}
2009-10-14 14:03:49 -04:00
void GRCoreEngine::HandleBlockExit(CFGBlock * B, ExplodedNode* Pred) {
2009-06-02 13:58:47 -04:00
if (Stmt* Term = B->getTerminator()) {
switch (Term->getStmtClass()) {
default:
assert(false && "Analysis for this terminator not implemented.");
break;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::BinaryOperatorClass: // '&&' and '||'
HandleBranch(cast<BinaryOperator>(Term)->getLHS(), Term, B, Pred);
return;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::ConditionalOperatorClass:
HandleBranch(cast<ConditionalOperator>(Term)->getCond(), Term, B, Pred);
return;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
// FIXME: Use constant-folding in CFG construction to simplify this
// case.
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::ChooseExprClass:
HandleBranch(cast<ChooseExpr>(Term)->getCond(), Term, B, Pred);
return;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::DoStmtClass:
HandleBranch(cast<DoStmt>(Term)->getCond(), Term, B, Pred);
return;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::ForStmtClass:
HandleBranch(cast<ForStmt>(Term)->getCond(), Term, B, Pred);
return;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::ContinueStmtClass:
case Stmt::BreakStmtClass:
2009-10-14 14:03:49 -04:00
case Stmt::GotoStmtClass:
2009-06-02 13:58:47 -04:00
break;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::IfStmtClass:
HandleBranch(cast<IfStmt>(Term)->getCond(), Term, B, Pred);
return;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::IndirectGotoStmtClass: {
// Only 1 successor: the indirect goto dispatch block.
assert (B->succ_size() == 1);
2009-10-14 14:03:49 -04:00
GRIndirectGotoNodeBuilder
2009-06-02 13:58:47 -04:00
builder(Pred, B, cast<IndirectGotoStmt>(Term)->getTarget(),
*(B->succ_begin()), this);
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
ProcessIndirectGoto(builder);
return;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::ObjCForCollectionStmtClass: {
// In the case of ObjCForCollectionStmt, it appears twice in a CFG:
//
// (1) inside a basic block, which represents the binding of the
// 'element' variable to a value.
// (2) in a terminator, which represents the branch.
//
// For (1), subengines will bind a value (i.e., 0 or 1) indicating
// whether or not collection contains any more elements. We cannot
// just test to see if the element is nil because a container can
// contain nil elements.
HandleBranch(Term, Term, B, Pred);
return;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::SwitchStmtClass: {
2009-10-14 14:03:49 -04:00
GRSwitchNodeBuilder builder(Pred, B, cast<SwitchStmt>(Term)->getCond(),
this);
2009-06-02 13:58:47 -04:00
ProcessSwitch(builder);
return;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
case Stmt::WhileStmtClass:
HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred);
return;
}
}
assert (B->succ_size() == 1 &&
"Blocks with no terminator should have at most 1 successor.");
2009-10-14 14:03:49 -04:00
GenerateNode(BlockEdge(B, *(B->succ_begin()), Pred->getLocationContext()),
Pred->State, Pred);
2009-06-02 13:58:47 -04:00
}
2009-10-14 14:03:49 -04:00
void GRCoreEngine::HandleBranch(Stmt* Cond, Stmt* Term, CFGBlock * B,
ExplodedNode* Pred) {
2009-06-02 13:58:47 -04:00
assert (B->succ_size() == 2);
2009-10-14 14:03:49 -04:00
GRBranchNodeBuilder Builder(B, *(B->succ_begin()), *(B->succ_begin()+1),
Pred, this);
2009-06-02 13:58:47 -04:00
ProcessBranch(Cond, Term, Builder);
}
2009-10-14 14:03:49 -04:00
void GRCoreEngine::HandlePostStmt(const PostStmt& L, CFGBlock* B,
unsigned StmtIdx, ExplodedNode* Pred) {
2009-06-02 13:58:47 -04:00
assert (!B->empty());
if (StmtIdx == B->size())
HandleBlockExit(B, Pred);
else {
2009-10-14 14:03:49 -04:00
GRStmtNodeBuilder Builder(B, StmtIdx, Pred, this,
SubEngine.getStateManager());
2009-06-02 13:58:47 -04:00
ProcessStmt((*B)[StmtIdx], Builder);
}
}
/// GenerateNode - Utility method to generate nodes, hook up successors,
/// and add nodes to the worklist.
2009-10-14 14:03:49 -04:00
void GRCoreEngine::GenerateNode(const ProgramPoint& Loc,
const GRState* State, ExplodedNode* Pred) {
2009-06-02 13:58:47 -04:00
bool IsNew;
2009-10-14 14:03:49 -04:00
ExplodedNode* Node = G->getNode(Loc, State, &IsNew);
if (Pred)
Node->addPredecessor(Pred, *G); // Link 'Node' with its predecessor.
2009-06-02 13:58:47 -04:00
else {
assert (IsNew);
G->addRoot(Node); // 'Node' has no predecessor. Make it a root.
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
// Only add 'Node' to the worklist if it was freshly generated.
if (IsNew) WList->Enqueue(Node);
}
2009-10-14 14:03:49 -04:00
GRStmtNodeBuilder::GRStmtNodeBuilder(CFGBlock* b, unsigned idx,
ExplodedNode* N, GRCoreEngine* e,
GRStateManager &mgr)
: Eng(*e), B(*b), Idx(idx), Pred(N), LastNode(N), Mgr(mgr), Auditor(0),
PurgingDeadSymbols(false), BuildSinks(false), HasGeneratedNode(false),
PointKind(ProgramPoint::PostStmtKind), Tag(0) {
2009-06-02 13:58:47 -04:00
Deferred.insert(N);
2009-10-14 14:03:49 -04:00
CleanedState = getLastNode()->getState();
2009-06-02 13:58:47 -04:00
}
2009-10-14 14:03:49 -04:00
GRStmtNodeBuilder::~GRStmtNodeBuilder() {
2009-06-02 13:58:47 -04:00
for (DeferredTy::iterator I=Deferred.begin(), E=Deferred.end(); I!=E; ++I)
if (!(*I)->isSink())
GenerateAutoTransition(*I);
}
2009-10-14 14:03:49 -04:00
void GRStmtNodeBuilder::GenerateAutoTransition(ExplodedNode* N) {
2009-06-02 13:58:47 -04:00
assert (!N->isSink());
2009-10-14 14:03:49 -04:00
PostStmt Loc(getStmt(), N->getLocationContext());
2009-06-02 13:58:47 -04:00
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;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
bool IsNew;
2009-10-14 14:03:49 -04:00
ExplodedNode* Succ = Eng.G->getNode(Loc, N->State, &IsNew);
Succ->addPredecessor(N, *Eng.G);
2009-06-02 13:58:47 -04:00
if (IsNew)
Eng.WList->Enqueue(Succ, B, Idx+1);
}
2009-11-18 09:59:57 -05:00
static ProgramPoint GetProgramPoint(const Stmt *S, ProgramPoint::Kind K,
const LocationContext *LC, const void *tag){
2009-06-02 13:58:47 -04:00
switch (K) {
default:
2009-11-18 09:59:57 -05:00
assert(false && "Unhandled ProgramPoint kind");
case ProgramPoint::PreStmtKind:
return PreStmt(S, LC, tag);
2009-06-02 13:58:47 -04:00
case ProgramPoint::PostStmtKind:
2009-11-18 09:59:57 -05:00
return PostStmt(S, LC, tag);
case ProgramPoint::PreLoadKind:
return PreLoad(S, LC, tag);
2009-06-02 13:58:47 -04:00
case ProgramPoint::PostLoadKind:
2009-11-18 09:59:57 -05:00
return PostLoad(S, LC, tag);
case ProgramPoint::PreStoreKind:
return PreStore(S, LC, tag);
2009-06-02 13:58:47 -04:00
case ProgramPoint::PostStoreKind:
2009-11-18 09:59:57 -05:00
return PostStore(S, LC, tag);
2009-06-02 13:58:47 -04:00
case ProgramPoint::PostLValueKind:
2009-11-18 09:59:57 -05:00
return PostLValue(S, LC, tag);
2009-06-02 13:58:47 -04:00
case ProgramPoint::PostPurgeDeadSymbolsKind:
2009-11-18 09:59:57 -05:00
return PostPurgeDeadSymbols(S, LC, tag);
2009-06-02 13:58:47 -04:00
}
}
2009-10-14 14:03:49 -04:00
ExplodedNode*
2009-11-18 09:59:57 -05:00
GRStmtNodeBuilder::generateNodeInternal(const Stmt* S, const GRState* state,
2009-10-14 14:03:49 -04:00
ExplodedNode* Pred,
2009-06-02 13:58:47 -04:00
ProgramPoint::Kind K,
const void *tag) {
2009-11-18 09:59:57 -05:00
2010-01-01 05:34:51 -05:00
const ProgramPoint &L = GetProgramPoint(S, K, Pred->getLocationContext(),tag);
2009-11-18 09:59:57 -05:00
return generateNodeInternal(L, state, Pred);
2009-06-02 13:58:47 -04:00
}
2009-10-14 14:03:49 -04:00
ExplodedNode*
GRStmtNodeBuilder::generateNodeInternal(const ProgramPoint &Loc,
const GRState* State,
ExplodedNode* Pred) {
2009-06-02 13:58:47 -04:00
bool IsNew;
2009-10-14 14:03:49 -04:00
ExplodedNode* N = Eng.G->getNode(Loc, State, &IsNew);
N->addPredecessor(Pred, *Eng.G);
2009-06-02 13:58:47 -04:00
Deferred.erase(Pred);
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
if (IsNew) {
Deferred.insert(N);
LastNode = N;
return N;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
LastNode = NULL;
2009-10-14 14:03:49 -04:00
return NULL;
2009-06-02 13:58:47 -04:00
}
2009-10-14 14:03:49 -04:00
ExplodedNode* GRBranchNodeBuilder::generateNode(const GRState* State,
bool branch) {
// If the branch has been marked infeasible we should not generate a node.
if (!isFeasible(branch))
return NULL;
2009-06-02 13:58:47 -04:00
bool IsNew;
2009-10-14 14:03:49 -04:00
ExplodedNode* Succ =
Eng.G->getNode(BlockEdge(Src,branch ? DstT:DstF,Pred->getLocationContext()),
State, &IsNew);
Succ->addPredecessor(Pred, *Eng.G);
if (branch)
GeneratedTrue = true;
else
GeneratedFalse = true;
2009-06-02 13:58:47 -04:00
if (IsNew) {
Deferred.push_back(Succ);
return Succ;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
return NULL;
}
2009-10-14 14:03:49 -04:00
GRBranchNodeBuilder::~GRBranchNodeBuilder() {
if (!GeneratedTrue) generateNode(Pred->State, true);
if (!GeneratedFalse) generateNode(Pred->State, false);
2009-06-02 13:58:47 -04:00
for (DeferredTy::iterator I=Deferred.begin(), E=Deferred.end(); I!=E; ++I)
if (!(*I)->isSink()) Eng.WList->Enqueue(*I);
}
2009-10-14 14:03:49 -04:00
ExplodedNode*
GRIndirectGotoNodeBuilder::generateNode(const iterator& I, const GRState* St,
bool isSink) {
2009-06-02 13:58:47 -04:00
bool IsNew;
2009-10-14 14:03:49 -04:00
ExplodedNode* Succ = Eng.G->getNode(BlockEdge(Src, I.getBlock(),
Pred->getLocationContext()), St, &IsNew);
Succ->addPredecessor(Pred, *Eng.G);
2009-06-02 13:58:47 -04:00
if (IsNew) {
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
if (isSink)
Succ->markAsSink();
else
Eng.WList->Enqueue(Succ);
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
return Succ;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
return NULL;
}
2009-10-14 14:03:49 -04:00
ExplodedNode*
GRSwitchNodeBuilder::generateCaseStmtNode(const iterator& I, const GRState* St){
2009-06-02 13:58:47 -04:00
bool IsNew;
2009-10-14 14:03:49 -04:00
ExplodedNode* Succ = Eng.G->getNode(BlockEdge(Src, I.getBlock(),
Pred->getLocationContext()), St, &IsNew);
Succ->addPredecessor(Pred, *Eng.G);
2009-06-02 13:58:47 -04:00
if (IsNew) {
Eng.WList->Enqueue(Succ);
return Succ;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
return NULL;
}
2009-10-14 14:03:49 -04:00
ExplodedNode*
GRSwitchNodeBuilder::generateDefaultCaseNode(const GRState* St, bool isSink) {
2009-06-02 13:58:47 -04:00
// Get the block for the default case.
assert (Src->succ_rbegin() != Src->succ_rend());
CFGBlock* DefaultBlock = *Src->succ_rbegin();
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
bool IsNew;
2009-10-14 14:03:49 -04:00
ExplodedNode* Succ = Eng.G->getNode(BlockEdge(Src, DefaultBlock,
Pred->getLocationContext()), St, &IsNew);
Succ->addPredecessor(Pred, *Eng.G);
2009-06-02 13:58:47 -04:00
if (IsNew) {
if (isSink)
Succ->markAsSink();
else
Eng.WList->Enqueue(Succ);
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
return Succ;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
return NULL;
}
2009-10-14 14:03:49 -04:00
GREndPathNodeBuilder::~GREndPathNodeBuilder() {
2009-06-02 13:58:47 -04:00
// Auto-generate an EOP node if one has not been generated.
2009-10-14 14:03:49 -04:00
if (!HasGeneratedNode) generateNode(Pred->State);
2009-06-02 13:58:47 -04:00
}
2009-10-14 14:03:49 -04:00
ExplodedNode*
GREndPathNodeBuilder::generateNode(const GRState* State, const void *tag,
ExplodedNode* P) {
HasGeneratedNode = true;
2009-06-02 13:58:47 -04:00
bool IsNew;
2009-10-14 14:03:49 -04:00
ExplodedNode* Node = Eng.G->getNode(BlockEntrance(&B,
Pred->getLocationContext(), tag), State, &IsNew);
Node->addPredecessor(P ? P : Pred, *Eng.G);
2009-06-02 13:58:47 -04:00
if (IsNew) {
Eng.G->addEndOfPath(Node);
return Node;
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
return NULL;
}