From f13654600b6c567b2f05902cfa2e86b23ddcbd4b Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 26 May 2011 18:45:44 +0000 Subject: [PATCH] Tighen analyzer diagnostics w.r.t ObjC/CF leaks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132130 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/CFRefCount.cpp | 29 +++++++++++++------------- test/Analysis/plist-output-alternate.m | 9 ++++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/StaticAnalyzer/Core/CFRefCount.cpp b/lib/StaticAnalyzer/Core/CFRefCount.cpp index 013eeec0e4..0512e2f08d 100644 --- a/lib/StaticAnalyzer/Core/CFRefCount.cpp +++ b/lib/StaticAnalyzer/Core/CFRefCount.cpp @@ -2090,7 +2090,7 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode* N, } if (CurrV.isOwned()) { - os << "+1 retain count (owning reference)."; + os << "+1 retain count"; if (static_cast(getBugType()).getTF().isGCEnabled()) { assert(CurrV.getObjKind() == RetEffect::CF); @@ -2100,7 +2100,7 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode* N, } else { assert (CurrV.isNotOwned()); - os << "+0 retain count (non-owning reference)."; + os << "+0 retain count"; } PathDiagnosticLocation Pos(S, BRC.getSourceManager()); @@ -2232,11 +2232,11 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode* N, case RefVal::ReturnedOwned: os << "Object returned to caller as an owning reference (single retain " - "count transferred to caller)."; + "count transferred to caller)"; break; case RefVal::ReturnedNotOwned: - os << "Object returned to caller with a +0 (non-owning) retain count."; + os << "Object returned to caller with a +0 retain count"; break; default: @@ -2369,12 +2369,7 @@ CFRefLeakReport::getEndPath(BugReporterContext& BRC, llvm::tie(AllocNode, FirstBinding) = GetAllocationSite(BRC.getStateManager(), EndN, Sym); - // Get the allocate site. - assert(AllocNode); - const Stmt* FirstStmt = cast(AllocNode->getLocation()).getStmt(); - SourceManager& SMgr = BRC.getSourceManager(); - unsigned AllocLine =SMgr.getInstantiationLineNumber(FirstStmt->getLocStart()); // Compute an actual location for the leak. Sometimes a leak doesn't // occur at an actual statement (e.g., transition between blocks; end @@ -2407,10 +2402,14 @@ CFRefLeakReport::getEndPath(BugReporterContext& BRC, std::string sbuf; llvm::raw_string_ostream os(sbuf); - os << "Object allocated on line " << AllocLine; + os << "Object leaked: "; - if (FirstBinding) - os << " and stored into '" << FirstBinding->getString() << '\''; + if (FirstBinding) { + os << "object allocated and stored into '" + << FirstBinding->getString() << '\''; + } + else + os << "allocated object"; // Get the retain count. const RefVal* RV = EndN->getState()->get(Sym); @@ -2425,7 +2424,7 @@ CFRefLeakReport::getEndPath(BugReporterContext& BRC, << MD->getSelector().getAsString() << "') does not start with 'copy', 'mutableCopy', 'alloc' or 'new'." " This violates the naming convention rules " - " given in the Memory Management Guide for Cocoa (object leaked)"; + " given in the Memory Management Guide for Cocoa"; } else { const FunctionDecl *FD = cast(D); @@ -2433,7 +2432,7 @@ CFRefLeakReport::getEndPath(BugReporterContext& BRC, << FD->getNameAsString() << "') does not contain 'Copy' or 'Create'. This violates the naming" " convention rules given the Memory Management Guide for Core " - " Foundation (object leaked)"; + " Foundation"; } } else if (RV->getKind() == RefVal::ErrorGCLeakReturned) { @@ -2446,7 +2445,7 @@ CFRefLeakReport::getEndPath(BugReporterContext& BRC, } else os << " is not referenced later in this execution path and has a retain " - "count of +" << RV->getCount() << " (object leaked)"; + "count of +" << RV->getCount(); return new PathDiagnosticEventPiece(L, os.str()); } diff --git a/test/Analysis/plist-output-alternate.m b/test/Analysis/plist-output-alternate.m index a7e3c3cfe4..0f4d3aee07 100644 --- a/test/Analysis/plist-output-alternate.m +++ b/test/Analysis/plist-output-alternate.m @@ -864,9 +864,9 @@ void rdar8331641(int x) { // CHECK: // CHECK: // CHECK: extended_message -// CHECK: Call to function 'CFNumberCreate' returns a Core Foundation object with a +1 retain count (owning reference) +// CHECK: Call to function 'CFNumberCreate' returns a Core Foundation object with a +1 retain count // CHECK: message -// CHECK: Call to function 'CFNumberCreate' returns a Core Foundation object with a +1 retain count (owning reference) +// CHECK: Call to function 'CFNumberCreate' returns a Core Foundation object with a +1 retain count // CHECK: // CHECK: // CHECK: kindcontrol @@ -994,9 +994,9 @@ void rdar8331641(int x) { // CHECK: // CHECK: // CHECK: extended_message -// CHECK: Object allocated on line 53 and stored into 'value' is not referenced later in this execution path and has a retain count of +1 (object leaked) +// CHECK: Object leaked: object allocated and stored into 'value' is not referenced later in this execution path and has a retain count of +1 // CHECK: message -// CHECK: Object allocated on line 53 and stored into 'value' is not referenced later in this execution path and has a retain count of +1 (object leaked) +// CHECK: Object leaked: object allocated and stored into 'value' is not referenced later in this execution path and has a retain count of +1 // CHECK: // CHECK: // CHECK: descriptionPotential leak of an object allocated on line 53 and stored into 'value' @@ -1012,3 +1012,4 @@ void rdar8331641(int x) { // CHECK: // CHECK: // CHECK: +