summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-02-28 22:39:22 +0000
committerAnna Zaks <ganna@apple.com>2012-02-28 22:39:22 +0000
commit75de32322abd77dcf906b18fdacc303db017fbd1 (patch)
tree218d61c97175dfbad827b3d5dbc9803089f72a5a /clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
parent8754926feb62c553b7af118597d9c1a088f35e38 (diff)
downloadbcm5719-llvm-75de32322abd77dcf906b18fdacc303db017fbd1.tar.gz
bcm5719-llvm-75de32322abd77dcf906b18fdacc303db017fbd1.zip
[analyzer] Leaks should be uniqued by the allocation point in the
closest function context (RetainCountChecker). llvm-svn: 151661
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
index 2350298b638..6b14013eea5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -2114,14 +2114,16 @@ namespace {
};
}
+// Find the first node in the current function context that referred to the
+// tracked symbol and the memory location that value was stored to. Note, the
+// value is only reported if the allocation occurred in the same function as
+// the leak.
static std::pair<const ExplodedNode*,const MemRegion*>
GetAllocationSite(ProgramStateManager& StateMgr, const ExplodedNode *N,
SymbolRef Sym) {
-
- // Find both first node that referred to the tracked symbol and the
- // memory location that value was store to.
const ExplodedNode *Last = N;
const MemRegion* FirstBinding = 0;
+ const LocationContext *LeakContext = N->getLocationContext();
while (N) {
ProgramStateRef St = N->getState();
@@ -2134,10 +2136,20 @@ GetAllocationSite(ProgramStateManager& StateMgr, const ExplodedNode *N,
StateMgr.iterBindings(St, FB);
if (FB) FirstBinding = FB.getRegion();
- Last = N;
+ // Allocation node, is the last node in the current context in which the
+ // symbol was tracked.
+ if (N->getLocationContext() == LeakContext)
+ Last = N;
+
N = N->pred_empty() ? NULL : *(N->pred_begin());
}
+ // If allocation happened in a function different from the leak node context,
+ // do not report the binding.
+ if (N->getLocationContext() != LeakContext) {
+ FirstBinding = 0;
+ }
+
return std::make_pair(Last, FirstBinding);
}
OpenPOWER on IntegriCloud