diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-06-02 17:14:13 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-06-02 17:14:13 +0000 |
commit | 0327f778699f0828b8ffb540e9d1e7cbe97d67a1 (patch) | |
tree | c20e93e4aa49e352e5015f7f1fe79034c2c6cdab | |
parent | b96ffdf59e1630fffffcb237e2e0e542c550a978 (diff) |
Teach the CF retain checker about "_init" methods. Fixes: <rdar://problem/5956379>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51872 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/CFRefCount.cpp | 2 | ||||
-rw-r--r-- | test/Analysis-Apple/NSString.m | 29 |
2 files changed, 21 insertions, 10 deletions
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 5660929a87..24971edcdd 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -607,7 +607,7 @@ RetainSummaryManager::getMethodSummary(ObjCMessageExpr* ME) { 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. diff --git a/test/Analysis-Apple/NSString.m b/test/Analysis-Apple/NSString.m index bf9d4e8e88..a1eefd45d7 100644 --- a/test/Analysis-Apple/NSString.m +++ b/test/Analysis-Apple/NSString.m @@ -71,23 +71,15 @@ NSString* f10() { } @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 @@ NSString* f10() { } return sharedInstance; // no-warning } +@end +@interface SharedClass : NSObject ++ (id)sharedInstance; @end +@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 +} +@end |