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