From: Ted Kremenek Date: Wed, 13 Feb 2008 17:27:37 +0000 (+0000) Subject: Simplify GRIndirectGotoNodeBuilder. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=24f1a967741ff9f8025ee23be12ba6feacc31f77;p=clang Simplify GRIndirectGotoNodeBuilder. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47068 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp index c2395512c5..dad8b08cf3 100644 --- a/Analysis/GRConstants.cpp +++ b/Analysis/GRConstants.cpp @@ -449,10 +449,8 @@ void GRConstants::ProcessIndirectGoto(IndirectGotoNodeBuilder& builder) { LabelStmt* L = cast(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 @@ void GRConstants::ProcessIndirectGoto(IndirectGotoNodeBuilder& builder) { if (isa(V) || isa(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 @@ void GRConstants::ProcessIndirectGoto(IndirectGotoNodeBuilder& builder) { assert (isa(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, diff --git a/Analysis/GREngine.cpp b/Analysis/GREngine.cpp index 3d46fa35fe..a15bcb5ba9 100644 --- a/Analysis/GREngine.cpp +++ b/Analysis/GREngine.cpp @@ -361,32 +361,15 @@ GRBranchNodeBuilderImpl::~GRBranchNodeBuilderImpl() { if (!(*I)->isSink()) Eng.WList->Enqueue(*I); } -GRIndirectGotoNodeBuilderImpl::Destination -GRIndirectGotoNodeBuilderImpl::Iterator::operator*() { - CFGBlock* B = *I; - assert (!B->empty()); - LabelStmt* L = cast(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); diff --git a/include/clang/Analysis/PathSensitive/GREngine.h b/include/clang/Analysis/PathSensitive/GREngine.h index 4e1f2095cb..bceb1b8594 100644 --- a/include/clang/Analysis/PathSensitive/GREngine.h +++ b/include/clang/Analysis/PathSensitive/GREngine.h @@ -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 GRBranchNodeBuilderImpl; 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 @@ public: 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 @@ public: Iterator& operator++() { ++I; return *this; } bool operator!=(const Iterator& X) const { return I != X.I; } - Destination operator*(); + LabelStmt* getLabel() const { + return llvm::cast((*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 @@ public: 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::toPtr(St); - return static_cast(NB.generateNodeImpl(D, state, isSink)); + return static_cast(NB.generateNodeImpl(I, state, isSink)); } inline StateTy getState() const {