]> granicus.if.org Git - clang/commitdiff
In symbol reaper, a variable is live if its stack frame is the parent of the
authorZhongxing Xu <xuzhongxing@gmail.com>
Wed, 17 Feb 2010 08:50:05 +0000 (08:50 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Wed, 17 Feb 2010 08:50:05 +0000 (08:50 +0000)
current stack frame.

When leaving a callee, remove all bindings belonging to that callee.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96473 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/CallInliner.cpp
lib/Checker/SymbolManager.cpp

index d94994b194376c2c6807faf29d38728ce6cd4fd6..0279d46f2287b9d707c42bf67a0d68d1aaa5acaf 100644 (file)
@@ -65,6 +65,7 @@ bool CallInliner::EvalCallExpr(CheckerContext &C, const CallExpr *CE) {
   BlockEdge Loc(Entry, SuccB, LocCtx);
 
   state = C.getStoreManager().EnterStackFrame(state, LocCtx);
+
   // This is a hack. We really should not use the GRStmtNodeBuilder.
   bool isNew;
   GRExprEngine &Eng = C.getEngine();
@@ -86,16 +87,26 @@ bool CallInliner::EvalCallExpr(CheckerContext &C, const CallExpr *CE) {
 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;
 
+  const StackFrameContext *ParentSF = 
+                                   cast<StackFrameContext>(LocCtx->getParent());
+
+  SymbolReaper SymReaper(*ParentSF->getLiveVariables(), Eng.getSymbolManager(), 
+                         ParentSF);
+  const Stmt *CE = LocCtx->getCallSite();
+
+  state = Eng.getStateManager().RemoveDeadBindings(state, const_cast<Stmt*>(CE),
+                                                   SymReaper);
+
+
   PostStmt NodeLoc(CE, LocCtx->getParent());
 
   bool isNew;
index 40bdcf65bca4cfac6261dcb102f03f7927fab218..7278b4189c2a2e7fbfac09a31d5140d807f18c06 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "clang/Checker/PathSensitive/SymbolManager.h"
 #include "clang/Checker/PathSensitive/MemRegion.h"
+#include "clang/Analysis/AnalysisContext.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
@@ -222,7 +223,11 @@ bool SymbolReaper::isLive(SymbolRef sym) {
 
 bool SymbolReaper::isLive(const Stmt *Loc, const VarRegion *VR) const {
   const StackFrameContext *SFC = VR->getStackFrame();
-  return SFC == CurrentStackFrame ? Liveness.isLive(Loc, VR->getDecl()) : true;
+
+  if (SFC == CurrentStackFrame)
+    return Liveness.isLive(Loc, VR->getDecl());
+  else
+    return SFC->isParentOf(CurrentStackFrame);
 }
 
 SymbolVisitor::~SymbolVisitor() {}