From: Ted Kremenek Date: Tue, 20 Oct 2009 00:13:00 +0000 (+0000) Subject: retain/release checker: allow 'new', 'copy', 'alloc', 'init' prefix to start before... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9731832ec3b995defba821ec24343d74d004f9f;p=clang retain/release checker: allow 'new', 'copy', 'alloc', 'init' prefix to start before '_' when determining Cocoa fundamental rule. Fixes: git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84569 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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 @@ -1097,6 +1097,28 @@ CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height, pixelBufferAttributes, pixelBufferOut) ; } +//===----------------------------------------------------------------------===// +// 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]; +} + //===----------------------------------------------------------------------===// // clang thinks [NSCursor dragCopyCursor] returns a // retained reference