2008-01-13 12:56:13 +08:00
|
|
|
//=-- ExplodedGraph.cpp - Local, Path-Sens. "Exploded Graph" -*- C++ -*------=//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the template classes ExplodedNode and ExplodedGraph,
|
|
|
|
// which represent a path-sensitive, intra-procedural "exploded graph."
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-10 09:03:03 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
|
2011-08-16 06:09:50 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
|
2008-04-16 23:51:26 +08:00
|
|
|
#include "clang/AST/Stmt.h"
|
2012-01-25 08:35:05 +08:00
|
|
|
#include "clang/AST/ParentMap.h"
|
2008-03-08 06:58:01 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2008-01-13 12:56:13 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace clang;
|
2010-12-23 15:20:52 +08:00
|
|
|
using namespace ento;
|
2008-01-13 12:56:13 +08:00
|
|
|
|
2008-08-27 09:56:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Node auditing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// An out of line virtual method to provide a home for the class vtable.
|
2009-08-06 09:32:16 +08:00
|
|
|
ExplodedNode::Auditor::~Auditor() {}
|
2008-08-27 09:56:11 +08:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2009-08-06 09:32:16 +08:00
|
|
|
static ExplodedNode::Auditor* NodeAuditor = 0;
|
2008-08-27 09:56:11 +08:00
|
|
|
#endif
|
|
|
|
|
2009-08-06 09:32:16 +08:00
|
|
|
void ExplodedNode::SetAuditor(ExplodedNode::Auditor* A) {
|
2008-08-27 09:56:11 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
NodeAuditor = A;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-02-09 09:27:33 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Cleanup.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef std::vector<ExplodedNode*> NodeList;
|
|
|
|
static inline NodeList*& getNodeList(void *&p) { return (NodeList*&) p; }
|
|
|
|
|
2012-01-25 08:35:05 +08:00
|
|
|
static const unsigned CounterTop = 1000;
|
|
|
|
|
|
|
|
ExplodedGraph::ExplodedGraph()
|
|
|
|
: NumNodes(0), recentlyAllocatedNodes(0),
|
|
|
|
freeNodes(0), reclaimNodes(false),
|
|
|
|
reclaimCounter(CounterTop) {}
|
|
|
|
|
2011-02-09 09:27:33 +08:00
|
|
|
ExplodedGraph::~ExplodedGraph() {
|
|
|
|
if (reclaimNodes) {
|
|
|
|
delete getNodeList(recentlyAllocatedNodes);
|
|
|
|
delete getNodeList(freeNodes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Node reclamation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void ExplodedGraph::reclaimRecentlyAllocatedNodes() {
|
|
|
|
if (!recentlyAllocatedNodes)
|
|
|
|
return;
|
2012-01-25 08:35:05 +08:00
|
|
|
|
|
|
|
// Only periodically relcaim nodes so that we can build up a set of
|
|
|
|
// nodes that meet the reclamation criteria. Freshly created nodes
|
|
|
|
// by definition have no successor, and thus cannot be reclaimed (see below).
|
|
|
|
assert(reclaimCounter > 0);
|
|
|
|
if (--reclaimCounter != 0)
|
|
|
|
return;
|
|
|
|
reclaimCounter = CounterTop;
|
|
|
|
|
2011-02-09 09:27:33 +08:00
|
|
|
NodeList &nl = *getNodeList(recentlyAllocatedNodes);
|
|
|
|
|
|
|
|
// Reclaimn all nodes that match *all* the following criteria:
|
|
|
|
//
|
|
|
|
// (1) 1 predecessor (that has one successor)
|
|
|
|
// (2) 1 successor (that has one predecessor)
|
|
|
|
// (3) The ProgramPoint is for a PostStmt.
|
|
|
|
// (4) There is no 'tag' for the ProgramPoint.
|
|
|
|
// (5) The 'store' is the same as the predecessor.
|
|
|
|
// (6) The 'GDM' is the same as the predecessor.
|
|
|
|
// (7) The LocationContext is the same as the predecessor.
|
2012-01-25 08:35:05 +08:00
|
|
|
// (8) The PostStmt is for a non-consumed Stmt or Expr.
|
2011-02-09 09:27:33 +08:00
|
|
|
|
|
|
|
for (NodeList::iterator i = nl.begin(), e = nl.end() ; i != e; ++i) {
|
|
|
|
ExplodedNode *node = *i;
|
|
|
|
|
|
|
|
// Conditions 1 and 2.
|
|
|
|
if (node->pred_size() != 1 || node->succ_size() != 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ExplodedNode *pred = *(node->pred_begin());
|
|
|
|
if (pred->succ_size() != 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ExplodedNode *succ = *(node->succ_begin());
|
|
|
|
if (succ->pred_size() != 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Condition 3.
|
|
|
|
ProgramPoint progPoint = node->getLocation();
|
2012-01-11 09:06:27 +08:00
|
|
|
if (!isa<PostStmt>(progPoint) ||
|
|
|
|
(isa<CallEnter>(progPoint) || isa<CallExit>(progPoint)))
|
2011-02-09 09:27:33 +08:00
|
|
|
continue;
|
|
|
|
// Condition 4.
|
|
|
|
PostStmt ps = cast<PostStmt>(progPoint);
|
2011-08-16 08:49:19 +08:00
|
|
|
if (ps.getTag())
|
2011-02-09 09:27:33 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (isa<BinaryOperator>(ps.getStmt()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Conditions 5, 6, and 7.
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState *state = node->getState();
|
|
|
|
const ProgramState *pred_state = pred->getState();
|
2011-02-19 11:56:19 +08:00
|
|
|
if (state->store != pred_state->store || state->GDM != pred_state->GDM ||
|
2011-02-09 09:27:33 +08:00
|
|
|
progPoint.getLocationContext() != pred->getLocationContext())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Condition 8.
|
2012-01-25 08:35:05 +08:00
|
|
|
if (const Expr *Ex = dyn_cast<Expr>(ps.getStmt())) {
|
|
|
|
ParentMap &PM = progPoint.getLocationContext()->getParentMap();
|
|
|
|
if (!PM.isConsumedExpr(Ex))
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-09 09:27:33 +08:00
|
|
|
|
|
|
|
// If we reach here, we can remove the node. This means:
|
|
|
|
// (a) changing the predecessors successor to the successor of this node
|
|
|
|
// (b) changing the successors predecessor to the predecessor of this node
|
|
|
|
// (c) Putting 'node' onto freeNodes.
|
|
|
|
pred->replaceSuccessor(succ);
|
|
|
|
succ->replacePredecessor(pred);
|
|
|
|
if (!freeNodes)
|
|
|
|
freeNodes = new NodeList();
|
|
|
|
getNodeList(freeNodes)->push_back(node);
|
|
|
|
Nodes.RemoveNode(node);
|
2011-02-10 10:21:52 +08:00
|
|
|
--NumNodes;
|
|
|
|
node->~ExplodedNode();
|
2011-02-09 09:27:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
nl.clear();
|
|
|
|
}
|
|
|
|
|
2008-08-27 09:56:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-08-06 09:32:16 +08:00
|
|
|
// ExplodedNode.
|
2008-08-27 09:56:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-01-13 12:56:13 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
static inline BumpVector<ExplodedNode*>& getVector(void *P) {
|
2009-10-07 08:42:52 +08:00
|
|
|
return *reinterpret_cast<BumpVector<ExplodedNode*>*>(P);
|
2008-01-13 12:56:13 +08:00
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExplodedNode::addPredecessor(ExplodedNode *V, ExplodedGraph &G) {
|
2008-08-27 09:27:52 +08:00
|
|
|
assert (!V->isSink());
|
2009-10-07 08:42:52 +08:00
|
|
|
Preds.addNode(V, G);
|
|
|
|
V->Succs.addNode(this, G);
|
2008-08-27 09:56:11 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
if (NodeAuditor) NodeAuditor->AddEdge(V, this);
|
|
|
|
#endif
|
2008-08-27 09:27:52 +08:00
|
|
|
}
|
|
|
|
|
2011-02-09 09:27:33 +08:00
|
|
|
void ExplodedNode::NodeGroup::replaceNode(ExplodedNode *node) {
|
|
|
|
assert(getKind() == Size1);
|
|
|
|
P = reinterpret_cast<uintptr_t>(node);
|
|
|
|
assert(getKind() == Size1);
|
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExplodedNode::NodeGroup::addNode(ExplodedNode *N, ExplodedGraph &G) {
|
2009-10-07 08:42:52 +08:00
|
|
|
assert((reinterpret_cast<uintptr_t>(N) & Mask) == 0x0);
|
|
|
|
assert(!getFlag());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-13 12:56:13 +08:00
|
|
|
if (getKind() == Size1) {
|
2011-08-13 07:37:29 +08:00
|
|
|
if (ExplodedNode *NOld = getNode()) {
|
2009-10-07 08:42:52 +08:00
|
|
|
BumpVectorContext &Ctx = G.getNodeAllocator();
|
|
|
|
BumpVector<ExplodedNode*> *V =
|
|
|
|
G.getAllocator().Allocate<BumpVector<ExplodedNode*> >();
|
|
|
|
new (V) BumpVector<ExplodedNode*>(Ctx, 4);
|
|
|
|
|
|
|
|
assert((reinterpret_cast<uintptr_t>(V) & Mask) == 0x0);
|
|
|
|
V->push_back(NOld, Ctx);
|
|
|
|
V->push_back(N, Ctx);
|
2008-01-30 07:31:09 +08:00
|
|
|
P = reinterpret_cast<uintptr_t>(V) | SizeOther;
|
2009-10-07 08:42:52 +08:00
|
|
|
assert(getPtr() == (void*) V);
|
|
|
|
assert(getKind() == SizeOther);
|
2008-01-13 12:56:13 +08:00
|
|
|
}
|
2008-03-06 03:08:55 +08:00
|
|
|
else {
|
2008-01-13 12:56:13 +08:00
|
|
|
P = reinterpret_cast<uintptr_t>(N);
|
2009-10-07 08:42:52 +08:00
|
|
|
assert(getKind() == Size1);
|
2008-03-06 03:08:55 +08:00
|
|
|
}
|
2008-01-13 12:56:13 +08:00
|
|
|
}
|
2008-03-06 03:08:55 +08:00
|
|
|
else {
|
2009-10-07 08:42:52 +08:00
|
|
|
assert(getKind() == SizeOther);
|
|
|
|
getVector(getPtr()).push_back(N, G.getNodeAllocator());
|
2008-03-06 03:08:55 +08:00
|
|
|
}
|
2008-01-13 12:56:13 +08:00
|
|
|
}
|
|
|
|
|
2009-08-06 09:32:16 +08:00
|
|
|
unsigned ExplodedNode::NodeGroup::size() const {
|
2008-03-08 06:58:01 +08:00
|
|
|
if (getFlag())
|
|
|
|
return 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-13 12:56:13 +08:00
|
|
|
if (getKind() == Size1)
|
|
|
|
return getNode() ? 1 : 0;
|
|
|
|
else
|
|
|
|
return getVector(getPtr()).size();
|
|
|
|
}
|
|
|
|
|
2009-10-07 08:42:52 +08:00
|
|
|
ExplodedNode **ExplodedNode::NodeGroup::begin() const {
|
2008-03-08 06:58:01 +08:00
|
|
|
if (getFlag())
|
|
|
|
return NULL;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-13 12:56:13 +08:00
|
|
|
if (getKind() == Size1)
|
2009-08-06 09:32:16 +08:00
|
|
|
return (ExplodedNode**) (getPtr() ? &P : NULL);
|
2008-01-13 12:56:13 +08:00
|
|
|
else
|
2009-08-06 09:32:16 +08:00
|
|
|
return const_cast<ExplodedNode**>(&*(getVector(getPtr()).begin()));
|
2008-01-13 12:56:13 +08:00
|
|
|
}
|
|
|
|
|
2009-08-06 09:32:16 +08:00
|
|
|
ExplodedNode** ExplodedNode::NodeGroup::end() const {
|
2008-03-08 06:58:01 +08:00
|
|
|
if (getFlag())
|
|
|
|
return NULL;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-13 12:56:13 +08:00
|
|
|
if (getKind() == Size1)
|
2009-08-06 09:32:16 +08:00
|
|
|
return (ExplodedNode**) (getPtr() ? &P+1 : NULL);
|
2008-04-21 07:54:24 +08:00
|
|
|
else {
|
|
|
|
// Dereferencing end() is undefined behaviour. The vector is not empty, so
|
2008-04-22 15:37:18 +08:00
|
|
|
// we can dereference the last elem and then add 1 to the result.
|
2009-10-07 08:42:52 +08:00
|
|
|
return const_cast<ExplodedNode**>(getVector(getPtr()).end());
|
2008-04-21 07:54:24 +08:00
|
|
|
}
|
2008-01-13 12:56:13 +08:00
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
ExplodedNode *ExplodedGraph::getNode(const ProgramPoint &L,
|
2011-11-02 06:41:19 +08:00
|
|
|
const ProgramState *State,
|
|
|
|
bool IsSink,
|
|
|
|
bool* IsNew) {
|
2009-08-06 14:28:40 +08:00
|
|
|
// Profile 'State' to determine if we already have an existing node.
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::FoldingSetNodeID profile;
|
2011-08-13 07:37:29 +08:00
|
|
|
void *InsertPos = 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-02 06:41:19 +08:00
|
|
|
NodeTy::Profile(profile, L, State, IsSink);
|
2009-08-06 14:28:40 +08:00
|
|
|
NodeTy* V = Nodes.FindNodeOrInsertPos(profile, InsertPos);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 14:28:40 +08:00
|
|
|
if (!V) {
|
2011-02-09 09:27:33 +08:00
|
|
|
if (freeNodes && !getNodeList(freeNodes)->empty()) {
|
|
|
|
NodeList *nl = getNodeList(freeNodes);
|
|
|
|
V = nl->back();
|
|
|
|
nl->pop_back();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Allocate a new node.
|
|
|
|
V = (NodeTy*) getAllocator().Allocate<NodeTy>();
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:41:19 +08:00
|
|
|
new (V) NodeTy(L, State, IsSink);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-02-09 09:27:33 +08:00
|
|
|
if (reclaimNodes) {
|
|
|
|
if (!recentlyAllocatedNodes)
|
|
|
|
recentlyAllocatedNodes = new NodeList();
|
|
|
|
getNodeList(recentlyAllocatedNodes)->push_back(V);
|
|
|
|
}
|
|
|
|
|
2009-08-06 14:28:40 +08:00
|
|
|
// Insert the node into the node set and return it.
|
|
|
|
Nodes.InsertNode(V, InsertPos);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 14:28:40 +08:00
|
|
|
++NumNodes;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 14:28:40 +08:00
|
|
|
if (IsNew) *IsNew = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (IsNew) *IsNew = false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 14:28:40 +08:00
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<ExplodedGraph*, InterExplodedGraphMap*>
|
|
|
|
ExplodedGraph::Trim(const NodeTy* const* NBeg, const NodeTy* const* NEnd,
|
|
|
|
llvm::DenseMap<const void*, const void*> *InverseMap) const {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 14:28:40 +08:00
|
|
|
if (NBeg == NEnd)
|
|
|
|
return std::make_pair((ExplodedGraph*) 0,
|
|
|
|
(InterExplodedGraphMap*) 0);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 14:28:40 +08:00
|
|
|
assert (NBeg < NEnd);
|
|
|
|
|
|
|
|
llvm::OwningPtr<InterExplodedGraphMap> M(new InterExplodedGraphMap());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 14:28:40 +08:00
|
|
|
ExplodedGraph* G = TrimInternal(NBeg, NEnd, M.get(), InverseMap);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 14:28:40 +08:00
|
|
|
return std::make_pair(static_cast<ExplodedGraph*>(G), M.take());
|
|
|
|
}
|
|
|
|
|
|
|
|
ExplodedGraph*
|
|
|
|
ExplodedGraph::TrimInternal(const ExplodedNode* const* BeginSources,
|
|
|
|
const ExplodedNode* const* EndSources,
|
|
|
|
InterExplodedGraphMap* M,
|
|
|
|
llvm::DenseMap<const void*, const void*> *InverseMap) const {
|
|
|
|
|
2009-08-06 09:32:16 +08:00
|
|
|
typedef llvm::DenseSet<const ExplodedNode*> Pass1Ty;
|
2008-03-08 06:58:01 +08:00
|
|
|
Pass1Ty Pass1;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 09:32:16 +08:00
|
|
|
typedef llvm::DenseMap<const ExplodedNode*, ExplodedNode*> Pass2Ty;
|
2009-02-05 07:49:09 +08:00
|
|
|
Pass2Ty& Pass2 = M->M;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<const ExplodedNode*, 10> WL1, WL2;
|
2008-03-08 06:58:01 +08:00
|
|
|
|
2009-03-13 07:41:59 +08:00
|
|
|
// ===- Pass 1 (reverse DFS) -===
|
2009-08-06 09:32:16 +08:00
|
|
|
for (const ExplodedNode* const* I = BeginSources; I != EndSources; ++I) {
|
2009-02-21 05:10:26 +08:00
|
|
|
assert(*I);
|
|
|
|
WL1.push_back(*I);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// Process the first worklist until it is empty. Because it is a std::list
|
|
|
|
// it acts like a FIFO queue.
|
|
|
|
while (!WL1.empty()) {
|
2009-08-06 09:32:16 +08:00
|
|
|
const ExplodedNode *N = WL1.back();
|
2009-02-21 05:10:26 +08:00
|
|
|
WL1.pop_back();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// Have we already visited this node? If so, continue to the next one.
|
|
|
|
if (Pass1.count(N))
|
|
|
|
continue;
|
2009-01-24 08:55:43 +08:00
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// Otherwise, mark this node as visited.
|
|
|
|
Pass1.insert(N);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// If this is a root enqueue it to the second worklist.
|
|
|
|
if (N->Preds.empty()) {
|
|
|
|
WL2.push_back(N);
|
|
|
|
continue;
|
2008-03-08 06:58:01 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// Visit our predecessors and enqueue them.
|
2009-08-06 09:32:16 +08:00
|
|
|
for (ExplodedNode** I=N->Preds.begin(), **E=N->Preds.end(); I!=E; ++I)
|
2009-03-13 07:41:59 +08:00
|
|
|
WL1.push_back(*I);
|
2008-03-08 06:58:01 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// We didn't hit a root? Return with a null pointer for the new graph.
|
2008-03-08 06:58:01 +08:00
|
|
|
if (WL2.empty())
|
2009-02-05 07:49:09 +08:00
|
|
|
return 0;
|
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// Create an empty graph.
|
2009-08-06 14:28:40 +08:00
|
|
|
ExplodedGraph* G = MakeEmptyGraph();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
// ===- Pass 2 (forward DFS to construct the new graph) -===
|
2008-03-08 06:58:01 +08:00
|
|
|
while (!WL2.empty()) {
|
2011-08-13 07:37:29 +08:00
|
|
|
const ExplodedNode *N = WL2.back();
|
2008-03-08 06:58:01 +08:00
|
|
|
WL2.pop_back();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
// Skip this node if we have already processed it.
|
|
|
|
if (Pass2.find(N) != Pass2.end())
|
|
|
|
continue;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// Create the corresponding node in the new graph and record the mapping
|
|
|
|
// from the old node to the new node.
|
2011-11-02 06:41:19 +08:00
|
|
|
ExplodedNode *NewN = G->getNode(N->getLocation(), N->State, N->isSink(), 0);
|
2008-03-08 06:58:01 +08:00
|
|
|
Pass2[N] = NewN;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// Also record the reverse mapping from the new node to the old node.
|
2009-02-18 11:48:14 +08:00
|
|
|
if (InverseMap) (*InverseMap)[NewN] = N;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-21 05:10:26 +08:00
|
|
|
// If this node is a root, designate it as such in the graph.
|
2008-03-08 06:58:01 +08:00
|
|
|
if (N->Preds.empty())
|
|
|
|
G->addRoot(NewN);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
// In the case that some of the intended predecessors of NewN have already
|
|
|
|
// been created, we should hook them up as predecessors.
|
2009-02-21 05:10:26 +08:00
|
|
|
|
|
|
|
// Walk through the predecessors of 'N' and hook up their corresponding
|
|
|
|
// nodes in the new graph (if any) to the freshly created node.
|
2009-08-06 09:32:16 +08:00
|
|
|
for (ExplodedNode **I=N->Preds.begin(), **E=N->Preds.end(); I!=E; ++I) {
|
2008-03-08 06:58:01 +08:00
|
|
|
Pass2Ty::iterator PI = Pass2.find(*I);
|
|
|
|
if (PI == Pass2.end())
|
|
|
|
continue;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-10-07 08:42:52 +08:00
|
|
|
NewN->addPredecessor(PI->second, *G);
|
2008-03-08 06:58:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// In the case that some of the intended successors of NewN have already
|
|
|
|
// been created, we should hook them up as successors. Otherwise, enqueue
|
|
|
|
// the new nodes from the original graph that should have nodes created
|
|
|
|
// in the new graph.
|
2009-08-06 09:32:16 +08:00
|
|
|
for (ExplodedNode **I=N->Succs.begin(), **E=N->Succs.end(); I!=E; ++I) {
|
2009-09-09 23:08:12 +08:00
|
|
|
Pass2Ty::iterator PI = Pass2.find(*I);
|
2008-03-08 06:58:01 +08:00
|
|
|
if (PI != Pass2.end()) {
|
2009-10-07 08:42:52 +08:00
|
|
|
PI->second->addPredecessor(NewN, *G);
|
2008-03-08 06:58:01 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue nodes to the worklist that were marked during pass 1.
|
2009-02-21 05:10:26 +08:00
|
|
|
if (Pass1.count(*I))
|
|
|
|
WL2.push_back(*I);
|
2008-03-08 06:58:01 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
return G;
|
|
|
|
}
|
2009-02-05 07:49:09 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void InterExplodedGraphMap::anchor() { }
|
|
|
|
|
2009-08-06 09:32:16 +08:00
|
|
|
ExplodedNode*
|
2011-08-13 07:37:29 +08:00
|
|
|
InterExplodedGraphMap::getMappedNode(const ExplodedNode *N) const {
|
2009-11-10 09:17:45 +08:00
|
|
|
llvm::DenseMap<const ExplodedNode*, ExplodedNode*>::const_iterator I =
|
2009-02-05 07:49:09 +08:00
|
|
|
M.find(N);
|
|
|
|
|
|
|
|
return I == M.end() ? 0 : I->second;
|
|
|
|
}
|
|
|
|
|