1*f4a2713aSLionel Sambuc// 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 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc 4*f4a2713aSLionel Sambuctypedef signed char BOOL; 5*f4a2713aSLionel Sambuctypedef int NSInteger; 6*f4a2713aSLionel Sambuctypedef struct _NSZone NSZone; 7*f4a2713aSLionel Sambuc@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; 8*f4a2713aSLionel Sambuc@protocol NSObject - (BOOL)isEqual:(id)object; @end 9*f4a2713aSLionel Sambuc@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end 10*f4a2713aSLionel Sambuc@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end 11*f4a2713aSLionel Sambuc@interface NSObject <NSObject> {} @end 12*f4a2713aSLionel Sambuc@class NSDictionary; 13*f4a2713aSLionel Sambuc@interface NSError : NSObject <NSCopying, NSCoding> {} 14*f4a2713aSLionel Sambuc+ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict; 15*f4a2713aSLionel Sambuc@end 16*f4a2713aSLionel Sambucextern NSString * const NSXMLParserErrorDomain ; 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel Sambuc@interface A 19*f4a2713aSLionel Sambuc- (void)myMethodWhichMayFail:(NSError **)error; 20*f4a2713aSLionel Sambuc- (BOOL)myMethodWhichMayFail2:(NSError **)error; 21*f4a2713aSLionel Sambuc@end 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc@implementation A 24*f4a2713aSLionel Sambuc- (void)myMethodWhichMayFail:(NSError **)error { // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred}} 25*f4a2713aSLionel Sambuc *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference}} 26*f4a2713aSLionel Sambuc} 27*f4a2713aSLionel Sambuc 28*f4a2713aSLionel Sambuc- (BOOL)myMethodWhichMayFail2:(NSError **)error { // no-warning 29*f4a2713aSLionel Sambuc if (error) *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning 30*f4a2713aSLionel Sambuc return 0; 31*f4a2713aSLionel Sambuc} 32*f4a2713aSLionel Sambuc@end 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambucstruct __CFError {}; 35*f4a2713aSLionel Sambuctypedef struct __CFError* CFErrorRef; 36*f4a2713aSLionel Sambuc 37*f4a2713aSLionel Sambucvoid foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred}} 38*f4a2713aSLionel Sambuc *error = 0; // expected-warning {{Potential null dereference}} 39*f4a2713aSLionel Sambuc} 40*f4a2713aSLionel Sambuc 41*f4a2713aSLionel Sambucint f1(CFErrorRef* error) { 42*f4a2713aSLionel Sambuc if (error) *error = 0; // no-warning 43*f4a2713aSLionel Sambuc return 0; 44*f4a2713aSLionel Sambuc} 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambucint f2(CFErrorRef* error) { 47*f4a2713aSLionel Sambuc if (0 != error) *error = 0; // no-warning 48*f4a2713aSLionel Sambuc return 0; 49*f4a2713aSLionel Sambuc} 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambucint f3(CFErrorRef* error) { 52*f4a2713aSLionel Sambuc if (error != 0) *error = 0; // no-warning 53*f4a2713aSLionel Sambuc return 0; 54*f4a2713aSLionel Sambuc} 55*f4a2713aSLionel Sambuc 56*f4a2713aSLionel Sambuc 57