blob: 6bf299d6bed5ad36c5249d0379793bdbb8841f01 [file] [log] [blame]
Ted Kremenek2f2692f2010-02-05 02:06:54 +00001// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s
2// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s
3// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s
4// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s
Ted Kremenekb5351812009-02-17 04:27:41 +00005
Ted Kremenek55bec4d2008-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 Kremenekf368fa62009-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 Lattner4fc69792008-11-24 01:28:17 +000028 *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference.}}
Ted Kremenek55bec4d2008-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 Kremenek3aa89a92008-10-01 23:24:09 +000036
37struct __CFError {};
38typedef struct __CFError* CFErrorRef;
39
Ted Kremenekf368fa62009-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 Lattner4fc69792008-11-24 01:28:17 +000041 *error = 0; // expected-warning {{Potential null dereference.}}
Ted Kremenek3aa89a92008-10-01 23:24:09 +000042}
43
Ted Kremenek035cf932009-03-28 19:59:33 +000044int f1(CFErrorRef* error) {
45 if (error) *error = 0; // no-warning
Ted Kremenek3aa89a92008-10-01 23:24:09 +000046 return 0;
47}
Ted Kremenek035cf932009-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