diff options
-rw-r--r-- | lib/Analysis/CFRefCount.cpp | 10 | ||||
-rw-r--r-- | test/Analysis/refcnt_naming.m | 4 | ||||
-rw-r--r-- | test/Analysis/retain-release.m | 22 |
3 files changed, 30 insertions, 6 deletions
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 50ddbba5b2..c629ad1d96 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -93,12 +93,14 @@ static NamingConvention deriveNamingConvention(Selector S) { // Skip '_'. if (*s == '_') { if (InPossiblePrefix) { + // If we already have a convention, return it. Otherwise, skip + // the prefix as if it wasn't there. + if (C != NoConvention) + break; + InPossiblePrefix = false; AtBeginning = true; - // Discard whatever 'convention' we - // had already derived since it occurs - // in the prefix. - C = NoConvention; + assert(C == NoConvention); } ++s; continue; diff --git a/test/Analysis/refcnt_naming.m b/test/Analysis/refcnt_naming.m index bea404799b..2ce00b2a8c 100644 --- a/test/Analysis/refcnt_naming.m +++ b/test/Analysis/refcnt_naming.m @@ -15,7 +15,7 @@ typedef signed char BOOL; -(NSObject*)photoCopy; // read as "photo Copy" -(NSObject*)__blebPRCopy; // read as "bleb PRCopy" -(NSObject*)__blebPRcopy; // read as "bleb P Rcopy" --(NSObject*)new_theprefixdoesnotcount; // read as "theprefixdoesnotcount" +-(NSObject*)new_theprefixdoescount; // read as "new theprefixdoescount" -(NSObject*)newestAwesomeStuff; // read as "newest awesome stuff" @end @@ -49,7 +49,7 @@ void testNames(NamingTest* x) { [x photoCopy]; // expected-warning{{leak}} [x __blebPRCopy]; // expected-warning{{leak}} [x __blebPRcopy]; // no-warning - [x new_theprefixdoesnotcount]; // no-warning + [x new_theprefixdoescount]; // expected-warning{{leak}} [x newestAwesomeStuff]; // no-warning } diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index a14a50b0fb..e620037b2c 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -1098,6 +1098,28 @@ CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height, } //===----------------------------------------------------------------------===// +// <rdar://problem/7265711> allow 'new', 'copy', 'alloc', 'init' prefix to +// start before '_' when determining Cocoa fundamental rule +// +// Previously the retain/release checker just skipped prefixes before the +// first '_' entirely. Now the checker honors the prefix if it results in a +// recognizable naming convention (e.g., 'new', 'init'). +//===----------------------------------------------------------------------===// + +@interface RDar7265711 {} +- (id) new_stuff; +@end + +void rdar7265711_a(RDar7265711 *x) { + id y = [x new_stuff]; // expected-warning{{leak}} +} + +void rdar7265711_b(RDar7265711 *x) { + id y = [x new_stuff]; // no-warning + [y release]; +} + +//===----------------------------------------------------------------------===// // <rdar://problem/7306898> clang thinks [NSCursor dragCopyCursor] returns a // retained reference //===----------------------------------------------------------------------===// |