diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-02-05 05:54:53 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-02-05 05:54:53 +0000 |
| commit | dd03d8ddaa18f9b197dc52c20894e34dae0a2462 (patch) | |
| tree | d32a06ef5a1f936957ce5957cdb34d0b397f1ede /clang/test/Analysis/self-init.m | |
| parent | 3d3208675f79d05fd0b026c735fbe83ecd20a98b (diff) | |
| download | bcm5719-llvm-dd03d8ddaa18f9b197dc52c20894e34dae0a2462.tar.gz bcm5719-llvm-dd03d8ddaa18f9b197dc52c20894e34dae0a2462.zip | |
[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
Diffstat (limited to 'clang/test/Analysis/self-init.m')
| -rw-r--r-- | clang/test/Analysis/self-init.m | 13 |
1 files changed, 13 insertions, 0 deletions
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 |

