From dd03d8ddaa18f9b197dc52c20894e34dae0a2462 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 5 Feb 2011 05:54:53 +0000 Subject: [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 --- clang/test/Analysis/self-init.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'clang/test/Analysis') diff --git a/clang/test/Analysis/self-init.m b/clang/test/Analysis/self-init.m index 1dc5aa92f9c..b4c6f29e387 100644 --- a/clang/test/Analysis/self-init.m +++ b/clang/test/Analysis/self-init.m @@ -42,6 +42,11 @@ extern NSString * const NSConnectionReplyMode; 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 @@ extern void *somePtr; 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 -- cgit v1.2.3