diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-02-21 00:46:29 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-02-21 00:46:29 +0000 |
commit | 7f9b1d963d4b7e2faff7305733e3453130b402fe (patch) | |
tree | c2f5e2571311d13023bda99d2f490fd87edffe6b | |
parent | ccc1b5eebc6ca8a904c58c0468b9a71483b7c7cf (diff) |
Have ScanReachableSymbols reported reachable regions. Fixes a false positive with nested array literals. <rdar://problem/10686586>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151012 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/StaticAnalyzer/Core/Environment.cpp | 9 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/ProgramState.cpp | 4 | ||||
-rw-r--r-- | test/Analysis/misc-ps.c | 15 |
3 files changed, 27 insertions, 1 deletions
diff --git a/lib/StaticAnalyzer/Core/Environment.cpp b/lib/StaticAnalyzer/Core/Environment.cpp index 61701385eb..74f04ce5a5 100644 --- a/lib/StaticAnalyzer/Core/Environment.cpp +++ b/lib/StaticAnalyzer/Core/Environment.cpp @@ -139,7 +139,14 @@ class MarkLiveCallback : public SymbolVisitor { SymbolReaper &SymReaper; public: MarkLiveCallback(SymbolReaper &symreaper) : SymReaper(symreaper) {} - bool VisitSymbol(SymbolRef sym) { SymReaper.markLive(sym); return true; } + bool VisitSymbol(SymbolRef sym) { + SymReaper.markLive(sym); + return true; + } + bool VisitMemRegion(const MemRegion *R) { + SymReaper.markLive(R); + return true; + } }; } // end anonymous namespace diff --git a/lib/StaticAnalyzer/Core/ProgramState.cpp b/lib/StaticAnalyzer/Core/ProgramState.cpp index 6f39c0321e..b9cfa27808 100644 --- a/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -553,6 +553,10 @@ bool ScanReachableSymbols::scan(const MemRegion *R) { if (isVisited) return true; isVisited = 1; + + + if (!visitor.VisitMemRegion(R)) + return false; // If this is a symbolic region, visit the symbol for the region. if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R)) diff --git a/test/Analysis/misc-ps.c b/test/Analysis/misc-ps.c index 8a36efb995..f81b0ddc68 100644 --- a/test/Analysis/misc-ps.c +++ b/test/Analysis/misc-ps.c @@ -111,3 +111,18 @@ struct rdar10385775 { void RDar10385775(struct rdar10385775* p) { p->name = L"a"; } + +// Test double loop of array and array literals. Previously this +// resulted in a false positive uninitailized value warning. +void rdar10686586() { + int array1[] = { 1, 2, 3, 0 }; + int array2[] = { 1, 2, 3, 0 }; + int *array[] = { array1, array2 }; + int sum = 0; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 4; j++) { + sum += array[i][j]; // no-warning + } + } +} + |