[cfe-commits] r51872 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis-Apple/NSString.m

Ted Kremenek kremenek at apple.com
Mon Jun 2 10:14:13 PDT 2008


Author: kremenek
Date: Mon Jun  2 12:14:13 2008
New Revision: 51872

URL: http://llvm.org/viewvc/llvm-project?rev=51872&view=rev
Log:
Teach the CF retain checker about "_init" methods.  Fixes: <rdar://problem/5956379>

Modified:
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/test/Analysis-Apple/NSString.m

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=51872&r1=51871&r2=51872&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Mon Jun  2 12:14:13 2008
@@ -607,7 +607,7 @@
   const char* s = S.getIdentifierInfoForSlot(0)->getName();
   assert (ScratchArgs.empty());
   
-  if (strncmp(s, "init", 4) == 0)
+  if (strncmp(s, "init", 4) == 0 || strncmp(s, "_init", 5) == 0)
     return getInitMethodSummary(S);  
   
   // "copyXXX", "createXXX", "newXXX": allocators.  

Modified: cfe/trunk/test/Analysis-Apple/NSString.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis-Apple/NSString.m?rev=51872&r1=51871&r2=51872&view=diff

==============================================================================
--- cfe/trunk/test/Analysis-Apple/NSString.m (original)
+++ cfe/trunk/test/Analysis-Apple/NSString.m Mon Jun  2 12:14:13 2008
@@ -71,23 +71,15 @@
 }
 
 @interface C1 : NSObject {}
-
 - (NSString*) getShared;
 + (C1*) sharedInstance;
-
 @end
-
 @implementation C1 : NSObject {}
-
 - (NSString*) getShared {
-  
   static NSString* s = nil;
-  
-  if (!s) s = [[NSString alloc] init];
-    
+  if (!s) s = [[NSString alloc] init];    
   return s; // no-warning  
 }
-
 + (C1 *)sharedInstance {
   static C1 *sharedInstance = nil;
   if (!sharedInstance) {
@@ -95,6 +87,25 @@
   }
   return sharedInstance; // no-warning
 }
+ at end
 
+ at interface SharedClass : NSObject
++ (id)sharedInstance;
 @end
+ at implementation SharedClass
+
+- (id)_init {
+    if ((self = [super init])) {
+        NSLog(@"Bar");
+    }
+    return self;
+}
 
++ (id)sharedInstance {
+    static SharedClass *_sharedInstance = nil;
+    if (!_sharedInstance) {
+        _sharedInstance = [[SharedClass alloc] _init];
+    }
+    return _sharedInstance; // no-warning
+}
+ at end





More information about the cfe-commits mailing list