blob: d35b686ef1d9c854f953fddca406d64456dee62d [file] [log] [blame]
Patrick Beardacfbe9e2012-04-06 18:12:22 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.NSError,osx.coreFoundation.CFError -analyzer-store=region -analyzer-constraints=basic -verify -Wno-objc-root-class %s
2// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.NSError,osx.coreFoundation.CFError -analyzer-store=region -analyzer-constraints=range -verify -Wno-objc-root-class %s
Ted Kremenekb5351812009-02-17 04:27:41 +00003
Ted Kremenek55bec4d2008-09-19 04:56:32 +00004
5typedef signed char BOOL;
6typedef int NSInteger;
7typedef struct _NSZone NSZone;
8@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
9@protocol NSObject - (BOOL)isEqual:(id)object; @end
10@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
11@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
12@interface NSObject <NSObject> {} @end
13@class NSDictionary;
14@interface NSError : NSObject <NSCopying, NSCoding> {}
15+ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict;
16@end
17extern NSString * const NSXMLParserErrorDomain ;
18
19@interface A
20- (void)myMethodWhichMayFail:(NSError **)error;
21- (BOOL)myMethodWhichMayFail2:(NSError **)error;
22@end
23
24@implementation A
Ted Kremenekf368fa62009-08-06 06:26:40 +000025- (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 +000026 *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference.}}
Ted Kremenek55bec4d2008-09-19 04:56:32 +000027}
28
29- (BOOL)myMethodWhichMayFail2:(NSError **)error { // no-warning
30 if (error) *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
31 return 0;
32}
33@end
Ted Kremenek3aa89a92008-10-01 23:24:09 +000034
35struct __CFError {};
36typedef struct __CFError* CFErrorRef;
37
Ted Kremenekf368fa62009-08-06 06:26:40 +000038void 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 +000039 *error = 0; // expected-warning {{Potential null dereference.}}
Ted Kremenek3aa89a92008-10-01 23:24:09 +000040}
41
Ted Kremenek035cf932009-03-28 19:59:33 +000042int f1(CFErrorRef* error) {
43 if (error) *error = 0; // no-warning
Ted Kremenek3aa89a92008-10-01 23:24:09 +000044 return 0;
45}
Ted Kremenek035cf932009-03-28 19:59:33 +000046
47int f2(CFErrorRef* error) {
48 if (0 != error) *error = 0; // no-warning
49 return 0;
50}
51
52int f3(CFErrorRef* error) {
53 if (error != 0) *error = 0; // no-warning
54 return 0;
55}
56
57