From 8cf91f7efb4dcb238fe443915d9a30119ce5b70c Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Wed, 10 Apr 2013 22:56:33 +0000 Subject: [PATCH] =?utf8?q?[analyzer]=20Address=20Jordan=E2=80=99s=20review?= =?utf8?q?=20of=20r179219?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179235 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 2 +- .../Checkers/RetainCountChecker.cpp | 2 +- test/Analysis/malloc-plist.c | 331 ++++++++++++++++-- 3 files changed, 308 insertions(+), 27 deletions(-) diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 64e017ed1c..2a603d36e1 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1531,7 +1531,7 @@ MallocChecker::getAllocationSite(const ExplodedNode *N, SymbolRef Sym, if (const MemRegion *MR = C.getLocationRegionIfPostStore(N)) { SVal Val = State->getSVal(MR); if (Val.getAsLocSymbol() == Sym) { - const VarRegion* VR = MR->getAs(); + const VarRegion* VR = MR->getBaseRegion()->getAs(); // Do not show local variables belonging to a function other than // where the error is reported. if (!VR || diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 6163cc19c6..156e1f9c3f 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -2170,7 +2170,7 @@ GetAllocationSite(ProgramStateManager& StateMgr, const ExplodedNode *N, if (FB) { const MemRegion *R = FB.getRegion(); - const VarRegion *VR = R->getAs(); + const VarRegion *VR = R->getBaseRegion()->getAs(); // Do not show local variables belonging to a function other than // where the error is reported. if (!VR || VR->getStackFrame() == LeakContext->getCurrentStackFrame()) diff --git a/test/Analysis/malloc-plist.c b/test/Analysis/malloc-plist.c index 124eec222e..6ec277491a 100644 --- a/test/Analysis/malloc-plist.c +++ b/test/Analysis/malloc-plist.c @@ -169,15 +169,28 @@ void use_function_with_leak7() { function_with_leak7(); } +// Test that we do not print the name of a variable not visible from where +// the issue is reported. int *my_malloc() { int *p = malloc(12); return p; } - void testOnlyRefferToVisibleVariables() { my_malloc(); } // expected-warning {{Potential leak of memory}} +struct PointerWrapper{ + int*p; +}; +int *my_malloc_into_struct() { + struct PointerWrapper w; + w.p = malloc(12); + return w.p; +} +void testMyMalloc() { + my_malloc_into_struct(); // expected-warning {{Potential leak of memory}} +} + // CHECK: diagnostics // CHECK-NEXT: // CHECK-NEXT: @@ -4525,7 +4538,7 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: kindevent // CHECK-NEXT: location // CHECK-NEXT: -// CHECK-NEXT: line178 +// CHECK-NEXT: line179 // CHECK-NEXT: col3 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4533,12 +4546,12 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line178 +// CHECK-NEXT: line179 // CHECK-NEXT: col3 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line178 +// CHECK-NEXT: line179 // CHECK-NEXT: col13 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4554,7 +4567,7 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: kindevent // CHECK-NEXT: location // CHECK-NEXT: -// CHECK-NEXT: line172 +// CHECK-NEXT: line174 // CHECK-NEXT: col1 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4572,12 +4585,12 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: start // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line172 +// CHECK-NEXT: line174 // CHECK-NEXT: col1 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line172 +// CHECK-NEXT: line174 // CHECK-NEXT: col3 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4585,12 +4598,12 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: end // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line173 +// CHECK-NEXT: line175 // CHECK-NEXT: col3 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line173 +// CHECK-NEXT: line175 // CHECK-NEXT: col5 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4606,12 +4619,12 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: start // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line173 +// CHECK-NEXT: line175 // CHECK-NEXT: col3 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line173 +// CHECK-NEXT: line175 // CHECK-NEXT: col5 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4619,12 +4632,12 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: end // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line173 +// CHECK-NEXT: line175 // CHECK-NEXT: col12 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line173 +// CHECK-NEXT: line175 // CHECK-NEXT: col17 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4636,7 +4649,7 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: kindevent // CHECK-NEXT: location // CHECK-NEXT: -// CHECK-NEXT: line173 +// CHECK-NEXT: line175 // CHECK-NEXT: col12 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4644,12 +4657,12 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line173 +// CHECK-NEXT: line175 // CHECK-NEXT: col12 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line173 +// CHECK-NEXT: line175 // CHECK-NEXT: col21 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4665,7 +4678,7 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: kindevent // CHECK-NEXT: location // CHECK-NEXT: -// CHECK-NEXT: line178 +// CHECK-NEXT: line179 // CHECK-NEXT: col3 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4673,12 +4686,12 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line178 +// CHECK-NEXT: line179 // CHECK-NEXT: col3 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line178 +// CHECK-NEXT: line179 // CHECK-NEXT: col13 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4698,12 +4711,12 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: start // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line178 +// CHECK-NEXT: line179 // CHECK-NEXT: col3 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line178 +// CHECK-NEXT: line179 // CHECK-NEXT: col11 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4711,12 +4724,12 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: end // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line179 +// CHECK-NEXT: line180 // CHECK-NEXT: col1 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: line179 +// CHECK-NEXT: line180 // CHECK-NEXT: col1 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4728,7 +4741,7 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: kindevent // CHECK-NEXT: location // CHECK-NEXT: -// CHECK-NEXT: line179 +// CHECK-NEXT: line180 // CHECK-NEXT: col1 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -4747,7 +4760,275 @@ void testOnlyRefferToVisibleVariables() { // CHECK-NEXT: issue_hash1 // CHECK-NEXT: location // CHECK-NEXT: -// CHECK-NEXT: line179 +// CHECK-NEXT: line180 +// CHECK-NEXT: col1 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: path +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: kindevent +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line191 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: ranges +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line191 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line191 +// CHECK-NEXT: col25 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: depth0 +// CHECK-NEXT: extended_message +// CHECK-NEXT: Calling 'my_malloc_into_struct' +// CHECK-NEXT: message +// CHECK-NEXT: Calling 'my_malloc_into_struct' +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: kindevent +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line185 +// CHECK-NEXT: col1 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: depth1 +// CHECK-NEXT: extended_message +// CHECK-NEXT: Entered call from 'testMyMalloc' +// CHECK-NEXT: message +// CHECK-NEXT: Entered call from 'testMyMalloc' +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: kindcontrol +// CHECK-NEXT: edges +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: start +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line185 +// CHECK-NEXT: col1 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line185 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: end +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line186 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line186 +// CHECK-NEXT: col8 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: kindcontrol +// CHECK-NEXT: edges +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: start +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line186 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line186 +// CHECK-NEXT: col8 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: end +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line187 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line187 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: kindcontrol +// CHECK-NEXT: edges +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: start +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line187 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line187 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: end +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line187 +// CHECK-NEXT: col9 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line187 +// CHECK-NEXT: col14 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: kindevent +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line187 +// CHECK-NEXT: col9 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: ranges +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line187 +// CHECK-NEXT: col9 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line187 +// CHECK-NEXT: col18 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: depth1 +// CHECK-NEXT: extended_message +// CHECK-NEXT: Memory is allocated +// CHECK-NEXT: message +// CHECK-NEXT: Memory is allocated +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: kindevent +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line191 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: ranges +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line191 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line191 +// CHECK-NEXT: col25 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: depth1 +// CHECK-NEXT: extended_message +// CHECK-NEXT: Returned allocated memory +// CHECK-NEXT: message +// CHECK-NEXT: Returned allocated memory +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: kindcontrol +// CHECK-NEXT: edges +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: start +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line191 +// CHECK-NEXT: col3 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line191 +// CHECK-NEXT: col23 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: end +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line192 +// CHECK-NEXT: col1 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: line192 +// CHECK-NEXT: col1 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: kindevent +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line192 +// CHECK-NEXT: col1 +// CHECK-NEXT: file0 +// CHECK-NEXT: +// CHECK-NEXT: depth0 +// CHECK-NEXT: extended_message +// CHECK-NEXT: Potential memory leak +// CHECK-NEXT: message +// CHECK-NEXT: Potential memory leak +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: descriptionPotential memory leak +// CHECK-NEXT: categoryMemory Error +// CHECK-NEXT: typeMemory leak +// CHECK-NEXT: issue_context_kindfunction +// CHECK-NEXT: issue_contexttestMyMalloc +// CHECK-NEXT: issue_hash1 +// CHECK-NEXT: location +// CHECK-NEXT: +// CHECK-NEXT: line192 // CHECK-NEXT: col1 // CHECK-NEXT: file0 // CHECK-NEXT: -- 2.40.0