[cfe-commits] r47068 - in /cfe/trunk: Analysis/GRConstants.cpp Analysis/GREngine.cpp include/clang/Analysis/PathSensitive/GREngine.h
Ted Kremenek
kremenek at apple.com
Wed Feb 13 09:27:37 PST 2008
Author: kremenek
Date: Wed Feb 13 11:27:37 2008
New Revision: 47068
URL: http://llvm.org/viewvc/llvm-project?rev=47068&view=rev
Log:
Simplify GRIndirectGotoNodeBuilder.
Modified:
cfe/trunk/Analysis/GRConstants.cpp
cfe/trunk/Analysis/GREngine.cpp
cfe/trunk/include/clang/Analysis/PathSensitive/GREngine.h
Modified: cfe/trunk/Analysis/GRConstants.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRConstants.cpp?rev=47068&r1=47067&r2=47068&view=diff
==============================================================================
--- cfe/trunk/Analysis/GRConstants.cpp (original)
+++ cfe/trunk/Analysis/GRConstants.cpp Wed Feb 13 11:27:37 2008
@@ -449,10 +449,8 @@
LabelStmt* L = cast<lval::GotoLabel>(V).getLabel();
for (iterator I=builder.begin(), E=builder.end(); I != E; ++I) {
- IndirectGotoNodeBuilder::Destination D = *I;
-
- if (D.getLabel() == L) {
- builder.generateNode(D, St);
+ if (I.getLabel() == L) {
+ builder.generateNode(I, St);
return;
}
}
@@ -463,7 +461,7 @@
if (isa<lval::ConcreteInt>(V) || isa<UninitializedVal>(V)) {
// Dispatch to the first target and mark it as a sink.
- NodeTy* N = builder.generateNode(*builder.begin(), St, true);
+ NodeTy* N = builder.generateNode(builder.begin(), St, true);
UninitBranches.insert(N);
return;
}
@@ -473,7 +471,7 @@
assert (isa<UnknownVal>(V));
for (iterator I=builder.begin(), E=builder.end(); I != E; ++I)
- builder.generateNode(*I, St);
+ builder.generateNode(I, St);
}
void GRConstants::VisitLogicalExpr(BinaryOperator* B, NodeTy* Pred,
Modified: cfe/trunk/Analysis/GREngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GREngine.cpp?rev=47068&r1=47067&r2=47068&view=diff
==============================================================================
--- cfe/trunk/Analysis/GREngine.cpp (original)
+++ cfe/trunk/Analysis/GREngine.cpp Wed Feb 13 11:27:37 2008
@@ -361,32 +361,15 @@
if (!(*I)->isSink()) Eng.WList->Enqueue(*I);
}
-GRIndirectGotoNodeBuilderImpl::Destination
-GRIndirectGotoNodeBuilderImpl::Iterator::operator*() {
- CFGBlock* B = *I;
- assert (!B->empty());
- LabelStmt* L = cast<LabelStmt>(B->getLabel());
- return Destination(L, *I);
-}
-
-GRIndirectGotoNodeBuilderImpl::Iterator
-GRIndirectGotoNodeBuilderImpl::begin() {
- return Iterator(DispatchBlock.succ_begin());
-}
-
-GRIndirectGotoNodeBuilderImpl::Iterator
-GRIndirectGotoNodeBuilderImpl::end() {
- return Iterator(DispatchBlock.succ_end());
-}
ExplodedNodeImpl*
-GRIndirectGotoNodeBuilderImpl::generateNodeImpl(const Destination& D,
+GRIndirectGotoNodeBuilderImpl::generateNodeImpl(const Iterator& I,
void* St,
bool isSink) {
bool IsNew;
ExplodedNodeImpl* Succ =
- Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, D.getBlock(), true),
+ Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, I.getBlock(), true),
St, &IsNew);
Succ->addPredecessor(Pred);
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GREngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GREngine.h?rev=47068&r1=47067&r2=47068&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GREngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GREngine.h Wed Feb 13 11:27:37 2008
@@ -15,11 +15,13 @@
#ifndef LLVM_CLANG_ANALYSIS_GRENGINE
#define LLVM_CLANG_ANALYSIS_GRENGINE
+#include "clang/AST/Stmt.h"
#include "clang/Analysis/PathSensitive/ExplodedGraph.h"
#include "clang/Analysis/PathSensitive/GRWorkList.h"
#include "clang/Analysis/PathSensitive/GRBlockCounter.h"
#include "llvm/ADT/OwningPtr.h"
+
namespace clang {
class GRStmtNodeBuilderImpl;
@@ -27,7 +29,16 @@
class GRIndirectGotoNodeBuilderImpl;
class GRWorkList;
class LabelStmt;
-
+
+//===----------------------------------------------------------------------===//
+/// GREngineImpl - Implements the core logic of the graph-reachability analysis.
+/// It traverses the CFG and generates the ExplodedGraph. Program "states"
+/// are treated as opaque void pointers. The template class GREngine
+/// (which subclasses GREngineImpl) provides the matching component
+/// to the engine that knows the actual types for states. Note that this
+/// engine only dispatches to transfer functions as the statement and
+/// block-level. The analyses themselves must implement any transfer
+/// function logic and the sub-expression level (if any).
class GREngineImpl {
protected:
friend class GRStmtNodeBuilderImpl;
@@ -262,20 +273,7 @@
GREngineImpl* eng)
: Eng(*eng), Src(src), DispatchBlock(*dispatch), E(e), Pred(pred) {}
- class Iterator;
-
- class Destination {
- LabelStmt* L;
- CFGBlock* B;
- friend class Iterator;
- Destination(LabelStmt* l, CFGBlock* b) : L(l), B(b) {}
-
- public:
- CFGBlock* getBlock() const { return B; }
- LabelStmt* getLabel() const { return L; }
- };
-
class Iterator {
CFGBlock::succ_iterator I;
@@ -286,13 +284,19 @@
Iterator& operator++() { ++I; return *this; }
bool operator!=(const Iterator& X) const { return I != X.I; }
- Destination operator*();
+ LabelStmt* getLabel() const {
+ return llvm::cast<LabelStmt>((*I)->getLabel());
+ }
+
+ CFGBlock* getBlock() const {
+ return *I;
+ }
};
- Iterator begin();
- Iterator end();
+ Iterator begin() { return Iterator(DispatchBlock.succ_begin()); }
+ Iterator end() { return Iterator(DispatchBlock.succ_end()); }
- ExplodedNodeImpl* generateNodeImpl(const Destination& D, void* State,
+ ExplodedNodeImpl* generateNodeImpl(const Iterator& I, void* State,
bool isSink);
inline Expr* getTarget() const { return E; }
@@ -312,18 +316,15 @@
GRIndirectGotoNodeBuilder(GRIndirectGotoNodeBuilderImpl& nb) : NB(nb) {}
typedef GRIndirectGotoNodeBuilderImpl::Iterator iterator;
- typedef GRIndirectGotoNodeBuilderImpl::Destination Destination;
inline iterator begin() { return NB.begin(); }
inline iterator end() { return NB.end(); }
inline Expr* getTarget() const { return NB.getTarget(); }
- inline NodeTy* generateNode(const Destination& D, StateTy St,
- bool isSink = false) {
-
+ inline NodeTy* generateNode(const iterator& I, StateTy St, bool isSink=false){
void *state = GRTrait<StateTy>::toPtr(St);
- return static_cast<NodeTy*>(NB.generateNodeImpl(D, state, isSink));
+ return static_cast<NodeTy*>(NB.generateNodeImpl(I, state, isSink));
}
inline StateTy getState() const {
More information about the cfe-commits
mailing list