2010-12-23 02:53:44 +08:00
|
|
|
//==- CoreEngine.cpp - Path-Sensitive Dataflow Engine ------------*- C++ -*-//
|
2009-09-09 23:08:12 +08:00
|
|
|
//
|
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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-10 09:03:03 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h"
|
2008-01-15 07:24:37 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2014-08-07 18:42:17 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2011-10-11 06:36:31 +08:00
|
|
|
#include "clang/AST/StmtCXX.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
2012-03-17 07:24:13 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
2012-03-17 07:24:13 +08:00
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
using namespace clang;
|
2010-12-23 15:20:52 +08:00
|
|
|
using namespace ento;
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2014-04-22 11:17:02 +08:00
|
|
|
#define DEBUG_TYPE "CoreEngine"
|
|
|
|
|
2012-06-23 06:08:06 +08:00
|
|
|
STATISTIC(NumSteps,
|
|
|
|
"The # of steps executed.");
|
2012-03-17 07:24:13 +08:00
|
|
|
STATISTIC(NumReachedMaxSteps,
|
|
|
|
"The # of times we reached the max number of steps.");
|
2012-03-23 05:06:06 +08:00
|
|
|
STATISTIC(NumPathsExplored,
|
|
|
|
"The # of paths explored by the analyzer.");
|
2012-03-17 07:24:13 +08:00
|
|
|
|
2008-12-17 06:13:33 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Worklist classes for exploration of reachable states.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-20 21:23:58 +08:00
|
|
|
WorkList::Visitor::~Visitor() {}
|
2010-11-13 13:04:49 +08:00
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
namespace {
|
2010-12-23 02:53:44 +08:00
|
|
|
class DFS : public WorkList {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<WorkListUnit,20> Stack;
|
2008-01-15 07:24:37 +08:00
|
|
|
public:
|
2014-03-15 12:29:04 +08:00
|
|
|
bool hasWork() const override {
|
2008-01-15 07:24:37 +08:00
|
|
|
return !Stack.empty();
|
|
|
|
}
|
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
void enqueue(const WorkListUnit& U) override {
|
2008-01-15 07:24:37 +08:00
|
|
|
Stack.push_back(U);
|
|
|
|
}
|
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
WorkListUnit dequeue() override {
|
2008-01-15 07:24:37 +08:00
|
|
|
assert (!Stack.empty());
|
2010-12-23 02:53:44 +08:00
|
|
|
const WorkListUnit& U = Stack.back();
|
2008-01-15 07:24:37 +08:00
|
|
|
Stack.pop_back(); // This technically "invalidates" U, but we are fine.
|
|
|
|
return U;
|
|
|
|
}
|
2014-03-15 12:29:04 +08:00
|
|
|
|
|
|
|
bool visitItemsInWorkList(Visitor &V) override {
|
2011-07-23 18:55:15 +08:00
|
|
|
for (SmallVectorImpl<WorkListUnit>::iterator
|
2010-11-13 13:04:49 +08:00
|
|
|
I = Stack.begin(), E = Stack.end(); I != E; ++I) {
|
2011-01-11 10:34:50 +08:00
|
|
|
if (V.visit(*I))
|
2010-11-13 13:04:49 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-15 07:24:37 +08:00
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
class BFS : public WorkList {
|
|
|
|
std::deque<WorkListUnit> Queue;
|
2009-05-02 06:18:46 +08:00
|
|
|
public:
|
2014-03-15 12:29:04 +08:00
|
|
|
bool hasWork() const override {
|
2009-05-02 06:18:46 +08:00
|
|
|
return !Queue.empty();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
void enqueue(const WorkListUnit& U) override {
|
2012-06-29 08:33:10 +08:00
|
|
|
Queue.push_back(U);
|
2009-05-02 06:18:46 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
WorkListUnit dequeue() override {
|
2010-12-23 02:53:44 +08:00
|
|
|
WorkListUnit U = Queue.front();
|
2010-11-13 13:04:49 +08:00
|
|
|
Queue.pop_front();
|
2009-05-02 06:18:46 +08:00
|
|
|
return U;
|
|
|
|
}
|
2014-03-15 12:29:04 +08:00
|
|
|
|
|
|
|
bool visitItemsInWorkList(Visitor &V) override {
|
2010-12-23 02:53:44 +08:00
|
|
|
for (std::deque<WorkListUnit>::iterator
|
2010-11-13 13:04:49 +08:00
|
|
|
I = Queue.begin(), E = Queue.end(); I != E; ++I) {
|
2011-01-11 10:34:50 +08:00
|
|
|
if (V.visit(*I))
|
2010-11-13 13:04:49 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-02 06:18:46 +08:00
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
// Place the dstor for WorkList here because it contains virtual member
|
2008-01-17 02:18:48 +08:00
|
|
|
// functions, and we the code for the dstor generated in one compilation unit.
|
2015-10-20 21:23:58 +08:00
|
|
|
WorkList::~WorkList() {}
|
2008-01-17 02:18:48 +08:00
|
|
|
|
2011-01-11 10:34:50 +08:00
|
|
|
WorkList *WorkList::makeDFS() { return new DFS(); }
|
|
|
|
WorkList *WorkList::makeBFS() { return new BFS(); }
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2008-12-17 06:13:33 +08:00
|
|
|
namespace {
|
2010-12-23 02:53:44 +08:00
|
|
|
class BFSBlockDFSContents : public WorkList {
|
|
|
|
std::deque<WorkListUnit> Queue;
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<WorkListUnit,20> Stack;
|
2008-12-17 06:13:33 +08:00
|
|
|
public:
|
2014-03-15 12:29:04 +08:00
|
|
|
bool hasWork() const override {
|
2008-12-17 06:13:33 +08:00
|
|
|
return !Queue.empty() || !Stack.empty();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
void enqueue(const WorkListUnit& U) override {
|
2013-02-22 06:23:56 +08:00
|
|
|
if (U.getNode()->getLocation().getAs<BlockEntrance>())
|
2010-11-13 13:04:49 +08:00
|
|
|
Queue.push_front(U);
|
2008-12-17 06:13:33 +08:00
|
|
|
else
|
|
|
|
Stack.push_back(U);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
WorkListUnit dequeue() override {
|
2008-12-17 06:13:33 +08:00
|
|
|
// Process all basic blocks to completion.
|
|
|
|
if (!Stack.empty()) {
|
2010-12-23 02:53:44 +08:00
|
|
|
const WorkListUnit& U = Stack.back();
|
2008-12-17 06:13:33 +08:00
|
|
|
Stack.pop_back(); // This technically "invalidates" U, but we are fine.
|
|
|
|
return U;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-12-17 06:13:33 +08:00
|
|
|
assert(!Queue.empty());
|
|
|
|
// Don't use const reference. The subsequent pop_back() might make it
|
|
|
|
// unsafe.
|
2010-12-23 02:53:44 +08:00
|
|
|
WorkListUnit U = Queue.front();
|
2010-11-13 13:04:49 +08:00
|
|
|
Queue.pop_front();
|
2009-09-09 23:08:12 +08:00
|
|
|
return U;
|
2008-12-17 06:13:33 +08:00
|
|
|
}
|
2014-03-15 12:29:04 +08:00
|
|
|
bool visitItemsInWorkList(Visitor &V) override {
|
2011-07-23 18:55:15 +08:00
|
|
|
for (SmallVectorImpl<WorkListUnit>::iterator
|
2010-11-13 13:04:49 +08:00
|
|
|
I = Stack.begin(), E = Stack.end(); I != E; ++I) {
|
2011-01-11 10:34:50 +08:00
|
|
|
if (V.visit(*I))
|
2010-11-13 13:04:49 +08:00
|
|
|
return true;
|
|
|
|
}
|
2010-12-23 02:53:44 +08:00
|
|
|
for (std::deque<WorkListUnit>::iterator
|
2010-11-13 13:04:49 +08:00
|
|
|
I = Queue.begin(), E = Queue.end(); I != E; ++I) {
|
2011-01-11 10:34:50 +08:00
|
|
|
if (V.visit(*I))
|
2010-11-13 13:04:49 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-17 06:13:33 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2011-01-11 10:34:50 +08:00
|
|
|
WorkList* WorkList::makeBFSBlockDFSContents() {
|
2008-12-17 06:13:33 +08:00
|
|
|
return new BFSBlockDFSContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Core analysis engine.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-02-26 03:01:53 +08:00
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
/// ExecuteWorkList - Run the worklist algorithm for a maximum number of steps.
|
2010-12-23 02:53:44 +08:00
|
|
|
bool CoreEngine::ExecuteWorkList(const LocationContext *L, unsigned Steps,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef InitState) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-08-09 07:36:37 +08:00
|
|
|
if (G.num_roots() == 0) { // Initialize the analysis by constructing
|
2008-01-15 07:24:37 +08:00
|
|
|
// the root if none exists.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
const CFGBlock *Entry = &(L->getCFG()->getEntry());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
assert (Entry->empty() &&
|
2008-01-15 07:24:37 +08:00
|
|
|
"Entry block must be empty.");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
assert (Entry->succ_size() == 1 &&
|
|
|
|
"Entry block must have 1 successor.");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-04-03 10:05:47 +08:00
|
|
|
// Mark the entry block as visited.
|
|
|
|
FunctionSummaries->markVisitedBasicBlock(Entry->getBlockID(),
|
|
|
|
L->getDecl(),
|
|
|
|
L->getCFG()->getNumBlockIDs());
|
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
// Get the solitary successor.
|
2011-08-13 07:37:29 +08:00
|
|
|
const CFGBlock *Succ = *(Entry->succ_begin());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
// Construct an edge representing the
|
|
|
|
// starting location in the function.
|
2009-08-15 11:17:38 +08:00
|
|
|
BlockEdge StartLoc(Entry, Succ, L);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 02:08:17 +08:00
|
|
|
// Set the current block counter to being empty.
|
|
|
|
WList->setBlockCounter(BCounterFactory.GetEmptyCounter());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-07-22 21:52:13 +08:00
|
|
|
if (!InitState)
|
2016-02-19 09:35:10 +08:00
|
|
|
InitState = SubEng.getInitialState(L);
|
|
|
|
|
|
|
|
bool IsNew;
|
|
|
|
ExplodedNode *Node = G.getNode(StartLoc, InitState, false, &IsNew);
|
|
|
|
assert (IsNew);
|
|
|
|
G.addRoot(Node);
|
|
|
|
|
|
|
|
NodeBuilderContext BuilderCtx(*this, StartLoc.getDst(), Node);
|
|
|
|
ExplodedNodeSet DstBegin;
|
|
|
|
SubEng.processBeginOfFunction(BuilderCtx, Node, DstBegin, StartLoc);
|
|
|
|
|
|
|
|
enqueue(DstBegin);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-09-30 07:48:13 +08:00
|
|
|
// Check if we have a steps limit
|
|
|
|
bool UnlimitedSteps = Steps == 0;
|
2016-06-10 21:22:13 +08:00
|
|
|
// Cap our pre-reservation in the event that the user specifies
|
|
|
|
// a very large number of maximum steps.
|
|
|
|
const unsigned PreReservationCap = 4000000;
|
|
|
|
if(!UnlimitedSteps)
|
|
|
|
G.reserve(std::min(Steps,PreReservationCap));
|
2010-09-30 07:48:13 +08:00
|
|
|
|
|
|
|
while (WList->hasWork()) {
|
|
|
|
if (!UnlimitedSteps) {
|
2012-03-17 07:24:13 +08:00
|
|
|
if (Steps == 0) {
|
|
|
|
NumReachedMaxSteps++;
|
2010-09-30 07:48:13 +08:00
|
|
|
break;
|
2012-03-17 07:24:13 +08:00
|
|
|
}
|
2010-09-30 07:48:13 +08:00
|
|
|
--Steps;
|
|
|
|
}
|
|
|
|
|
2012-06-23 06:08:06 +08:00
|
|
|
NumSteps++;
|
|
|
|
|
2011-01-11 10:34:50 +08:00
|
|
|
const WorkListUnit& WU = WList->dequeue();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 02:08:17 +08:00
|
|
|
// Set the current block counter.
|
|
|
|
WList->setBlockCounter(WU.getBlockCounter());
|
|
|
|
|
|
|
|
// Retrieve the node.
|
2011-08-13 07:37:29 +08:00
|
|
|
ExplodedNode *Node = WU.getNode();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-03-28 04:02:53 +08:00
|
|
|
dispatchWorkItem(Node, Node->getLocation(), WU);
|
|
|
|
}
|
|
|
|
SubEng.processEndWorklist(hasWorkRemaining());
|
|
|
|
return WList->hasWork();
|
|
|
|
}
|
2008-12-17 06:13:33 +08:00
|
|
|
|
2012-03-28 04:02:53 +08:00
|
|
|
void CoreEngine::dispatchWorkItem(ExplodedNode* Pred, ProgramPoint Loc,
|
|
|
|
const WorkListUnit& WU) {
|
|
|
|
// Dispatch on the location type.
|
|
|
|
switch (Loc.getKind()) {
|
|
|
|
case ProgramPoint::BlockEdgeKind:
|
2013-02-22 06:23:56 +08:00
|
|
|
HandleBlockEdge(Loc.castAs<BlockEdge>(), Pred);
|
2012-03-28 04:02:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::BlockEntranceKind:
|
2013-02-22 06:23:56 +08:00
|
|
|
HandleBlockEntrance(Loc.castAs<BlockEntrance>(), Pred);
|
2012-03-28 04:02:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::BlockExitKind:
|
|
|
|
assert (false && "BlockExit location never occur in forward analysis.");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::CallEnterKind: {
|
2016-02-19 09:35:10 +08:00
|
|
|
HandleCallEnter(Loc.castAs<CallEnter>(), Pred);
|
2012-03-28 04:02:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-02-26 03:01:53 +08:00
|
|
|
|
2012-04-21 05:59:08 +08:00
|
|
|
case ProgramPoint::CallExitBeginKind:
|
2012-03-28 04:02:53 +08:00
|
|
|
SubEng.processCallExit(Pred);
|
|
|
|
break;
|
2010-02-26 03:01:53 +08:00
|
|
|
|
2012-03-28 04:02:53 +08:00
|
|
|
case ProgramPoint::EpsilonKind: {
|
|
|
|
assert(Pred->hasSinglePred() &&
|
|
|
|
"Assume epsilon has exactly one predecessor by construction");
|
|
|
|
ExplodedNode *PNode = Pred->getFirstPred();
|
|
|
|
dispatchWorkItem(Pred, PNode->getLocation(), WU);
|
|
|
|
break;
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
2012-03-28 04:02:53 +08:00
|
|
|
default:
|
2013-02-22 06:23:56 +08:00
|
|
|
assert(Loc.getAs<PostStmt>() ||
|
|
|
|
Loc.getAs<PostInitializer>() ||
|
|
|
|
Loc.getAs<PostImplicitCall>() ||
|
|
|
|
Loc.getAs<CallExitEnd>());
|
2012-03-28 04:02:53 +08:00
|
|
|
HandlePostStmt(WU.getBlock(), WU.getIndex(), Pred);
|
|
|
|
break;
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 01:05:50 +08:00
|
|
|
bool CoreEngine::ExecuteWorkListWithInitialState(const LocationContext *L,
|
2011-08-16 06:09:50 +08:00
|
|
|
unsigned Steps,
|
2015-09-08 11:50:52 +08:00
|
|
|
ProgramStateRef InitState,
|
2011-08-16 06:09:50 +08:00
|
|
|
ExplodedNodeSet &Dst) {
|
2012-03-29 01:05:50 +08:00
|
|
|
bool DidNotFinish = ExecuteWorkList(L, Steps, InitState);
|
2014-08-09 07:36:37 +08:00
|
|
|
for (ExplodedGraph::eop_iterator I = G.eop_begin(), E = G.eop_end(); I != E;
|
|
|
|
++I) {
|
2010-07-22 21:52:13 +08:00
|
|
|
Dst.Add(*I);
|
|
|
|
}
|
2012-03-29 01:05:50 +08:00
|
|
|
return DidNotFinish;
|
2010-07-22 21:52:13 +08:00
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void CoreEngine::HandleBlockEdge(const BlockEdge &L, ExplodedNode *Pred) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
const CFGBlock *Blk = L.getDst();
|
2011-10-27 05:06:22 +08:00
|
|
|
NodeBuilderContext BuilderCtx(*this, Blk, Pred);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-04-03 10:05:47 +08:00
|
|
|
// Mark this block as visited.
|
|
|
|
const LocationContext *LC = Pred->getLocationContext();
|
|
|
|
FunctionSummaries->markVisitedBasicBlock(Blk->getBlockID(),
|
|
|
|
LC->getDecl(),
|
|
|
|
LC->getCFG()->getNumBlockIDs());
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// Check if we are entering the EXIT block.
|
2009-12-23 16:54:57 +08:00
|
|
|
if (Blk == &(L.getLocationContext()->getCFG()->getExit())) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-12-23 16:54:57 +08:00
|
|
|
assert (L.getLocationContext()->getCFG()->getExit().size() == 0
|
2008-01-29 08:33:40 +08:00
|
|
|
&& "EXIT block cannot contain Stmts.");
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2016-10-07 22:21:08 +08:00
|
|
|
// Get return statement..
|
|
|
|
const ReturnStmt *RS = nullptr;
|
|
|
|
if (!L.getSrc()->empty()) {
|
|
|
|
if (Optional<CFGStmt> LastStmt = L.getSrc()->back().getAs<CFGStmt>()) {
|
2016-10-08 03:11:33 +08:00
|
|
|
if ((RS = dyn_cast<ReturnStmt>(LastStmt->getStmt()))) {
|
2016-10-07 22:21:08 +08:00
|
|
|
if (!RS->getRetValue())
|
|
|
|
RS = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 06:03:04 +08:00
|
|
|
// Process the final state transition.
|
2016-10-07 22:21:08 +08:00
|
|
|
SubEng.processEndOfFunction(BuilderCtx, Pred, RS);
|
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
|
|
|
|
2011-10-27 05:06:22 +08:00
|
|
|
// Call into the SubEngine to process entering the CFGBlock.
|
2011-01-11 14:37:47 +08:00
|
|
|
ExplodedNodeSet dstNodes;
|
|
|
|
BlockEntrance BE(Blk, Pred->getLocationContext());
|
2011-10-27 05:06:22 +08:00
|
|
|
NodeBuilderWithSinks nodeBuilder(Pred, dstNodes, BuilderCtx, BE);
|
2012-11-03 10:54:11 +08:00
|
|
|
SubEng.processCFGBlockEntrance(L, nodeBuilder, Pred);
|
2011-01-11 14:37:47 +08:00
|
|
|
|
2011-10-27 05:06:22 +08:00
|
|
|
// Auto-generate a node.
|
|
|
|
if (!nodeBuilder.hasGeneratedNodes()) {
|
|
|
|
nodeBuilder.generateNode(Pred->State, Pred);
|
2011-01-11 14:37:47 +08:00
|
|
|
}
|
|
|
|
|
2011-10-27 05:06:22 +08:00
|
|
|
// Enqueue nodes onto the worklist.
|
|
|
|
enqueue(dstNodes);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void CoreEngine::HandleBlockEntrance(const BlockEntrance &L,
|
|
|
|
ExplodedNode *Pred) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 02:08:17 +08:00
|
|
|
// Increment the block counter.
|
2012-04-03 10:05:47 +08:00
|
|
|
const LocationContext *LC = Pred->getLocationContext();
|
|
|
|
unsigned BlockId = L.getBlock()->getBlockID();
|
2010-12-23 02:53:44 +08:00
|
|
|
BlockCounter Counter = WList->getBlockCounter();
|
2012-04-03 10:05:47 +08:00
|
|
|
Counter = BCounterFactory.IncrementCount(Counter, LC->getCurrentStackFrame(),
|
|
|
|
BlockId);
|
2008-02-13 02:08:17 +08:00
|
|
|
WList->setBlockCounter(Counter);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
// Process the entrance of the block.
|
2013-02-23 08:29:34 +08:00
|
|
|
if (Optional<CFGElement> E = L.getFirstElement()) {
|
2011-10-19 07:06:48 +08:00
|
|
|
NodeBuilderContext Ctx(*this, L.getBlock(), Pred);
|
2013-02-23 08:29:34 +08:00
|
|
|
SubEng.processCFGElement(*E, Pred, 0, &Ctx);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
else
|
2008-01-15 08:24:08 +08:00
|
|
|
HandleBlockExit(L.getBlock(), Pred);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void CoreEngine::HandleBlockExit(const CFGBlock * B, ExplodedNode *Pred) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const Stmt *Term = B->getTerminator()) {
|
2008-01-30 06:56:11 +08:00
|
|
|
switch (Term->getStmtClass()) {
|
|
|
|
default:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Analysis for this terminator not implemented.");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-08-07 18:42:17 +08:00
|
|
|
case Stmt::CXXBindTemporaryExprClass:
|
|
|
|
HandleCleanupTemporaryBranch(
|
|
|
|
cast<CXXBindTemporaryExpr>(B->getTerminator().getStmt()), B, Pred);
|
|
|
|
return;
|
|
|
|
|
2013-03-29 08:09:28 +08:00
|
|
|
// Model static initializers.
|
|
|
|
case Stmt::DeclStmtClass:
|
|
|
|
HandleStaticInit(cast<DeclStmt>(Term), B, Pred);
|
|
|
|
return;
|
|
|
|
|
2008-02-13 05:51:20 +08:00
|
|
|
case Stmt::BinaryOperatorClass: // '&&' and '||'
|
|
|
|
HandleBranch(cast<BinaryOperator>(Term)->getLHS(), Term, B, Pred);
|
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
case Stmt::BinaryConditionalOperatorClass:
|
2008-02-05 08:26:40 +08:00
|
|
|
case Stmt::ConditionalOperatorClass:
|
2011-02-17 18:25:35 +08:00
|
|
|
HandleBranch(cast<AbstractConditionalOperator>(Term)->getCond(),
|
|
|
|
Term, B, Pred);
|
2008-02-13 05:51:20 +08:00
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 05:51:20 +08:00
|
|
|
// FIXME: Use constant-folding in CFG construction to simplify this
|
|
|
|
// case.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
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;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-03-10 09:34:17 +08:00
|
|
|
case Stmt::CXXTryStmtClass: {
|
|
|
|
// Generate a node for each of the successors.
|
|
|
|
// Our logic for EH analysis can certainly be improved.
|
|
|
|
for (CFGBlock::const_succ_iterator it = B->succ_begin(),
|
|
|
|
et = B->succ_end(); it != et; ++it) {
|
|
|
|
if (const CFGBlock *succ = *it) {
|
|
|
|
generateNode(BlockEdge(B, succ, Pred->getLocationContext()),
|
|
|
|
Pred->State, Pred);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2008-02-13 05:51:20 +08:00
|
|
|
case Stmt::DoStmtClass:
|
|
|
|
HandleBranch(cast<DoStmt>(Term)->getCond(), Term, B, Pred);
|
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-11 06:36:31 +08:00
|
|
|
case Stmt::CXXForRangeStmtClass:
|
|
|
|
HandleBranch(cast<CXXForRangeStmt>(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;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 00:56:51 +08:00
|
|
|
case Stmt::ContinueStmtClass:
|
|
|
|
case Stmt::BreakStmtClass:
|
2009-09-09 23:08:12 +08:00
|
|
|
case Stmt::GotoStmtClass:
|
2008-01-30 06:56:11 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 05:51:20 +08:00
|
|
|
case Stmt::IfStmtClass:
|
|
|
|
HandleBranch(cast<IfStmt>(Term)->getCond(), Term, B, Pred);
|
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 08:24:44 +08:00
|
|
|
case Stmt::IndirectGotoStmtClass: {
|
|
|
|
// Only 1 successor: the indirect goto dispatch block.
|
|
|
|
assert (B->succ_size() == 1);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
IndirectGotoNodeBuilder
|
2008-02-13 08:24:44 +08:00
|
|
|
builder(Pred, B, cast<IndirectGotoStmt>(Term)->getTarget(),
|
|
|
|
*(B->succ_begin()), this);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-01-11 12:49:40 +08:00
|
|
|
SubEng.processIndirectGoto(builder);
|
2008-02-13 08:24:44 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-11-13 03:24:17 +08: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-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
case Stmt::SwitchStmtClass: {
|
2010-12-23 02:53:44 +08:00
|
|
|
SwitchNodeBuilder builder(Pred, B, cast<SwitchStmt>(Term)->getCond(),
|
2009-08-06 20:48:26 +08:00
|
|
|
this);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-01-11 12:49:40 +08:00
|
|
|
SubEng.processSwitch(builder);
|
2008-02-14 07:08:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
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.");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-12-21 05:19:09 +08:00
|
|
|
generateNode(BlockEdge(B, *(B->succ_begin()), Pred->getLocationContext()),
|
2009-08-15 11:17:38 +08:00
|
|
|
Pred->State, Pred);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
|
2016-02-19 09:35:10 +08:00
|
|
|
void CoreEngine::HandleCallEnter(const CallEnter &CE, ExplodedNode *Pred) {
|
|
|
|
NodeBuilderContext BuilderCtx(*this, CE.getEntry(), Pred);
|
|
|
|
SubEng.processCallEnter(BuilderCtx, CE, Pred);
|
|
|
|
}
|
|
|
|
|
2015-09-08 11:50:52 +08:00
|
|
|
void CoreEngine::HandleBranch(const Stmt *Cond, const Stmt *Term,
|
2011-08-13 07:37:29 +08:00
|
|
|
const CFGBlock * B, ExplodedNode *Pred) {
|
2011-01-11 12:49:40 +08:00
|
|
|
assert(B->succ_size() == 2);
|
2011-10-19 07:06:48 +08:00
|
|
|
NodeBuilderContext Ctx(*this, B, Pred);
|
2011-10-25 02:25:53 +08:00
|
|
|
ExplodedNodeSet Dst;
|
|
|
|
SubEng.processBranch(Cond, Term, Ctx, Pred, Dst,
|
2011-10-19 07:06:04 +08:00
|
|
|
*(B->succ_begin()), *(B->succ_begin()+1));
|
2011-10-25 02:25:53 +08:00
|
|
|
// Enqueue the new frontier onto the worklist.
|
|
|
|
enqueue(Dst);
|
2008-01-30 06:56:11 +08:00
|
|
|
}
|
|
|
|
|
2014-08-07 18:42:17 +08:00
|
|
|
void CoreEngine::HandleCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE,
|
|
|
|
const CFGBlock *B,
|
|
|
|
ExplodedNode *Pred) {
|
|
|
|
assert(B->succ_size() == 2);
|
|
|
|
NodeBuilderContext Ctx(*this, B, Pred);
|
|
|
|
ExplodedNodeSet Dst;
|
|
|
|
SubEng.processCleanupTemporaryBranch(BTE, Ctx, Pred, Dst, *(B->succ_begin()),
|
|
|
|
*(B->succ_begin() + 1));
|
|
|
|
// Enqueue the new frontier onto the worklist.
|
|
|
|
enqueue(Dst);
|
|
|
|
}
|
2013-03-29 08:09:28 +08:00
|
|
|
|
|
|
|
void CoreEngine::HandleStaticInit(const DeclStmt *DS, const CFGBlock *B,
|
|
|
|
ExplodedNode *Pred) {
|
|
|
|
assert(B->succ_size() == 2);
|
|
|
|
NodeBuilderContext Ctx(*this, B, Pred);
|
|
|
|
ExplodedNodeSet Dst;
|
|
|
|
SubEng.processStaticInitializer(DS, Ctx, Pred, Dst,
|
|
|
|
*(B->succ_begin()), *(B->succ_begin()+1));
|
|
|
|
// Enqueue the new frontier onto the worklist.
|
|
|
|
enqueue(Dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-08 11:50:52 +08:00
|
|
|
void CoreEngine::HandlePostStmt(const CFGBlock *B, unsigned StmtIdx,
|
2011-08-13 07:37:29 +08:00
|
|
|
ExplodedNode *Pred) {
|
2011-10-19 07:06:04 +08:00
|
|
|
assert(B);
|
|
|
|
assert(!B->empty());
|
2008-01-15 07:24:37 +08:00
|
|
|
|
2008-01-15 08:24:08 +08:00
|
|
|
if (StmtIdx == B->size())
|
|
|
|
HandleBlockExit(B, Pred);
|
2008-01-15 07:24:37 +08:00
|
|
|
else {
|
2011-10-19 07:06:48 +08:00
|
|
|
NodeBuilderContext Ctx(*this, B, Pred);
|
2011-10-25 02:26:19 +08:00
|
|
|
SubEng.processCFGElement((*B)[StmtIdx], Pred, StmtIdx, &Ctx);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-21 05:19:09 +08:00
|
|
|
/// generateNode - Utility method to generate nodes, hook up successors,
|
2008-01-15 07:24:37 +08:00
|
|
|
/// and add nodes to the worklist.
|
2011-08-13 07:37:29 +08:00
|
|
|
void CoreEngine::generateNode(const ProgramPoint &Loc,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef State,
|
2011-08-16 06:09:50 +08:00
|
|
|
ExplodedNode *Pred) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
bool IsNew;
|
2014-08-09 07:36:37 +08:00
|
|
|
ExplodedNode *Node = G.getNode(Loc, State, false, &IsNew);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
if (Pred)
|
2014-08-09 07:36:37 +08:00
|
|
|
Node->addPredecessor(Pred, G); // Link 'Node' with its predecessor.
|
2008-01-15 07:24:37 +08:00
|
|
|
else {
|
|
|
|
assert (IsNew);
|
2014-08-09 07:36:37 +08:00
|
|
|
G.addRoot(Node); // 'Node' has no predecessor. Make it a root.
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-15 07:24:37 +08:00
|
|
|
// Only add 'Node' to the worklist if it was freshly generated.
|
2011-01-11 10:34:50 +08:00
|
|
|
if (IsNew) WList->enqueue(Node);
|
2008-01-15 07:24:37 +08:00
|
|
|
}
|
|
|
|
|
2011-10-27 08:59:23 +08:00
|
|
|
void CoreEngine::enqueueStmtNode(ExplodedNode *N,
|
|
|
|
const CFGBlock *Block, unsigned Idx) {
|
2011-11-02 06:41:06 +08:00
|
|
|
assert(Block);
|
2011-10-27 08:59:23 +08:00
|
|
|
assert (!N->isSink());
|
|
|
|
|
|
|
|
// Check if this node entered a callee.
|
2013-02-22 06:23:56 +08:00
|
|
|
if (N->getLocation().getAs<CallEnter>()) {
|
2011-10-27 08:59:23 +08:00
|
|
|
// Still use the index of the CallExpr. It's needed to create the callee
|
|
|
|
// StackFrameContext.
|
|
|
|
WList->enqueue(N, Block, Idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not create extra nodes. Move to the next CFG element.
|
2013-02-22 06:23:56 +08:00
|
|
|
if (N->getLocation().getAs<PostInitializer>() ||
|
|
|
|
N->getLocation().getAs<PostImplicitCall>()) {
|
2011-10-27 08:59:23 +08:00
|
|
|
WList->enqueue(N, Block, Idx+1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-22 06:23:56 +08:00
|
|
|
if (N->getLocation().getAs<EpsilonPoint>()) {
|
2012-03-28 04:02:53 +08:00
|
|
|
WList->enqueue(N, Block, Idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-11 10:21:06 +08:00
|
|
|
if ((*Block)[Idx].getKind() == CFGElement::NewAllocator) {
|
|
|
|
WList->enqueue(N, Block, Idx+1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-08 03:48:09 +08:00
|
|
|
// At this point, we know we're processing a normal statement.
|
2013-02-22 04:58:29 +08:00
|
|
|
CFGStmt CS = (*Block)[Idx].castAs<CFGStmt>();
|
2012-09-08 03:48:09 +08:00
|
|
|
PostStmt Loc(CS.getStmt(), N->getLocationContext());
|
2011-10-27 08:59:23 +08:00
|
|
|
|
2014-06-19 03:23:30 +08:00
|
|
|
if (Loc == N->getLocation().withTag(nullptr)) {
|
2011-10-27 08:59:23 +08:00
|
|
|
// Note: 'N' should be a fresh node because otherwise it shouldn't be
|
|
|
|
// a member of Deferred.
|
|
|
|
WList->enqueue(N, Block, Idx+1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsNew;
|
2014-08-09 07:36:37 +08:00
|
|
|
ExplodedNode *Succ = G.getNode(Loc, N->getState(), false, &IsNew);
|
|
|
|
Succ->addPredecessor(N, G);
|
2011-10-27 08:59:23 +08:00
|
|
|
|
|
|
|
if (IsNew)
|
|
|
|
WList->enqueue(Succ, Block, Idx+1);
|
|
|
|
}
|
|
|
|
|
2016-10-07 22:21:08 +08:00
|
|
|
ExplodedNode *CoreEngine::generateCallExitBeginNode(ExplodedNode *N,
|
|
|
|
const ReturnStmt *RS) {
|
2012-04-21 05:59:08 +08:00
|
|
|
// Create a CallExitBegin node and enqueue it.
|
2011-10-27 08:59:28 +08:00
|
|
|
const StackFrameContext *LocCtx
|
|
|
|
= cast<StackFrameContext>(N->getLocationContext());
|
|
|
|
|
2012-07-23 16:59:39 +08:00
|
|
|
// Use the callee location context.
|
2016-10-07 22:21:08 +08:00
|
|
|
CallExitBegin Loc(LocCtx, RS);
|
2011-10-27 08:59:28 +08:00
|
|
|
|
|
|
|
bool isNew;
|
2014-08-09 07:36:37 +08:00
|
|
|
ExplodedNode *Node = G.getNode(Loc, N->getState(), false, &isNew);
|
|
|
|
Node->addPredecessor(N, G);
|
2014-05-27 10:45:47 +08:00
|
|
|
return isNew ? Node : nullptr;
|
2011-10-27 08:59:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-27 08:59:23 +08:00
|
|
|
void CoreEngine::enqueue(ExplodedNodeSet &Set) {
|
|
|
|
for (ExplodedNodeSet::iterator I = Set.begin(),
|
|
|
|
E = Set.end(); I != E; ++I) {
|
2011-10-19 07:06:04 +08:00
|
|
|
WList->enqueue(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-27 08:59:23 +08:00
|
|
|
void CoreEngine::enqueue(ExplodedNodeSet &Set,
|
|
|
|
const CFGBlock *Block, unsigned Idx) {
|
|
|
|
for (ExplodedNodeSet::iterator I = Set.begin(),
|
|
|
|
E = Set.end(); I != E; ++I) {
|
|
|
|
enqueueStmtNode(*I, Block, Idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 22:21:08 +08:00
|
|
|
void CoreEngine::enqueueEndOfFunction(ExplodedNodeSet &Set, const ReturnStmt *RS) {
|
2011-10-27 08:59:28 +08:00
|
|
|
for (ExplodedNodeSet::iterator I = Set.begin(), E = Set.end(); I != E; ++I) {
|
|
|
|
ExplodedNode *N = *I;
|
2012-04-21 05:59:08 +08:00
|
|
|
// If we are in an inlined call, generate CallExitBegin node.
|
2011-10-27 08:59:28 +08:00
|
|
|
if (N->getLocationContext()->getParent()) {
|
2016-10-07 22:21:08 +08:00
|
|
|
N = generateCallExitBeginNode(N, RS);
|
2011-10-27 08:59:28 +08:00
|
|
|
if (N)
|
|
|
|
WList->enqueue(N);
|
2012-03-23 05:06:06 +08:00
|
|
|
} else {
|
2012-04-21 05:59:08 +08:00
|
|
|
// TODO: We should run remove dead bindings here.
|
2014-08-09 07:36:37 +08:00
|
|
|
G.addEndOfPath(N);
|
2012-03-23 05:06:06 +08:00
|
|
|
NumPathsExplored++;
|
|
|
|
}
|
2011-10-27 08:59:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-27 08:59:23 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void NodeBuilder::anchor() { }
|
|
|
|
|
2011-10-19 07:05:58 +08:00
|
|
|
ExplodedNode* NodeBuilder::generateNodeImpl(const ProgramPoint &Loc,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef State,
|
2011-10-19 07:06:33 +08:00
|
|
|
ExplodedNode *FromN,
|
|
|
|
bool MarkAsSink) {
|
2011-10-19 07:06:44 +08:00
|
|
|
HasGeneratedNodes = true;
|
2011-10-19 07:05:58 +08:00
|
|
|
bool IsNew;
|
2014-08-09 07:36:37 +08:00
|
|
|
ExplodedNode *N = C.Eng.G.getNode(Loc, State, MarkAsSink, &IsNew);
|
|
|
|
N->addPredecessor(FromN, C.Eng.G);
|
2011-10-25 02:25:53 +08:00
|
|
|
Frontier.erase(FromN);
|
2011-11-02 06:41:14 +08:00
|
|
|
|
|
|
|
if (!IsNew)
|
2014-05-27 10:45:47 +08:00
|
|
|
return nullptr;
|
2011-10-19 07:05:58 +08:00
|
|
|
|
2011-11-02 06:41:19 +08:00
|
|
|
if (!MarkAsSink)
|
2011-10-25 02:25:53 +08:00
|
|
|
Frontier.Add(N);
|
2011-10-19 07:05:58 +08:00
|
|
|
|
2011-11-02 06:41:14 +08:00
|
|
|
return N;
|
2011-10-19 07:05:58 +08:00
|
|
|
}
|
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void NodeBuilderWithSinks::anchor() { }
|
|
|
|
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder::~StmtNodeBuilder() {
|
2011-10-25 05:19:53 +08:00
|
|
|
if (EnclosingBldr)
|
|
|
|
for (ExplodedNodeSet::iterator I = Frontier.begin(),
|
|
|
|
E = Frontier.end(); I != E; ++I )
|
|
|
|
EnclosingBldr->addNodes(*I);
|
2010-04-14 14:35:09 +08:00
|
|
|
}
|
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void BranchNodeBuilder::anchor() { }
|
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ExplodedNode *BranchNodeBuilder::generateNode(ProgramStateRef State,
|
2011-10-19 07:06:04 +08:00
|
|
|
bool branch,
|
|
|
|
ExplodedNode *NodePred) {
|
2009-07-21 02:44:36 +08:00
|
|
|
// If the branch has been marked infeasible we should not generate a node.
|
|
|
|
if (!isFeasible(branch))
|
2014-05-27 10:45:47 +08:00
|
|
|
return nullptr;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-19 07:06:04 +08:00
|
|
|
ProgramPoint Loc = BlockEdge(C.Block, branch ? DstT:DstF,
|
|
|
|
NodePred->getLocationContext());
|
|
|
|
ExplodedNode *Succ = generateNodeImpl(Loc, State, NodePred);
|
|
|
|
return Succ;
|
2008-01-30 06:56:11 +08:00
|
|
|
}
|
2008-01-30 07:32:35 +08:00
|
|
|
|
2009-08-06 09:32:16 +08:00
|
|
|
ExplodedNode*
|
2011-08-16 06:09:50 +08:00
|
|
|
IndirectGotoNodeBuilder::generateNode(const iterator &I,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef St,
|
2011-11-02 06:41:19 +08:00
|
|
|
bool IsSink) {
|
2008-02-13 08:24:44 +08:00
|
|
|
bool IsNew;
|
2014-08-09 07:36:37 +08:00
|
|
|
ExplodedNode *Succ =
|
|
|
|
Eng.G.getNode(BlockEdge(Src, I.getBlock(), Pred->getLocationContext()),
|
|
|
|
St, IsSink, &IsNew);
|
|
|
|
Succ->addPredecessor(Pred, Eng.G);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-02 06:41:19 +08:00
|
|
|
if (!IsNew)
|
2014-05-27 10:45:47 +08:00
|
|
|
return nullptr;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-02 06:41:19 +08:00
|
|
|
if (!IsSink)
|
|
|
|
Eng.WList->enqueue(Succ);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-02 06:41:19 +08:00
|
|
|
return Succ;
|
2008-02-13 08:24:44 +08:00
|
|
|
}
|
2008-02-14 07:08:21 +08:00
|
|
|
|
|
|
|
|
2009-08-06 09:32:16 +08:00
|
|
|
ExplodedNode*
|
2011-08-16 06:09:50 +08:00
|
|
|
SwitchNodeBuilder::generateCaseStmtNode(const iterator &I,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef St) {
|
2008-02-14 07:08:21 +08:00
|
|
|
|
|
|
|
bool IsNew;
|
2014-08-09 07:36:37 +08:00
|
|
|
ExplodedNode *Succ =
|
|
|
|
Eng.G.getNode(BlockEdge(Src, I.getBlock(), Pred->getLocationContext()),
|
|
|
|
St, false, &IsNew);
|
|
|
|
Succ->addPredecessor(Pred, Eng.G);
|
2011-11-02 06:41:19 +08:00
|
|
|
if (!IsNew)
|
2014-05-27 10:45:47 +08:00
|
|
|
return nullptr;
|
2011-11-02 06:41:19 +08:00
|
|
|
|
|
|
|
Eng.WList->enqueue(Succ);
|
|
|
|
return Succ;
|
2008-02-14 07:08:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-06 09:32:16 +08:00
|
|
|
ExplodedNode*
|
2012-01-27 05:29:00 +08:00
|
|
|
SwitchNodeBuilder::generateDefaultCaseNode(ProgramStateRef St,
|
2011-11-02 06:41:19 +08:00
|
|
|
bool IsSink) {
|
2008-02-14 07:08:21 +08:00
|
|
|
// Get the block for the default case.
|
2011-09-30 11:51:54 +08:00
|
|
|
assert(Src->succ_rbegin() != Src->succ_rend());
|
2011-08-13 07:37:29 +08:00
|
|
|
CFGBlock *DefaultBlock = *Src->succ_rbegin();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-09-30 11:51:54 +08:00
|
|
|
// Sanity check for default blocks that are unreachable and not caught
|
|
|
|
// by earlier stages.
|
|
|
|
if (!DefaultBlock)
|
2014-05-27 10:45:47 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
bool IsNew;
|
2014-08-09 07:36:37 +08:00
|
|
|
ExplodedNode *Succ =
|
|
|
|
Eng.G.getNode(BlockEdge(Src, DefaultBlock, Pred->getLocationContext()),
|
|
|
|
St, IsSink, &IsNew);
|
|
|
|
Succ->addPredecessor(Pred, Eng.G);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-02 06:41:19 +08:00
|
|
|
if (!IsNew)
|
2014-05-27 10:45:47 +08:00
|
|
|
return nullptr;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-02 06:41:19 +08:00
|
|
|
if (!IsSink)
|
|
|
|
Eng.WList->enqueue(Succ);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-02 06:41:19 +08:00
|
|
|
return Succ;
|
2008-02-14 07:08:21 +08:00
|
|
|
}
|