[PATCH] [analyzer] Fix inefficiency in dead symbol removal
Pavel Labath
labath at google.com
Fri Aug 16 03:38:05 PDT 2013
Ah, yes, I forgot about that.
I added a separate set to track the (region, store) pairs (or pairs of anything, if it is ever needed).
Hi jordan_rose,
http://llvm-reviews.chandlerc.com/D1398
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1398?vs=3466&id=3521#toc
Files:
include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
lib/StaticAnalyzer/Core/ProgramState.cpp
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===================================================================
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -799,15 +799,18 @@
/// SymbolVisitor.
class ScanReachableSymbols {
typedef llvm::DenseMap<const void*, unsigned> VisitedItems;
+ typedef llvm::DenseMap<std::pair<const void*, const void*>, unsigned> VisitedPairs;
VisitedItems visited;
+ VisitedPairs visitedPairs;
ProgramStateRef state;
SymbolVisitor &visitor;
public:
ScanReachableSymbols(ProgramStateRef st, SymbolVisitor& v)
: state(st), visitor(v) {}
+ bool scan(nonloc::LazyCompoundVal val);
bool scan(nonloc::CompoundVal val);
bool scan(SVal val);
bool scan(const MemRegion *R);
Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -526,6 +526,20 @@
return getPersistentState(NewState);
}
+bool ScanReachableSymbols::scan(nonloc::LazyCompoundVal val) {
+ StoreManager &StoreMgr = state->getStateManager().getStoreManager();
+ // FIXME: We don't really want to use getBaseRegion() here because pointer
+ // arithmetic doesn't apply, but scanReachableSymbols only accepts base
+ // regions right now.
+ const MemRegion *R = val.getRegion()->getBaseRegion();
+ unsigned &isVisited = visitedPairs[std::make_pair(R, val.getStore())];
+ if (isVisited)
+ return true;
+ isVisited = 1;
+
+ return StoreMgr.scanReachableSymbols(val.getStore(), R, *this);
+}
+
bool ScanReachableSymbols::scan(nonloc::CompoundVal val) {
for (nonloc::CompoundVal::iterator I=val.begin(), E=val.end(); I!=E; ++I)
if (!scan(*I))
@@ -570,16 +584,8 @@
return scan(X->getRegion());
if (Optional<nonloc::LazyCompoundVal> X =
- val.getAs<nonloc::LazyCompoundVal>()) {
- StoreManager &StoreMgr = state->getStateManager().getStoreManager();
- // FIXME: We don't really want to use getBaseRegion() here because pointer
- // arithmetic doesn't apply, but scanReachableSymbols only accepts base
- // regions right now.
- if (!StoreMgr.scanReachableSymbols(X->getStore(),
- X->getRegion()->getBaseRegion(),
- *this))
- return false;
- }
+ val.getAs<nonloc::LazyCompoundVal>())
+ return scan(*X);
if (Optional<nonloc::LocAsInteger> X = val.getAs<nonloc::LocAsInteger>())
return scan(X->getLoc());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1398.2.patch
Type: text/x-patch
Size: 2648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130816/ccbf81b6/attachment.bin>
More information about the cfe-commits
mailing list