blob: 8b2b82fabae1149fb1186df78be69b29c1f310ae [file] [log] [blame]
Argyrios Kyrtzidisd7a31ba2011-01-11 19:45:25 +00001// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem %s -verify
2
3@class NSZone, NSCoder;
4@protocol NSObject
5@end
6@protocol NSCopying - (id)copyWithZone:(NSZone *)zone;
7@end
8@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone;
9@end
10@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder;
11@end
12@interface NSObject <NSObject> {}
13+ (id)allocWithZone:(NSZone *)zone;
14+ (id)alloc;
15- (void)dealloc;
16-(id)class;
17-(id)init;
18-(id)release;
19@end
20//#import "Foundation/NSObject.h"
21typedef unsigned NSUInteger;
22typedef int NSInteger;
23
24@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
25@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
26- (NSUInteger)length;
27+ (id)stringWithUTF8String:(const char *)nullTerminatedCString;
28@end extern NSString * const NSBundleDidLoadNotification;
29@interface NSAssertionHandler : NSObject {}
30+ (NSAssertionHandler *)currentHandler;
31- (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...;
32@end
33extern NSString * const NSConnectionReplyMode;
34
35@interface NSBundle : NSObject
36+(id)loadNibNamed:(NSString*)s owner:(id)o;
37@end
38
39void log(void *obj);
40extern void *somePtr;
41
42@interface MyObj : NSObject {
43 id myivar;
44 int myint;
45}
46-(id)_init;
47-(id)initWithSomething:(int)x;
48-(void)doSomething;
49@end
50
51@implementation MyObj
52
53-(id)init {
54 do { if (!((somePtr != 0))) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:"init.m"] lineNumber:21 description:(@"Invalid parameter not satisfying: %s"), ("x != 0"), (0), (0), (0), (0)]; } } while(0);
55 return [self initWithSomething:0];
56}
57
58-(id)init2 {
59 self = [self initWithSomething:0];
60 return self;
61}
62
63-(id)init3 {
64 log([self class]);
65 return [self initWithSomething:0];
66}
67
68-(id)init4 {
69 self = [super init];
70 if (self) {
71 log(&self);
72 }
73 return self;
74}
75
76- (id)initWithSomething:(int)x {
77 if ((self = [super init]))
78 myint = x;
79 return self;
80}
81
82-(id)_init {
83 myivar = 0;
84 return self;
85}
86
87-(id)init5 {
88 [NSBundle loadNibNamed:@"Window" owner:self];
89 return [self initWithSomething:0];
90}
91
92-(id)init6 {
93 [NSBundle loadNibNamed:@"Window" owner:myivar]; // expected-warning {{Using an ivar}}
94 return [self initWithSomething:0];
95}
96
97-(id)init7 {
98 if (0 != (self = [self _init]))
99 myivar = 0;
100 return self;
101}
102
103-(id)init8 {
104 if ((self = [super init])) {
105 log(&self);
106 myivar = 0;
107 }
108 return self;
109}
110
111-(id)init9 {
112 [self doSomething];
113 return self; // expected-warning {{Returning 'self'}}
114}
115
116-(id)init10 {
117 myivar = 0; // expected-warning {{Using an ivar}}
118 return self;
119}
120
121-(id)init11 {
122 return self; // expected-warning {{Returning 'self'}}
123}
124
125-(id)init12 {
126 [super init];
127 return self; // expected-warning {{Returning 'self'}}
128}
129
130-(id)init13 {
131 if ((self == [super init])) {
132 myivar = 0; // expected-warning {{Using an ivar}}
133 }
134 return self; // expected-warning {{Returning 'self'}}
135}
136
137-(void)doSomething {}
138
139@end