Index: clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h =================================================================== --- clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h +++ clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h @@ -141,12 +141,14 @@ }; class CFRefReport : public BugReport { +protected: + SymbolRef Sym; public: CFRefReport(CFRefBug &D, const LangOptions &LOpts, const SummaryLogTy &Log, ExplodedNode *n, SymbolRef sym, bool registerVisitor = true) - : BugReport(D, D.getDescription(), n) { + : BugReport(D, D.getDescription(), n), Sym(sym) { if (registerVisitor) addVisitor(llvm::make_unique(sym, Log)); } Index: clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp +++ clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp @@ -432,7 +432,7 @@ if (RegionDescription) { os << "object allocated and stored into '" << *RegionDescription << '\''; } else { - os << "allocated object"; + os << "allocated object of type " << Sym->getType().getAsString(); } // Get the retain count. @@ -472,10 +472,10 @@ " Foundation"; } } - } - else + } else { os << " is not referenced later in this execution path and has a retain " "count of +" << RV->getCount(); + } return std::make_shared(L, os.str()); } @@ -555,6 +555,10 @@ FullSourceLoc SL(AllocStmt->getBeginLoc(), Ctx.getSourceManager()); os << " (allocated on line " << SL.getSpellingLineNumber() << ")"; } + } else { + + // If we can't figure out the name, just supply the type information. + os << " of type " << Sym->getType().getAsString(); } } Index: clang/test/Analysis/Inputs/expected-plists/objc-arc.m.plist =================================================================== --- clang/test/Analysis/Inputs/expected-plists/objc-arc.m.plist +++ clang/test/Analysis/Inputs/expected-plists/objc-arc.m.plist @@ -1727,12 +1727,12 @@ depth0 extended_message - Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1 + Object leaked: allocated object of type CFStringRef is not referenced later in this execution path and has a retain count of +1 message - Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1 + Object leaked: allocated object of type CFStringRef is not referenced later in this execution path and has a retain count of +1 - descriptionPotential leak of an object + descriptionPotential leak of an object of type CFStringRef categoryMemory (Core Foundation/Objective-C) typeLeak check_nameosx.cocoa.RetainCount Index: clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist =================================================================== --- clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist +++ clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist @@ -3834,12 +3834,12 @@ depth0 extended_message - Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1 + Object leaked: allocated object of type MyObj * is not referenced later in this execution path and has a retain count of +1 message - Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1 + Object leaked: allocated object of type MyObj * is not referenced later in this execution path and has a retain count of +1 - descriptionPotential leak of an object + descriptionPotential leak of an object of type MyObj * categoryMemory (Core Foundation/Objective-C) typeLeak check_nameosx.cocoa.RetainCount Index: clang/test/Analysis/objc-radar17039661.m =================================================================== --- clang/test/Analysis/objc-radar17039661.m +++ clang/test/Analysis/objc-radar17039661.m @@ -1315,12 +1315,12 @@ // CHECK: // CHECK: depth4 // CHECK: extended_message -// CHECK: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1 +// CHECK: Object leaked: allocated object of type NSNumber * is not referenced later in this execution path and has a retain count of +1 // CHECK: message -// CHECK: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1 +// CHECK: Object leaked: allocated object of type NSNumber * is not referenced later in this execution path and has a retain count of +1 // CHECK: // CHECK: -// CHECK: descriptionPotential leak of an object +// CHECK: descriptionPotential leak of an object of type NSNumber * // CHECK: categoryMemory (Core Foundation/Objective-C) // CHECK: typeLeak // CHECK: location Index: clang/test/Analysis/osobject-retain-release.cpp =================================================================== --- clang/test/Analysis/osobject-retain-release.cpp +++ clang/test/Analysis/osobject-retain-release.cpp @@ -95,6 +95,7 @@ OSArray *generateArray() { return OSArray::withCapacity(10); // expected-note{{Call to function 'withCapacity' returns an OSObject of type struct OSArray * with a +1 retain count}} + // expected-note@-1{{Call to function 'withCapacity' returns an OSObject of type struct OSArray * with a +1 retain count}} } unsigned int check_leak_good_error_message() { @@ -109,7 +110,10 @@ } unsigned int check_leak_msg_temporary() { - return generateArray()->getCount(); + return generateArray()->getCount(); // expected-warning{{Potential leak of an object}} + // expected-note@-1{{Calling 'generateArray'}} + // expected-note@-2{{Returning from 'generateArray'}} + // expected-note@-3{{Object leaked: allocated object of type struct OSArray * is not referenced later in this execution path and has a retain count of +1}} } void check_confusing_getters() { Index: clang/test/Analysis/retain-release-path-notes.m =================================================================== --- clang/test/Analysis/retain-release-path-notes.m +++ clang/test/Analysis/retain-release-path-notes.m @@ -227,7 +227,7 @@ // expected-note@-1 {{Method returns an instance of MyObj with a +1 retain count}} // expected-note@-2 {{Calling 'initX'}} // expected-note@-3 {{Returning from 'initX'}} - // expected-note@-4 {{Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1}} + // expected-note@-4 {{Object leaked: allocated object of type MyObj * is not referenced later in this execution path and has a retain count of +1}} // initI is inlined because the allocation happens within initY id y = [[MyObj alloc] initY]; // expected-note@-1 {{Calling 'initY'}} Index: clang/test/Analysis/retaincountchecker-compoundregion.m =================================================================== --- clang/test/Analysis/retaincountchecker-compoundregion.m +++ clang/test/Analysis/retaincountchecker-compoundregion.m @@ -19,7 +19,7 @@ int width = 0; int height = 0; CFTypeRef* values = (CFTypeRef[]){ - CFNumberCreate(allocator, kCFNumberSInt32Type, &width), //expected-warning-re{{Potential leak of an object{{$}}}} - CFNumberCreate(allocator, kCFNumberSInt32Type, &height), //expected-warning-re{{Potential leak of an object{{$}}}} + CFNumberCreate(allocator, kCFNumberSInt32Type, &width), //expected-warning{{Potential leak of an object of type CFNumberRef}} + CFNumberCreate(allocator, kCFNumberSInt32Type, &height), //expected-warning{{Potential leak of an object of type CFNumberRef}} }; }