]> granicus.if.org Git - clang/commitdiff
retain/release checker: allow 'new', 'copy', 'alloc', 'init' prefix to start before...
authorTed Kremenek <kremenek@apple.com>
Tue, 20 Oct 2009 00:13:00 +0000 (00:13 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 20 Oct 2009 00:13:00 +0000 (00:13 +0000)
Fixes: <rdar://problem/7265711>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84569 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFRefCount.cpp
test/Analysis/refcnt_naming.m
test/Analysis/retain-release.m

index 50ddbba5b2c52b42ef199151ec263e9e8969433f..c629ad1d961234bf06561411578ca473068e8c28 100644 (file)
@@ -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;
index bea404799ba3474945eb715fe82a3b5a63e58943..2ce00b2a8cca71de51a15b4e3fae3049921fa185 100644 (file)
@@ -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
 }
 
index a14a50b0fb6c66615b0a3291ee61a35f23bdcb37..e620037b2c14fdcf95b1a08e54ac13c2cc6c9ffa 100644 (file)
@@ -1097,6 +1097,28 @@ CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height,
               pixelBufferAttributes, pixelBufferOut) ;
 }
 
+//===----------------------------------------------------------------------===//
+// <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