From 79ed11c12e02eb418543dffe05be36d72bb42766 Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Tue, 11 Dec 2018 01:13:20 +0000 Subject: [PATCH] [analyzer] Resolve another bug where the name of the leaked object was not printed properly Differential Revision: https://reviews.llvm.org/D55528 llvm-svn: 348819 --- .../Checkers/RetainCountChecker/RetainCountDiagnostics.cpp | 6 +++--- clang/test/Analysis/osobject-retain-release.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp index b5828db..d2dbcbd 100644 --- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp @@ -405,11 +405,11 @@ static AllocationInfo GetAllocationSite(ProgramStateManager &StateMgr, if (FB) { const MemRegion *R = FB.getRegion(); - 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->getStackFrame()) - FirstBinding = R; + if (auto MR = dyn_cast(R->getMemorySpace())) + if (MR->getStackFrame() == LeakContext->getStackFrame()) + FirstBinding = R; } // AllocationNode is the last node in which the symbol was tracked. diff --git a/clang/test/Analysis/osobject-retain-release.cpp b/clang/test/Analysis/osobject-retain-release.cpp index 68529e9..b7a299d 100644 --- a/clang/test/Analysis/osobject-retain-release.cpp +++ b/clang/test/Analysis/osobject-retain-release.cpp @@ -153,8 +153,8 @@ void check_free_use_after_free() { unsigned int check_leak_explicit_new() { OSArray *arr = new OSArray; // expected-note{{Operator new returns an OSObject of type OSArray with a +1 retain count}} - return arr->getCount(); // expected-note{{Object leaked: allocated object of type OSArray is not referenced later in this execution path and has a retain count of +1}} - // expected-warning@-1{{Potential leak of an object of type OSArray}} + return arr->getCount(); // expected-note{{Object leaked: object allocated and stored into 'arr' is not referenced later in this execution path and has a retain count of +1}} + // expected-warning@-1{{Potential leak of an object stored into 'arr'}} } unsigned int check_leak_factory() { -- 2.7.4