blob: 5f92594f30d826fd9a86b830bba2ab19d94bdcbd [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s &&
2// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s &&
3// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s &&
4// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +00005
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
Ted Kremenekaddc9312009-08-06 06:26:40 +000027- (void)myMethodWhichMayFail:(NSError **)error { // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred}}
Chris Lattner0947b4e2008-11-24 01:28:17 +000028 *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
Ted Kremenekaddc9312009-08-06 06:26:40 +000040void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred}}
Chris Lattner0947b4e2008-11-24 01:28:17 +000041 *error = 0; // expected-warning {{Potential null dereference.}}
Ted Kremenekcc9ac412008-10-01 23:24:09 +000042}
43
Ted Kremenek2a8d6b02009-03-28 19:59:33 +000044int f1(CFErrorRef* error) {
45 if (error) *error = 0; // no-warning
Ted Kremenekcc9ac412008-10-01 23:24:09 +000046 return 0;
47}
Ted Kremenek2a8d6b02009-03-28 19:59:33 +000048
49int f2(CFErrorRef* error) {
50 if (0 != error) *error = 0; // no-warning
51 return 0;
52}
53
54int f3(CFErrorRef* error) {
55 if (error != 0) *error = 0; // no-warning
56 return 0;
57}
58
59