blob: b3eacda20d2de5d43426597177ec1d35019c5d9a [file] [log] [blame]
Ted Kremenekf536ca32009-01-22 18:54:47 +00001// RUN: clang -analyze -checker-cfref -analyzer-store-basic -verify %s &&
2// RUN: clang -analyze -checker-cfref -analyzer-store-region -verify %s
Ted Kremenek1cd920a2008-09-19 04:56:32 +00003
4typedef signed char BOOL;
5typedef int NSInteger;
6typedef struct _NSZone NSZone;
7@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
8@protocol NSObject - (BOOL)isEqual:(id)object; @end
9@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
10@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
11@interface NSObject <NSObject> {} @end
12@class NSDictionary;
13@interface NSError : NSObject <NSCopying, NSCoding> {}
14+ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict;
15@end
16extern NSString * const NSXMLParserErrorDomain ;
17
18@interface A
19- (void)myMethodWhichMayFail:(NSError **)error;
20- (BOOL)myMethodWhichMayFail2:(NSError **)error;
21@end
22
23@implementation A
Chris Lattner0947b4e2008-11-24 01:28:17 +000024- (void)myMethodWhichMayFail:(NSError **)error { // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occured.}}
25 *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference.}}
Ted Kremenek1cd920a2008-09-19 04:56:32 +000026}
27
28- (BOOL)myMethodWhichMayFail2:(NSError **)error { // no-warning
29 if (error) *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
30 return 0;
31}
32@end
Ted Kremenekcc9ac412008-10-01 23:24:09 +000033
34struct __CFError {};
35typedef struct __CFError* CFErrorRef;
36
Chris Lattner0947b4e2008-11-24 01:28:17 +000037void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occured.}}
38 *error = 0; // expected-warning {{Potential null dereference.}}
Ted Kremenekcc9ac412008-10-01 23:24:09 +000039}
40
41int bar(CFErrorRef* error) {
42 if (error) *error = 0;
43 return 0;
44}