2009-06-02 13:58:47 -04:00
|
|
|
//=-- ExplodedGraph.h - 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."
|
2010-04-02 04:55:10 -04:00
|
|
|
// See "Precise interprocedural dataflow analysis via graph reachability"
|
|
|
|
|
// by Reps, Horwitz, and Sagiv
|
|
|
|
|
// (http://portal.acm.org/citation.cfm?id=199462) for the definition of an
|
|
|
|
|
// exploded graph.
|
2009-06-02 13:58:47 -04:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2011-02-20 08:06:31 -05:00
|
|
|
#ifndef LLVM_CLANG_GR_EXPLODEDGRAPH
|
|
|
|
|
#define LLVM_CLANG_GR_EXPLODEDGRAPH
|
2009-06-02 13:58:47 -04:00
|
|
|
|
|
|
|
|
#include "clang/Analysis/ProgramPoint.h"
|
2010-02-16 04:31:36 -05:00
|
|
|
#include "clang/Analysis/AnalysisContext.h"
|
2009-06-02 13:58:47 -04:00
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
|
|
|
|
#include "llvm/ADT/GraphTraits.h"
|
|
|
|
|
#include "llvm/ADT/DepthFirstIterator.h"
|
|
|
|
|
#include "llvm/Support/Casting.h"
|
2009-10-14 14:03:49 -04:00
|
|
|
#include "clang/Analysis/Support/BumpVector.h"
|
2011-10-20 17:14:49 -04:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
|
2012-04-14 10:01:31 -04:00
|
|
|
#include <vector>
|
2009-06-02 13:58:47 -04:00
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
|
|
class CFG;
|
2011-02-20 08:06:31 -05:00
|
|
|
|
|
|
|
|
namespace ento {
|
|
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
class ExplodedGraph;
|
2009-06-02 13:58:47 -04:00
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
// ExplodedGraph "implementation" classes. These classes are not typed to
|
|
|
|
|
// contain a specific kind of state. Typed-specialized versions are defined
|
|
|
|
|
// on top of these classes.
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-02-20 08:06:31 -05:00
|
|
|
// ExplodedNode is not constified all over the engine because we need to add
|
|
|
|
|
// successors to it at any time after creating it.
|
|
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
class ExplodedNode : public llvm::FoldingSetNode {
|
|
|
|
|
friend class ExplodedGraph;
|
2011-02-20 08:06:31 -05:00
|
|
|
friend class CoreEngine;
|
2012-04-14 10:01:31 -04:00
|
|
|
friend class NodeBuilder;
|
2011-02-20 08:06:31 -05:00
|
|
|
friend class BranchNodeBuilder;
|
|
|
|
|
friend class IndirectGotoNodeBuilder;
|
|
|
|
|
friend class SwitchNodeBuilder;
|
|
|
|
|
friend class EndOfFunctionNodeBuilder;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
/// Efficiently stores a list of ExplodedNodes, or an optional flag.
|
|
|
|
|
///
|
|
|
|
|
/// NodeGroup provides opaque storage for a list of ExplodedNodes, optimizing
|
|
|
|
|
/// for the case when there is only one node in the group. This is a fairly
|
|
|
|
|
/// common case in an ExplodedGraph, where most nodes have only one
|
|
|
|
|
/// predecessor and many have only one successor. It can also be used to
|
|
|
|
|
/// store a flag rather than a node list, which ExplodedNode uses to mark
|
|
|
|
|
/// whether a node is a sink. If the flag is set, the group is implicitly
|
|
|
|
|
/// empty and no nodes may be added.
|
2009-06-02 13:58:47 -04:00
|
|
|
class NodeGroup {
|
2012-12-02 08:20:44 -05:00
|
|
|
// Conceptually a discriminated union. If the low bit is set, the node is
|
|
|
|
|
// a sink. If the low bit is not set, the pointer refers to the storage
|
|
|
|
|
// for the nodes in the group.
|
|
|
|
|
// This is not a PointerIntPair in order to keep the storage type opaque.
|
2009-06-02 13:58:47 -04:00
|
|
|
uintptr_t P;
|
2011-02-20 08:06:31 -05:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
public:
|
2012-12-02 08:20:44 -05:00
|
|
|
NodeGroup(bool Flag = false) : P(Flag) {
|
|
|
|
|
assert(getFlag() == Flag);
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
ExplodedNode * const *begin() const;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
ExplodedNode * const *end() const;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
unsigned size() const;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
bool empty() const { return P == 0 || getFlag() != 0; }
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
/// Adds a node to the list.
|
|
|
|
|
///
|
|
|
|
|
/// The group must not have been created with its flag set.
|
2011-10-20 17:14:49 -04:00
|
|
|
void addNode(ExplodedNode *N, ExplodedGraph &G);
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
/// Replaces the single node in this group with a new node.
|
|
|
|
|
///
|
|
|
|
|
/// Note that this should only be used when you know the group was not
|
|
|
|
|
/// created with its flag set, and that the group is empty or contains
|
|
|
|
|
/// only a single node.
|
2011-02-20 08:06:31 -05:00
|
|
|
void replaceNode(ExplodedNode *node);
|
|
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
/// Returns whether this group was created with its flag set.
|
2009-06-02 13:58:47 -04:00
|
|
|
bool getFlag() const {
|
2012-12-02 08:20:44 -05:00
|
|
|
return (P & 1);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
};
|
|
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
/// Location - The program location (within a function body) associated
|
|
|
|
|
/// with this node.
|
|
|
|
|
const ProgramPoint Location;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
/// State - The state associated with this node.
|
2012-04-14 10:01:31 -04:00
|
|
|
ProgramStateRef State;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
/// Preds - The predecessors of this node.
|
|
|
|
|
NodeGroup Preds;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
/// Succs - The successors of this node.
|
|
|
|
|
NodeGroup Succs;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
public:
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-04-14 10:01:31 -04:00
|
|
|
explicit ExplodedNode(const ProgramPoint &loc, ProgramStateRef state,
|
|
|
|
|
bool IsSink)
|
2012-12-02 08:20:44 -05:00
|
|
|
: Location(loc), State(state), Succs(IsSink) {
|
|
|
|
|
assert(isSink() == IsSink);
|
2011-02-20 08:06:31 -05:00
|
|
|
}
|
|
|
|
|
|
2012-04-14 10:01:31 -04:00
|
|
|
~ExplodedNode() {}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
/// getLocation - Returns the edge associated with the given node.
|
|
|
|
|
ProgramPoint getLocation() const { return Location; }
|
|
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
const LocationContext *getLocationContext() const {
|
|
|
|
|
return getLocation().getLocationContext();
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
|
|
|
|
|
2012-08-15 16:02:54 -04:00
|
|
|
const StackFrameContext *getStackFrame() const {
|
|
|
|
|
return getLocationContext()->getCurrentStackFrame();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
const Decl &getCodeDecl() const { return *getLocationContext()->getDecl(); }
|
2009-06-02 13:58:47 -04:00
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
CFG &getCFG() const { return *getLocationContext()->getCFG(); }
|
|
|
|
|
|
|
|
|
|
ParentMap &getParentMap() const {return getLocationContext()->getParentMap();}
|
|
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
template <typename T>
|
|
|
|
|
T &getAnalysis() const {
|
|
|
|
|
return *getLocationContext()->getAnalysis<T>();
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-04-14 10:01:31 -04:00
|
|
|
ProgramStateRef getState() const { return State; }
|
2009-10-14 14:03:49 -04:00
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
const T* getLocationAs() const { return llvm::dyn_cast<T>(&Location); }
|
|
|
|
|
|
|
|
|
|
static void Profile(llvm::FoldingSetNodeID &ID,
|
2012-04-14 10:01:31 -04:00
|
|
|
const ProgramPoint &Loc,
|
2012-08-15 16:02:54 -04:00
|
|
|
const ProgramStateRef &state,
|
2012-04-14 10:01:31 -04:00
|
|
|
bool IsSink) {
|
2009-06-02 13:58:47 -04:00
|
|
|
ID.Add(Loc);
|
2012-04-14 10:01:31 -04:00
|
|
|
ID.AddPointer(state.getPtr());
|
|
|
|
|
ID.AddBoolean(IsSink);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
|
|
|
|
void Profile(llvm::FoldingSetNodeID& ID) const {
|
2012-04-14 10:01:31 -04:00
|
|
|
Profile(ID, getLocation(), getState(), isSink());
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
|
|
|
|
/// addPredeccessor - Adds a predecessor to the current node, and
|
|
|
|
|
/// in tandem add this node as a successor of the other node.
|
2011-10-20 17:14:49 -04:00
|
|
|
void addPredecessor(ExplodedNode *V, ExplodedGraph &G);
|
2009-10-14 14:03:49 -04:00
|
|
|
|
|
|
|
|
unsigned succ_size() const { return Succs.size(); }
|
|
|
|
|
unsigned pred_size() const { return Preds.size(); }
|
|
|
|
|
bool succ_empty() const { return Succs.empty(); }
|
|
|
|
|
bool pred_empty() const { return Preds.empty(); }
|
|
|
|
|
|
|
|
|
|
bool isSink() const { return Succs.getFlag(); }
|
2012-04-14 10:01:31 -04:00
|
|
|
|
|
|
|
|
bool hasSinglePred() const {
|
|
|
|
|
return (pred_size() == 1);
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
ExplodedNode *getFirstPred() {
|
2009-06-02 13:58:47 -04:00
|
|
|
return pred_empty() ? NULL : *(pred_begin());
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
const ExplodedNode *getFirstPred() const {
|
2009-06-02 13:58:47 -04:00
|
|
|
return const_cast<ExplodedNode*>(this)->getFirstPred();
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
// Iterators over successor and predecessor vertices.
|
2012-12-02 08:20:44 -05:00
|
|
|
typedef ExplodedNode* const * succ_iterator;
|
2009-06-02 13:58:47 -04:00
|
|
|
typedef const ExplodedNode* const * const_succ_iterator;
|
2012-12-02 08:20:44 -05:00
|
|
|
typedef ExplodedNode* const * pred_iterator;
|
2009-06-02 13:58:47 -04:00
|
|
|
typedef const ExplodedNode* const * const_pred_iterator;
|
|
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
pred_iterator pred_begin() { return Preds.begin(); }
|
|
|
|
|
pred_iterator pred_end() { return Preds.end(); }
|
2009-06-02 13:58:47 -04:00
|
|
|
|
|
|
|
|
const_pred_iterator pred_begin() const {
|
|
|
|
|
return const_cast<ExplodedNode*>(this)->pred_begin();
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
2009-06-02 13:58:47 -04:00
|
|
|
const_pred_iterator pred_end() const {
|
|
|
|
|
return const_cast<ExplodedNode*>(this)->pred_end();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
succ_iterator succ_begin() { return Succs.begin(); }
|
|
|
|
|
succ_iterator succ_end() { return Succs.end(); }
|
2009-06-02 13:58:47 -04:00
|
|
|
|
|
|
|
|
const_succ_iterator succ_begin() const {
|
|
|
|
|
return const_cast<ExplodedNode*>(this)->succ_begin();
|
|
|
|
|
}
|
|
|
|
|
const_succ_iterator succ_end() const {
|
|
|
|
|
return const_cast<ExplodedNode*>(this)->succ_end();
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
|
|
|
|
// For debugging.
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
class Auditor {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~Auditor();
|
2011-10-20 17:14:49 -04:00
|
|
|
virtual void AddEdge(ExplodedNode *Src, ExplodedNode *Dst) = 0;
|
2009-10-14 14:03:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void SetAuditor(Auditor* A);
|
2011-02-20 08:06:31 -05:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void replaceSuccessor(ExplodedNode *node) { Succs.replaceNode(node); }
|
|
|
|
|
void replacePredecessor(ExplodedNode *node) { Preds.replaceNode(node); }
|
2009-06-02 13:58:47 -04:00
|
|
|
};
|
|
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
// FIXME: Is this class necessary?
|
|
|
|
|
class InterExplodedGraphMap {
|
2012-04-14 10:01:31 -04:00
|
|
|
virtual void anchor();
|
2009-10-14 14:03:49 -04:00
|
|
|
llvm::DenseMap<const ExplodedNode*, ExplodedNode*> M;
|
|
|
|
|
friend class ExplodedGraph;
|
2009-06-02 13:58:47 -04:00
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
public:
|
2011-10-20 17:14:49 -04:00
|
|
|
ExplodedNode *getMappedNode(const ExplodedNode *N) const;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2010-01-01 05:34:51 -05:00
|
|
|
InterExplodedGraphMap() {}
|
2009-10-14 14:03:49 -04:00
|
|
|
virtual ~InterExplodedGraphMap() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ExplodedGraph {
|
2009-06-02 13:58:47 -04:00
|
|
|
protected:
|
2011-02-20 08:06:31 -05:00
|
|
|
friend class CoreEngine;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
// Type definitions.
|
2012-04-14 10:01:31 -04:00
|
|
|
typedef std::vector<ExplodedNode *> NodeVector;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-04-14 10:01:31 -04:00
|
|
|
/// The roots of the simulation graph. Usually there will be only
|
2009-06-02 13:58:47 -04:00
|
|
|
/// one, but clients are free to establish multiple subgraphs within a single
|
|
|
|
|
/// SimulGraph. Moreover, these subgraphs can often merge when paths from
|
|
|
|
|
/// different roots reach the same state at the same program location.
|
2012-04-14 10:01:31 -04:00
|
|
|
NodeVector Roots;
|
2009-06-02 13:58:47 -04:00
|
|
|
|
2012-04-14 10:01:31 -04:00
|
|
|
/// The nodes in the simulation graph which have been
|
|
|
|
|
/// specially marked as the endpoint of an abstract simulation path.
|
|
|
|
|
NodeVector EndNodes;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
|
|
|
|
/// Nodes - The nodes in the graph.
|
|
|
|
|
llvm::FoldingSet<ExplodedNode> Nodes;
|
|
|
|
|
|
|
|
|
|
/// BVC - Allocator and context for allocating nodes and their predecessor
|
|
|
|
|
/// and successor groups.
|
|
|
|
|
BumpVectorContext BVC;
|
|
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
/// NumNodes - The number of nodes in the graph.
|
|
|
|
|
unsigned NumNodes;
|
2011-02-20 08:06:31 -05:00
|
|
|
|
|
|
|
|
/// A list of recently allocated nodes that can potentially be recycled.
|
2012-04-14 10:01:31 -04:00
|
|
|
NodeVector ChangedNodes;
|
2011-02-20 08:06:31 -05:00
|
|
|
|
|
|
|
|
/// A list of nodes that can be reused.
|
2012-04-14 10:01:31 -04:00
|
|
|
NodeVector FreeNodes;
|
2011-02-20 08:06:31 -05:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
/// Determines how often nodes are reclaimed.
|
|
|
|
|
///
|
|
|
|
|
/// If this is 0, nodes will never be reclaimed.
|
|
|
|
|
unsigned ReclaimNodeInterval;
|
2012-04-14 10:01:31 -04:00
|
|
|
|
|
|
|
|
/// Counter to determine when to reclaim nodes.
|
2012-12-02 08:20:44 -05:00
|
|
|
unsigned ReclaimCounter;
|
2009-06-02 13:58:47 -04:00
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
public:
|
2012-04-14 10:01:31 -04:00
|
|
|
|
|
|
|
|
/// \brief Retrieve the node associated with a (Location,State) pair,
|
2009-10-14 14:03:49 -04:00
|
|
|
/// where the 'Location' is a ProgramPoint in the CFG. If no node for
|
2012-04-14 10:01:31 -04:00
|
|
|
/// this pair exists, it is created. IsNew is set to true if
|
2009-10-14 14:03:49 -04:00
|
|
|
/// the node was freshly created.
|
2012-04-14 10:01:31 -04:00
|
|
|
ExplodedNode *getNode(const ProgramPoint &L, ProgramStateRef State,
|
|
|
|
|
bool IsSink = false,
|
2009-10-14 14:03:49 -04:00
|
|
|
bool* IsNew = 0);
|
|
|
|
|
|
|
|
|
|
ExplodedGraph* MakeEmptyGraph() const {
|
2010-07-13 13:21:42 -04:00
|
|
|
return new ExplodedGraph();
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
2009-06-02 13:58:47 -04:00
|
|
|
|
|
|
|
|
/// addRoot - Add an untyped node to the set of roots.
|
2011-10-20 17:14:49 -04:00
|
|
|
ExplodedNode *addRoot(ExplodedNode *V) {
|
2009-06-02 13:58:47 -04:00
|
|
|
Roots.push_back(V);
|
|
|
|
|
return V;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// addEndOfPath - Add an untyped node to the set of EOP nodes.
|
2011-10-20 17:14:49 -04:00
|
|
|
ExplodedNode *addEndOfPath(ExplodedNode *V) {
|
2009-06-02 13:58:47 -04:00
|
|
|
EndNodes.push_back(V);
|
|
|
|
|
return V;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-14 10:01:31 -04:00
|
|
|
ExplodedGraph();
|
2009-06-02 13:58:47 -04:00
|
|
|
|
2011-02-20 08:06:31 -05:00
|
|
|
~ExplodedGraph();
|
|
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
unsigned num_roots() const { return Roots.size(); }
|
|
|
|
|
unsigned num_eops() const { return EndNodes.size(); }
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
bool empty() const { return NumNodes == 0; }
|
|
|
|
|
unsigned size() const { return NumNodes; }
|
|
|
|
|
|
|
|
|
|
// Iterators.
|
2009-10-14 14:03:49 -04:00
|
|
|
typedef ExplodedNode NodeTy;
|
|
|
|
|
typedef llvm::FoldingSet<ExplodedNode> AllNodesTy;
|
2012-04-14 10:01:31 -04:00
|
|
|
typedef NodeVector::iterator roots_iterator;
|
|
|
|
|
typedef NodeVector::const_iterator const_roots_iterator;
|
|
|
|
|
typedef NodeVector::iterator eop_iterator;
|
|
|
|
|
typedef NodeVector::const_iterator const_eop_iterator;
|
2009-10-14 14:03:49 -04:00
|
|
|
typedef AllNodesTy::iterator node_iterator;
|
|
|
|
|
typedef AllNodesTy::const_iterator const_node_iterator;
|
2009-06-02 13:58:47 -04:00
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
node_iterator nodes_begin() { return Nodes.begin(); }
|
2009-06-02 13:58:47 -04:00
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
node_iterator nodes_end() { return Nodes.end(); }
|
|
|
|
|
|
|
|
|
|
const_node_iterator nodes_begin() const { return Nodes.begin(); }
|
|
|
|
|
|
|
|
|
|
const_node_iterator nodes_end() const { return Nodes.end(); }
|
|
|
|
|
|
|
|
|
|
roots_iterator roots_begin() { return Roots.begin(); }
|
|
|
|
|
|
|
|
|
|
roots_iterator roots_end() { return Roots.end(); }
|
|
|
|
|
|
|
|
|
|
const_roots_iterator roots_begin() const { return Roots.begin(); }
|
|
|
|
|
|
|
|
|
|
const_roots_iterator roots_end() const { return Roots.end(); }
|
|
|
|
|
|
|
|
|
|
eop_iterator eop_begin() { return EndNodes.begin(); }
|
|
|
|
|
|
|
|
|
|
eop_iterator eop_end() { return EndNodes.end(); }
|
|
|
|
|
|
|
|
|
|
const_eop_iterator eop_begin() const { return EndNodes.begin(); }
|
|
|
|
|
|
|
|
|
|
const_eop_iterator eop_end() const { return EndNodes.end(); }
|
|
|
|
|
|
|
|
|
|
llvm::BumpPtrAllocator & getAllocator() { return BVC.getAllocator(); }
|
|
|
|
|
BumpVectorContext &getNodeAllocator() { return BVC; }
|
|
|
|
|
|
|
|
|
|
typedef llvm::DenseMap<const ExplodedNode*, ExplodedNode*> NodeMap;
|
|
|
|
|
|
|
|
|
|
std::pair<ExplodedGraph*, InterExplodedGraphMap*>
|
2009-06-02 13:58:47 -04:00
|
|
|
Trim(const NodeTy* const* NBeg, const NodeTy* const* NEnd,
|
2009-10-14 14:03:49 -04:00
|
|
|
llvm::DenseMap<const void*, const void*> *InverseMap = 0) const;
|
|
|
|
|
|
|
|
|
|
ExplodedGraph* TrimInternal(const ExplodedNode* const * NBeg,
|
|
|
|
|
const ExplodedNode* const * NEnd,
|
|
|
|
|
InterExplodedGraphMap *M,
|
|
|
|
|
llvm::DenseMap<const void*, const void*> *InverseMap) const;
|
2011-02-20 08:06:31 -05:00
|
|
|
|
|
|
|
|
/// Enable tracking of recently allocated nodes for potential reclamation
|
|
|
|
|
/// when calling reclaimRecentlyAllocatedNodes().
|
2012-12-02 08:20:44 -05:00
|
|
|
void enableNodeReclamation(unsigned Interval) {
|
|
|
|
|
ReclaimCounter = ReclaimNodeInterval = Interval;
|
|
|
|
|
}
|
2011-02-20 08:06:31 -05:00
|
|
|
|
|
|
|
|
/// Reclaim "uninteresting" nodes created since the last time this method
|
|
|
|
|
/// was called.
|
|
|
|
|
void reclaimRecentlyAllocatedNodes();
|
2012-04-14 10:01:31 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool shouldCollect(const ExplodedNode *node);
|
|
|
|
|
void collectNode(ExplodedNode *node);
|
2009-06-02 13:58:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ExplodedNodeSet {
|
2009-10-14 14:03:49 -04:00
|
|
|
typedef llvm::SmallPtrSet<ExplodedNode*,5> ImplTy;
|
2009-06-02 13:58:47 -04:00
|
|
|
ImplTy Impl;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
public:
|
2011-10-20 17:14:49 -04:00
|
|
|
ExplodedNodeSet(ExplodedNode *N) {
|
2009-10-14 14:03:49 -04:00
|
|
|
assert (N && !static_cast<ExplodedNode*>(N)->isSink());
|
2009-06-02 13:58:47 -04:00
|
|
|
Impl.insert(N);
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
ExplodedNodeSet() {}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
inline void Add(ExplodedNode *N) {
|
2009-10-14 14:03:49 -04:00
|
|
|
if (N && !static_cast<ExplodedNode*>(N)->isSink()) Impl.insert(N);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef ImplTy::iterator iterator;
|
|
|
|
|
typedef ImplTy::const_iterator const_iterator;
|
2009-06-02 13:58:47 -04:00
|
|
|
|
2009-12-01 06:08:04 -05:00
|
|
|
unsigned size() const { return Impl.size(); }
|
|
|
|
|
bool empty() const { return Impl.empty(); }
|
2012-04-14 10:01:31 -04:00
|
|
|
bool erase(ExplodedNode *N) { return Impl.erase(N); }
|
2009-12-01 06:08:04 -05:00
|
|
|
|
|
|
|
|
void clear() { Impl.clear(); }
|
|
|
|
|
void insert(const ExplodedNodeSet &S) {
|
2012-04-14 10:01:31 -04:00
|
|
|
assert(&S != this);
|
2009-12-01 06:08:04 -05:00
|
|
|
if (empty())
|
|
|
|
|
Impl = S.Impl;
|
|
|
|
|
else
|
|
|
|
|
Impl.insert(S.begin(), S.end());
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
inline iterator begin() { return Impl.begin(); }
|
|
|
|
|
inline iterator end() { return Impl.end(); }
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
inline const_iterator begin() const { return Impl.begin(); }
|
|
|
|
|
inline const_iterator end() const { return Impl.end(); }
|
2009-10-14 14:03:49 -04:00
|
|
|
};
|
|
|
|
|
|
2011-02-20 08:06:31 -05:00
|
|
|
} // end GR namespace
|
|
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
} // end clang namespace
|
|
|
|
|
|
|
|
|
|
// GraphTraits
|
|
|
|
|
|
|
|
|
|
namespace llvm {
|
2011-02-20 08:06:31 -05:00
|
|
|
template<> struct GraphTraits<clang::ento::ExplodedNode*> {
|
|
|
|
|
typedef clang::ento::ExplodedNode NodeType;
|
2009-10-14 14:03:49 -04:00
|
|
|
typedef NodeType::succ_iterator ChildIteratorType;
|
2009-06-02 13:58:47 -04:00
|
|
|
typedef llvm::df_iterator<NodeType*> nodes_iterator;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline NodeType* getEntryNode(NodeType* N) {
|
|
|
|
|
return N;
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline ChildIteratorType child_begin(NodeType* N) {
|
|
|
|
|
return N->succ_begin();
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline ChildIteratorType child_end(NodeType* N) {
|
|
|
|
|
return N->succ_end();
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline nodes_iterator nodes_begin(NodeType* N) {
|
|
|
|
|
return df_begin(N);
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline nodes_iterator nodes_end(NodeType* N) {
|
|
|
|
|
return df_end(N);
|
|
|
|
|
}
|
|
|
|
|
};
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-02-20 08:06:31 -05:00
|
|
|
template<> struct GraphTraits<const clang::ento::ExplodedNode*> {
|
|
|
|
|
typedef const clang::ento::ExplodedNode NodeType;
|
2009-10-14 14:03:49 -04:00
|
|
|
typedef NodeType::const_succ_iterator ChildIteratorType;
|
2009-06-02 13:58:47 -04:00
|
|
|
typedef llvm::df_iterator<NodeType*> nodes_iterator;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline NodeType* getEntryNode(NodeType* N) {
|
|
|
|
|
return N;
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline ChildIteratorType child_begin(NodeType* N) {
|
|
|
|
|
return N->succ_begin();
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline ChildIteratorType child_end(NodeType* N) {
|
|
|
|
|
return N->succ_end();
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline nodes_iterator nodes_begin(NodeType* N) {
|
|
|
|
|
return df_begin(N);
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static inline nodes_iterator nodes_end(NodeType* N) {
|
|
|
|
|
return df_end(N);
|
|
|
|
|
}
|
|
|
|
|
};
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
} // end llvm namespace
|
|
|
|
|
|
|
|
|
|
#endif
|