From: Zhongxing Xu Date: Wed, 17 Mar 2010 03:35:08 +0000 (+0000) Subject: Mark CXXThisRegion in the current or parent stack frame context as live so that X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17ddf1c108bb847fb05111fec09d664c9bb2e49b;p=clang Mark CXXThisRegion in the current or parent stack frame context as live so that their bindings are not removed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98705 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Checker/PathSensitive/GRState.h b/include/clang/Checker/PathSensitive/GRState.h index 1178143bcc..657266b750 100644 --- a/include/clang/Checker/PathSensitive/GRState.h +++ b/include/clang/Checker/PathSensitive/GRState.h @@ -453,6 +453,7 @@ public: ConstraintManager& getConstraintManager() { return *ConstraintMgr; } const GRState* RemoveDeadBindings(const GRState* St, Stmt* Loc, + const StackFrameContext *LCtx, SymbolReaper& SymReaper); public: diff --git a/include/clang/Checker/PathSensitive/Store.h b/include/clang/Checker/PathSensitive/Store.h index c660e7b7fe..edc338012a 100644 --- a/include/clang/Checker/PathSensitive/Store.h +++ b/include/clang/Checker/PathSensitive/Store.h @@ -144,6 +144,7 @@ public: } virtual Store RemoveDeadBindings(Store store, Stmt* Loc, + const StackFrameContext *LCtx, SymbolReaper& SymReaper, llvm::SmallVectorImpl& RegionRoots) = 0; diff --git a/lib/Checker/BasicStore.cpp b/lib/Checker/BasicStore.cpp index 10136f3fc4..7c5399113d 100644 --- a/lib/Checker/BasicStore.cpp +++ b/lib/Checker/BasicStore.cpp @@ -72,7 +72,9 @@ public: /// RemoveDeadBindings - Scans a BasicStore of 'state' for dead values. /// It updatees the GRState object in place with the values removed. - Store RemoveDeadBindings(Store store, Stmt* Loc, SymbolReaper& SymReaper, + Store RemoveDeadBindings(Store store, Stmt* Loc, + const StackFrameContext *LCtx, + SymbolReaper& SymReaper, llvm::SmallVectorImpl& RegionRoots); void iterBindings(Store store, BindingsHandler& f); @@ -250,6 +252,7 @@ Store BasicStoreManager::Remove(Store store, Loc loc) { } Store BasicStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, + const StackFrameContext *LCtx, SymbolReaper& SymReaper, llvm::SmallVectorImpl& RegionRoots) { diff --git a/lib/Checker/FlatStore.cpp b/lib/Checker/FlatStore.cpp index 07a54fb487..2af9ffa4a4 100644 --- a/lib/Checker/FlatStore.cpp +++ b/lib/Checker/FlatStore.cpp @@ -44,7 +44,9 @@ public: } SVal ArrayToPointer(Loc Array); - Store RemoveDeadBindings(Store store, Stmt* Loc, SymbolReaper& SymReaper, + Store RemoveDeadBindings(Store store, Stmt* Loc, + const StackFrameContext *LCtx, + SymbolReaper& SymReaper, llvm::SmallVectorImpl& RegionRoots){ return store; } diff --git a/lib/Checker/GRExprEngine.cpp b/lib/Checker/GRExprEngine.cpp index e64ba9446d..3ace552adc 100644 --- a/lib/Checker/GRExprEngine.cpp +++ b/lib/Checker/GRExprEngine.cpp @@ -481,7 +481,9 @@ void GRExprEngine::ProcessStmt(CFGElement CE, GRStmtNodeBuilder& builder) { SymbolReaper SymReaper(BasePred->getLocationContext(), SymMgr); CleanedState = AMgr.shouldPurgeDead() - ? StateMgr.RemoveDeadBindings(EntryNode->getState(), CurrentStmt, SymReaper) + ? StateMgr.RemoveDeadBindings(EntryNode->getState(), CurrentStmt, + BasePred->getLocationContext()->getCurrentStackFrame(), + SymReaper) : EntryNode->getState(); // Process any special transfer function for dead symbols. diff --git a/lib/Checker/GRState.cpp b/lib/Checker/GRState.cpp index 97ede1d480..2defbcd93c 100644 --- a/lib/Checker/GRState.cpp +++ b/lib/Checker/GRState.cpp @@ -35,6 +35,7 @@ GRStateManager::~GRStateManager() { const GRState* GRStateManager::RemoveDeadBindings(const GRState* state, Stmt* Loc, + const StackFrameContext *LCtx, SymbolReaper& SymReaper) { // This code essentially performs a "mark-and-sweep" of the VariableBindings. @@ -50,7 +51,7 @@ GRStateManager::RemoveDeadBindings(const GRState* state, Stmt* Loc, state, RegionRoots); // Clean up the store. - NewState.St = StoreMgr->RemoveDeadBindings(NewState.St, Loc, SymReaper, + NewState.St = StoreMgr->RemoveDeadBindings(NewState.St, Loc, LCtx, SymReaper, RegionRoots); return ConstraintMgr->RemoveDeadBindings(getPersistentState(NewState), diff --git a/lib/Checker/RegionStore.cpp b/lib/Checker/RegionStore.cpp index 307ef78803..c2b702acad 100644 --- a/lib/Checker/RegionStore.cpp +++ b/lib/Checker/RegionStore.cpp @@ -354,7 +354,9 @@ public: // Part of public interface to class. /// RemoveDeadBindings - Scans the RegionStore of 'state' for dead values. /// It returns a new Store with these values removed. - Store RemoveDeadBindings(Store store, Stmt* Loc, SymbolReaper& SymReaper, + Store RemoveDeadBindings(Store store, Stmt* Loc, + const StackFrameContext *LCtx, + SymbolReaper& SymReaper, llvm::SmallVectorImpl& RegionRoots); const GRState *EnterStackFrame(const GRState *state, @@ -1678,12 +1680,14 @@ class RemoveDeadBindingsWorker : llvm::SmallVector Postponed; SymbolReaper &SymReaper; Stmt *Loc; + const StackFrameContext *CurrentLCtx; + public: RemoveDeadBindingsWorker(RegionStoreManager &rm, GRStateManager &stateMgr, RegionBindings b, SymbolReaper &symReaper, - Stmt *loc) + Stmt *loc, const StackFrameContext *LCtx) : ClusterAnalysis(rm, stateMgr, b), - SymReaper(symReaper), Loc(loc) {} + SymReaper(symReaper), Loc(loc), CurrentLCtx(LCtx) {} // Called by ClusterAnalysis. void VisitAddedToCluster(const MemRegion *baseR, RegionCluster &C); @@ -1713,6 +1717,15 @@ void RemoveDeadBindingsWorker::VisitAddedToCluster(const MemRegion *baseR, return; } + + // CXXThisRegion in the current or parent location context is live. + if (const CXXThisRegion *TR = dyn_cast(baseR)) { + const StackArgumentsSpaceRegion *StackReg = + cast(TR->getSuperRegion()); + const StackFrameContext *RegCtx = StackReg->getStackFrame(); + if (RegCtx == CurrentLCtx || RegCtx->isParentOf(CurrentLCtx)) + AddToWorkList(TR, C); + } } void RemoveDeadBindingsWorker::VisitCluster(const MemRegion *baseR, @@ -1799,11 +1812,12 @@ bool RemoveDeadBindingsWorker::UpdatePostponed() { } Store RegionStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, + const StackFrameContext *LCtx, SymbolReaper& SymReaper, llvm::SmallVectorImpl& RegionRoots) { RegionBindings B = GetRegionBindings(store); - RemoveDeadBindingsWorker W(*this, StateMgr, B, SymReaper, Loc); + RemoveDeadBindingsWorker W(*this, StateMgr, B, SymReaper, Loc, LCtx); W.GenerateClusters(); // Enqueue the region roots onto the worklist.