[cfe-commits] r92116 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRCoreEngine.h lib/Analysis/CallInliner.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Wed Dec 23 18:25:21 PST 2009
Author: zhongxingxu
Date: Wed Dec 23 20:25:21 2009
New Revision: 92116
URL: http://llvm.org/viewvc/llvm-project?rev=92116&view=rev
Log:
Inter-procedural analysis: now we can return from the callee.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
cfe/trunk/lib/Analysis/CallInliner.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h?rev=92116&r1=92115&r2=92116&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h Wed Dec 23 20:25:21 2009
@@ -211,6 +211,8 @@
/// of this builder.
CFGBlock* getBlock() const { return &B; }
+ unsigned getIndex() const { return Idx; }
+
void setAuditor(GRAuditor* A) { Auditor = A; }
const GRState* GetState(ExplodedNode* Pred) const {
@@ -401,7 +403,7 @@
};
class GREndPathNodeBuilder {
- GRCoreEngine& Eng;
+ GRCoreEngine &Eng;
CFGBlock& B;
ExplodedNode* Pred;
@@ -414,6 +416,8 @@
~GREndPathNodeBuilder();
+ GRWorkList &getWorkList() { return *Eng.WList; }
+
ExplodedNode* getPredecessor() const { return Pred; }
GRBlockCounter getBlockCounter() const {
Modified: cfe/trunk/lib/Analysis/CallInliner.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CallInliner.cpp?rev=92116&r1=92115&r2=92116&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CallInliner.cpp (original)
+++ cfe/trunk/lib/Analysis/CallInliner.cpp Wed Dec 23 20:25:21 2009
@@ -19,6 +19,11 @@
namespace {
class CallInliner : public Checker {
+
+ /// CallSitePosition - Map the call site to its CFG block and stmt index. This
+ /// is used when exiting from a callee.
+ llvm::DenseMap<const Stmt *, std::pair<CFGBlock*,unsigned> > CallSitePosition;
+
public:
static void *getTag() {
static int x;
@@ -26,6 +31,7 @@
}
virtual bool EvalCallExpr(CheckerContext &C, const CallExpr *CE);
+ virtual void EvalEndPath(GREndPathNodeBuilder &B,void *tag,GRExprEngine &Eng);
};
}
@@ -77,6 +83,37 @@
Builder.HasGeneratedNode = true;
+ // Record the call site position.
+ CallSitePosition[CE] = std::make_pair(Builder.getBlock(), Builder.getIndex());
return true;
}
+void CallInliner::EvalEndPath(GREndPathNodeBuilder &B, void *tag,
+ GRExprEngine &Eng) {
+ const GRState *state = B.getState();
+ ExplodedNode *Pred = B.getPredecessor();
+ const StackFrameContext *LocCtx =
+ cast<StackFrameContext>(Pred->getLocationContext());
+
+ const Stmt *CE = LocCtx->getCallSite();
+
+ // Check if this is the top level stack frame.
+ if (!LocCtx->getParent())
+ return;
+
+ PostStmt NodeLoc(CE, LocCtx->getParent());
+
+ bool isNew;
+ ExplodedNode *Succ = Eng.getGraph().getNode(NodeLoc, state, &isNew);
+ Succ->addPredecessor(Pred, Eng.getGraph());
+
+ assert(CallSitePosition.find(CE) != CallSitePosition.end());
+
+ // When creating the new work list unit, increment the statement index to
+ // point to the statement after the CallExpr.
+ if (isNew)
+ B.getWorkList().Enqueue(Succ, *CallSitePosition[CE].first,
+ CallSitePosition[CE].second + 1);
+
+ B.HasGeneratedNode = true;
+}
More information about the cfe-commits
mailing list