[analyzer] Fix a false positive of the 'self' initialization checker.
A common pattern in classes with multiple initializers is to put the
subclass's common initialization bits into a static function that receives
the value of 'self', e.g:
if (!(self = [super init]))
return nil;
if (!(self = _commonInit(self)))
return nil;
It was reported that 'self' was not set to the result of [super init].
Until we can use inter-procedural analysis, in such a call, transfer the
ObjCSelfInitChecker flags associated with 'self' to the result of the call.
Fixes rdar://8937441 & http://llvm.org/PR9094
llvm-svn: 124940
diff --git a/clang/test/Analysis/self-init.m b/clang/test/Analysis/self-init.m
index 1dc5aa9..b4c6f29 100644
--- a/clang/test/Analysis/self-init.m
+++ b/clang/test/Analysis/self-init.m
@@ -42,6 +42,11 @@
void log(void *obj);
extern void *somePtr;
+@class MyObj;
+static id _commonInit(MyObj *self) {
+ return self;
+}
+
@interface MyObj : NSObject {
id myivar;
int myint;
@@ -141,6 +146,14 @@
return self; // expected-warning {{Returning 'self'}}
}
+-(id)init14 {
+ if (!(self = [super init]))
+ return 0;
+ if (!(self = _commonInit(self)))
+ return 0;
+ return self;
+}
+
-(void)doSomething {}
@end