summaryrefslogtreecommitdiffstats
path: root/test/Analysis
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/objc-bool.m2
-rw-r--r--test/Analysis/redefined_system.c2
-rw-r--r--test/Analysis/self-init.m61
3 files changed, 59 insertions, 6 deletions
diff --git a/test/Analysis/objc-bool.m b/test/Analysis/objc-bool.m
index 631cd2d..f95736a 100644
--- a/test/Analysis/objc-bool.m
+++ b/test/Analysis/objc-bool.m
@@ -1,4 +1,4 @@
-// RUN: %clang --analyze %s -o %t -verify
+// RUN: %clang --analyze %s -o %t -Xclang -verify
// Test handling of ObjC bool literals.
diff --git a/test/Analysis/redefined_system.c b/test/Analysis/redefined_system.c
index 3f585c4..3c08b5e 100644
--- a/test/Analysis/redefined_system.c
+++ b/test/Analysis/redefined_system.c
@@ -12,6 +12,6 @@ char strdup();
char atoi();
int foo () {
- return memmove() + malloc() + system + stdin() + memccpy() + free() + strdup() + atoi();
+ return memmove() + malloc() + system() + stdin() + memccpy() + free() + strdup() + atoi();
}
diff --git a/test/Analysis/self-init.m b/test/Analysis/self-init.m
index 3db42e9..d515173 100644
--- a/test/Analysis/self-init.m
+++ b/test/Analysis/self-init.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=osx.cocoa.SelfInit %s -verify
+// RUN: %clang_cc1 -analyze -analyzer-checker=osx.cocoa.SelfInit -fobjc-default-synthesize-properties %s -verify
@class NSZone, NSCoder;
@protocol NSObject- (id)self;
@@ -48,9 +48,7 @@ void log(void *obj);
extern void *somePtr;
@class MyObj;
-static id _commonInit(MyObj *self) {
- return self;
-}
+extern id _commonInit(MyObj *self);
@interface MyObj : NSObject {
id myivar;
@@ -59,6 +57,7 @@ static id _commonInit(MyObj *self) {
-(id)_init;
-(id)initWithSomething:(int)x;
-(void)doSomething;
++(id)commonInitMember:(id)s;
@end
@interface MyProxyObj : NSProxy {}
@@ -90,6 +89,14 @@ static id _commonInit(MyObj *self) {
return self;
}
+-(id)init4_w {
+ [super init];
+ if (self) {
+ log(&self);
+ }
+ return self; // expected-warning {{Returning 'self' while it is not set to the result of '[(super or self) init...]'}}
+}
+
- (id)initWithSomething:(int)x {
if ((self = [super init]))
myint = x;
@@ -157,6 +164,12 @@ static id _commonInit(MyObj *self) {
return self;
}
+-(id)init14_w {
+ [super init];
+ self = _commonInit(self);
+ return self; // expected-warning {{Returning 'self' while it is not set to the result of '[(super or self) init...]'}}
+}
+
-(id)init15 {
if (!(self = [super init]))
return 0;
@@ -176,6 +189,28 @@ static id _commonInit(MyObj *self) {
return 0;
}
+-(id)init18 {
+ self = [super init];
+ self = _commonInit(self);
+ return self;
+}
+
++(id)commonInitMember:(id)s {
+ return s;
+}
+
+-(id)init19 {
+ self = [super init];
+ self = [MyObj commonInitMember:self];
+ return self;
+}
+
+-(id)init19_w {
+ [super init];
+ self = [MyObj commonInitMember:self];
+ return self; // expected-warning {{Returning 'self'}}
+}
+
-(void)doSomething {}
@end
@@ -201,3 +236,21 @@ static id _commonInit(MyObj *self) {
}
@end
+// Test radar:11235991 - passing self to a call to super.
+@protocol MyDelegate
+@end
+@interface Object : NSObject
+- (id) initWithObject: (id)i;
+@end
+@interface Derived: Object <MyDelegate>
+- (id) initWithInt: (int)t;
+@property (nonatomic, retain, readwrite) Object *size;
+@end
+@implementation Derived
+- (id) initWithInt: (int)t {
+ if ((self = [super initWithObject:self])) {
+ _size = [[Object alloc] init];
+ }
+ return self;
+}
+@end
OpenPOWER on IntegriCloud