Skip to content

Commit 29a3ca1

Browse files
committed
[analyzer] Include type name in Retain Count Checker diagnostics
The more detailed diagnostic will make identifying which object the diagnostics refer to easier. Differential Revision: https://reviews.llvm.org/D27740 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289883 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9761e66 commit 29a3ca1

File tree

8 files changed

+101
-89
lines changed

8 files changed

+101
-89
lines changed

lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,11 +1990,23 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N,
19901990
}
19911991

19921992
if (CurrV.getObjKind() == RetEffect::CF) {
1993-
os << " returns a Core Foundation object with a ";
1993+
if (Sym->getType().isNull()) {
1994+
os << " returns a Core Foundation object with a ";
1995+
} else {
1996+
os << " returns a Core Foundation object of type "
1997+
<< Sym->getType().getAsString() << " with a ";
1998+
}
19941999
}
19952000
else {
19962001
assert (CurrV.getObjKind() == RetEffect::ObjC);
1997-
os << " returns an Objective-C object with a ";
2002+
QualType T = Sym->getType();
2003+
if (T.isNull() || !isa<ObjCObjectPointerType>(T)) {
2004+
os << " returns an Objective-C object with a ";
2005+
} else {
2006+
const ObjCObjectPointerType *PT = cast<ObjCObjectPointerType>(T);
2007+
os << " returns an instance of "
2008+
<< PT->getPointeeType().getAsString() << " with a ";
2009+
}
19982010
}
19992011

20002012
if (CurrV.isOwned()) {

test/Analysis/edges-new.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,9 +2438,9 @@ void longLines() {
24382438
// CHECK-NEXT: </array>
24392439
// CHECK-NEXT: <key>depth</key><integer>0</integer>
24402440
// CHECK-NEXT: <key>extended_message</key>
2441-
// CHECK-NEXT: <string>Call to function &apos;CFNumberCreate&apos; returns a Core Foundation object with a +1 retain count</string>
2441+
// CHECK-NEXT: <string>Call to function &apos;CFNumberCreate&apos; returns a Core Foundation object of type CFNumberRef with a +1 retain count</string>
24422442
// CHECK-NEXT: <key>message</key>
2443-
// CHECK-NEXT: <string>Call to function &apos;CFNumberCreate&apos; returns a Core Foundation object with a +1 retain count</string>
2443+
// CHECK-NEXT: <string>Call to function &apos;CFNumberCreate&apos; returns a Core Foundation object of type CFNumberRef with a +1 retain count</string>
24442444
// CHECK-NEXT: </dict>
24452445
// CHECK-NEXT: <dict>
24462446
// CHECK-NEXT: <key>kind</key><string>control</string>
@@ -11355,9 +11355,9 @@ void longLines() {
1135511355
// CHECK-NEXT: </array>
1135611356
// CHECK-NEXT: <key>depth</key><integer>0</integer>
1135711357
// CHECK-NEXT: <key>extended_message</key>
11358-
// CHECK-NEXT: <string>Method returns an Objective-C object with a +1 retain count</string>
11358+
// CHECK-NEXT: <string>Method returns an instance of RDar10797980 with a +1 retain count</string>
1135911359
// CHECK-NEXT: <key>message</key>
11360-
// CHECK-NEXT: <string>Method returns an Objective-C object with a +1 retain count</string>
11360+
// CHECK-NEXT: <string>Method returns an instance of RDar10797980 with a +1 retain count</string>
1136111361
// CHECK-NEXT: </dict>
1136211362
// CHECK-NEXT: <dict>
1136311363
// CHECK-NEXT: <key>kind</key><string>control</string>
@@ -20325,9 +20325,9 @@ void longLines() {
2032520325
// CHECK-NEXT: </array>
2032620326
// CHECK-NEXT: <key>depth</key><integer>0</integer>
2032720327
// CHECK-NEXT: <key>extended_message</key>
20328-
// CHECK-NEXT: <string>Method returns an Objective-C object with a +1 retain count</string>
20328+
// CHECK-NEXT: <string>Method returns an instance of NSObject with a +1 retain count</string>
2032920329
// CHECK-NEXT: <key>message</key>
20330-
// CHECK-NEXT: <string>Method returns an Objective-C object with a +1 retain count</string>
20330+
// CHECK-NEXT: <string>Method returns an instance of NSObject with a +1 retain count</string>
2033120331
// CHECK-NEXT: </dict>
2033220332
// CHECK-NEXT: <dict>
2033320333
// CHECK-NEXT: <key>kind</key><string>control</string>

test/Analysis/inlining/path-notes.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ id testAutoreleaseTakesEffectInDispatch() {
160160
dispatch_once(&token, ^{});
161161

162162
id x = [[[[NSObject alloc] init] autorelease] autorelease];
163-
// expected-note@-1 {{Method returns an Objective-C object with a +1 retain count}}
163+
// expected-note@-1 {{Method returns an instance of NSObject with a +1 retain count}}
164164
// expected-note@-2 {{Object autoreleased}}
165165
// expected-note@-3 {{Object autoreleased}}
166166

@@ -1840,9 +1840,9 @@ void testNullDereferenceInDispatch() {
18401840
// CHECK-NEXT: </array>
18411841
// CHECK-NEXT: <key>depth</key><integer>0</integer>
18421842
// CHECK-NEXT: <key>extended_message</key>
1843-
// CHECK-NEXT: <string>Method returns an Objective-C object with a +1 retain count</string>
1843+
// CHECK-NEXT: <string>Method returns an instance of NSObject with a +1 retain count</string>
18441844
// CHECK-NEXT: <key>message</key>
1845-
// CHECK-NEXT: <string>Method returns an Objective-C object with a +1 retain count</string>
1845+
// CHECK-NEXT: <string>Method returns an instance of NSObject with a +1 retain count</string>
18461846
// CHECK-NEXT: </dict>
18471847
// CHECK-NEXT: <dict>
18481848
// CHECK-NEXT: <key>kind</key><string>control</string>

test/Analysis/objc-arc.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ id rdar14061675() {
441441
// CHECK-NEXT: </array>
442442
// CHECK-NEXT: <key>depth</key><integer>0</integer>
443443
// CHECK-NEXT: <key>extended_message</key>
444-
// CHECK-NEXT: <string>Call to function &apos;CFDateCreate&apos; returns a Core Foundation object with a +1 retain count</string>
444+
// CHECK-NEXT: <string>Call to function &apos;CFDateCreate&apos; returns a Core Foundation object of type CFDateRef with a +1 retain count</string>
445445
// CHECK-NEXT: <key>message</key>
446-
// CHECK-NEXT: <string>Call to function &apos;CFDateCreate&apos; returns a Core Foundation object with a +1 retain count</string>
446+
// CHECK-NEXT: <string>Call to function &apos;CFDateCreate&apos; returns a Core Foundation object of type CFDateRef with a +1 retain count</string>
447447
// CHECK-NEXT: </dict>
448448
// CHECK-NEXT: <dict>
449449
// CHECK-NEXT: <key>kind</key><string>control</string>
@@ -911,9 +911,9 @@ id rdar14061675() {
911911
// CHECK-NEXT: </array>
912912
// CHECK-NEXT: <key>depth</key><integer>0</integer>
913913
// CHECK-NEXT: <key>extended_message</key>
914-
// CHECK-NEXT: <string>Call to function &apos;CFCreateSomething&apos; returns a Core Foundation object with a +1 retain count</string>
914+
// CHECK-NEXT: <string>Call to function &apos;CFCreateSomething&apos; returns a Core Foundation object of type CFTypeRef with a +1 retain count</string>
915915
// CHECK-NEXT: <key>message</key>
916-
// CHECK-NEXT: <string>Call to function &apos;CFCreateSomething&apos; returns a Core Foundation object with a +1 retain count</string>
916+
// CHECK-NEXT: <string>Call to function &apos;CFCreateSomething&apos; returns a Core Foundation object of type CFTypeRef with a +1 retain count</string>
917917
// CHECK-NEXT: </dict>
918918
// CHECK-NEXT: <dict>
919919
// CHECK-NEXT: <key>kind</key><string>control</string>
@@ -1091,9 +1091,9 @@ id rdar14061675() {
10911091
// CHECK-NEXT: </array>
10921092
// CHECK-NEXT: <key>depth</key><integer>0</integer>
10931093
// CHECK-NEXT: <key>extended_message</key>
1094-
// CHECK-NEXT: <string>Call to function &apos;CFCreateString&apos; returns a Core Foundation object with a +1 retain count</string>
1094+
// CHECK-NEXT: <string>Call to function &apos;CFCreateString&apos; returns a Core Foundation object of type CFStringRef with a +1 retain count</string>
10951095
// CHECK-NEXT: <key>message</key>
1096-
// CHECK-NEXT: <string>Call to function &apos;CFCreateString&apos; returns a Core Foundation object with a +1 retain count</string>
1096+
// CHECK-NEXT: <string>Call to function &apos;CFCreateString&apos; returns a Core Foundation object of type CFStringRef with a +1 retain count</string>
10971097
// CHECK-NEXT: </dict>
10981098
// CHECK-NEXT: <dict>
10991099
// CHECK-NEXT: <key>kind</key><string>control</string>
@@ -1466,9 +1466,9 @@ id rdar14061675() {
14661466
// CHECK-NEXT: </array>
14671467
// CHECK-NEXT: <key>depth</key><integer>0</integer>
14681468
// CHECK-NEXT: <key>extended_message</key>
1469-
// CHECK-NEXT: <string>Call to function &apos;CFDateCreate&apos; returns a Core Foundation object with a +1 retain count</string>
1469+
// CHECK-NEXT: <string>Call to function &apos;CFDateCreate&apos; returns a Core Foundation object of type CFDateRef with a +1 retain count</string>
14701470
// CHECK-NEXT: <key>message</key>
1471-
// CHECK-NEXT: <string>Call to function &apos;CFDateCreate&apos; returns a Core Foundation object with a +1 retain count</string>
1471+
// CHECK-NEXT: <string>Call to function &apos;CFDateCreate&apos; returns a Core Foundation object of type CFDateRef with a +1 retain count</string>
14721472
// CHECK-NEXT: </dict>
14731473
// CHECK-NEXT: <dict>
14741474
// CHECK-NEXT: <key>kind</key><string>control</string>
@@ -1782,9 +1782,9 @@ id rdar14061675() {
17821782
// CHECK-NEXT: </array>
17831783
// CHECK-NEXT: <key>depth</key><integer>0</integer>
17841784
// CHECK-NEXT: <key>extended_message</key>
1785-
// CHECK-NEXT: <string>Call to function &apos;CFCreateString&apos; returns a Core Foundation object with a +1 retain count</string>
1785+
// CHECK-NEXT: <string>Call to function &apos;CFCreateString&apos; returns a Core Foundation object of type CFStringRef with a +1 retain count</string>
17861786
// CHECK-NEXT: <key>message</key>
1787-
// CHECK-NEXT: <string>Call to function &apos;CFCreateString&apos; returns a Core Foundation object with a +1 retain count</string>
1787+
// CHECK-NEXT: <string>Call to function &apos;CFCreateString&apos; returns a Core Foundation object of type CFStringRef with a +1 retain count</string>
17881788
// CHECK-NEXT: </dict>
17891789
// CHECK-NEXT: <dict>
17901790
// CHECK-NEXT: <key>kind</key><string>control</string>
@@ -1879,9 +1879,9 @@ id rdar14061675() {
18791879
// CHECK-NEXT: </array>
18801880
// CHECK-NEXT: <key>depth</key><integer>0</integer>
18811881
// CHECK-NEXT: <key>extended_message</key>
1882-
// CHECK-NEXT: <string>Method returns an Objective-C object with a +0 retain count</string>
1882+
// CHECK-NEXT: <string>Method returns an instance of NSObject with a +0 retain count</string>
18831883
// CHECK-NEXT: <key>message</key>
1884-
// CHECK-NEXT: <string>Method returns an Objective-C object with a +0 retain count</string>
1884+
// CHECK-NEXT: <string>Method returns an instance of NSObject with a +0 retain count</string>
18851885
// CHECK-NEXT: </dict>
18861886
// CHECK-NEXT: <dict>
18871887
// CHECK-NEXT: <key>kind</key><string>control</string>

test/Analysis/plist-output-alternate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,9 +1191,9 @@ void rdar8331641(int x) {
11911191
// CHECK-NEXT: </array>
11921192
// CHECK-NEXT: <key>depth</key><integer>0</integer>
11931193
// CHECK-NEXT: <key>extended_message</key>
1194-
// CHECK-NEXT: <string>Call to function &apos;CFNumberCreate&apos; returns a Core Foundation object with a +1 retain count</string>
1194+
// CHECK-NEXT: <string>Call to function &apos;CFNumberCreate&apos; returns a Core Foundation object of type CFNumberRef with a +1 retain count</string>
11951195
// CHECK-NEXT: <key>message</key>
1196-
// CHECK-NEXT: <string>Call to function &apos;CFNumberCreate&apos; returns a Core Foundation object with a +1 retain count</string>
1196+
// CHECK-NEXT: <string>Call to function &apos;CFNumberCreate&apos; returns a Core Foundation object of type CFNumberRef with a +1 retain count</string>
11971197
// CHECK-NEXT: </dict>
11981198
// CHECK-NEXT: <dict>
11991199
// CHECK-NEXT: <key>kind</key><string>control</string>

test/Analysis/retain-release-arc.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ - (NSDictionary *)copyTestWithBridgeReturningRetainable:(NSData *)plistData {
9090
CFErrorRef error;
9191
CFDictionaryRef testDict = CFPropertyListCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)plistData, 0, 0, &error);
9292
#if HAS_ARC
93-
// expected-note@-2 {{Call to function 'CFPropertyListCreateWithData' returns a Core Foundation object with a +1 retain count}}
93+
// expected-note@-2 {{Call to function 'CFPropertyListCreateWithData' returns a Core Foundation object of type CFPropertyListRef with a +1 retain count}}
9494
#endif
9595
return (__bridge NSDictionary *)testDict;
9696
#if HAS_ARC

0 commit comments

Comments
 (0)