diff options
| author | Anna Zaks <ganna@apple.com> | 2012-05-08 21:19:21 +0000 |
|---|---|---|
| committer | Anna Zaks <ganna@apple.com> | 2012-05-08 21:19:21 +0000 |
| commit | 66843480a64a9f23f2a23118d92aa3dd6260af0c (patch) | |
| tree | 22b4768885f4c94b6d0ea38e7a1f157b1066da58 /clang/test | |
| parent | 92f6adc8befc032ab6d442a0d121a67573d6f91e (diff) | |
| download | bcm5719-llvm-66843480a64a9f23f2a23118d92aa3dd6260af0c.tar.gz bcm5719-llvm-66843480a64a9f23f2a23118d92aa3dd6260af0c.zip | |
[analyzer] SelfInit: Stop tracking self if it's assigned a value we
don't reason about.
Self is just like a local variable in init methods, so it can be
assigned anything like result of static functions, other methods ... So
to suppress false positives that result in such cases, stop tracking the
checker-specific state after self is being assigned to (unless the
value is't being assigned to is either self or conforms to our rules).
This change does not invalidate any existing regression tests.
llvm-svn: 156420
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/self-init.m | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/clang/test/Analysis/self-init.m b/clang/test/Analysis/self-init.m index 365096e4454..10b0c4da47b 100644 --- a/clang/test/Analysis/self-init.m +++ b/clang/test/Analysis/self-init.m @@ -1,7 +1,8 @@ // RUN: %clang_cc1 -analyze -analyzer-checker=osx.cocoa.SelfInit -fobjc-default-synthesize-properties -fno-builtin %s -verify @class NSZone, NSCoder; -@protocol NSObject- (id)self; +@protocol NSObject +- (id)self; @end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end @@ -254,3 +255,28 @@ extern id _commonInit(MyObj *self); return self; } @end + +// Test for radar://11125870: init constructing a special instance. +typedef signed char BOOL; +@interface MyClass : NSObject +@end +@implementation MyClass ++ (id)specialInstance { + return [[MyClass alloc] init]; +} +- (id)initSpecially:(BOOL)handleSpecially { + if ((self = [super init])) { + if (handleSpecially) { + self = [MyClass specialInstance]; + } + } + return self; +} +- (id)initSelfSelf { + if ((self = [super init])) { + self = self; + } + return self; +} +@end + |

