From 94f8c4a7d5d134d6a641876692a52899c0eaacce Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 26 Nov 2009 02:35:42 +0000 Subject: [PATCH] Teach RegionStoreManager::RemoveDeadBindings() about BlockDataRegions. Any VarRegion for a "captured" variable should also be considered live. llvm-svn: 89928 --- clang/lib/Analysis/RegionStore.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/clang/lib/Analysis/RegionStore.cpp b/clang/lib/Analysis/RegionStore.cpp index deb6c0785254..2e62395db87c 100644 --- a/clang/lib/Analysis/RegionStore.cpp +++ b/clang/lib/Analysis/RegionStore.cpp @@ -1651,9 +1651,9 @@ void RegionStoreManager::RemoveDeadBindings(GRState &state, Stmt* Loc, llvm::OwningPtr SubRegions(getRegionStoreSubRegionMap(store)); - // Do a pass over the regions in the store. For VarRegions we check if - // the variable is still live and if so add it to the list of live roots. - // For other regions we populate our region backmap. + // Do a pass over the regions in the store. For VarRegions we check if + // the variable is still live and if so add it to the list of live roots. + // For other regions we populate our region backmap. llvm::SmallVector IntermediateRoots; // Scan the direct bindings for "intermediate" roots. @@ -1751,8 +1751,21 @@ tryAgain: // Mark the symbol for any live SymbolicRegion as "live". This means we // should continue to track that symbol. - if (const SymbolicRegion* SymR = dyn_cast(R)) + if (const SymbolicRegion *SymR = dyn_cast(R)) SymReaper.markLive(SymR->getSymbol()); + + // For BlockDataRegions, enqueue all VarRegions for that are referenced + // via BlockDeclRefExprs. + if (const BlockDataRegion *BD = dyn_cast(R)) { + for (BlockDataRegion::referenced_vars_iterator + RI = BD->referenced_vars_begin(), RE = BD->referenced_vars_end(); + RI != RE; ++RI) + WorkList.push_back(std::make_pair(state_N, *RI)); + + // No possible data bindings on a BlockDataRegion. Continue to the + // next region in the worklist. + continue; + } Store store_N = state_N->getStore(); RegionBindings B_N = GetRegionBindings(store_N);