1*67e74705SXin Li// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,alpha.core -verify %s -analyzer-constraints=range -analyzer-store=region 2*67e74705SXin Li// expected-no-diagnostics 3*67e74705SXin Li 4*67e74705SXin Litypedef struct objc_selector *SEL; 5*67e74705SXin Litypedef signed char BOOL; 6*67e74705SXin Litypedef int NSInteger; 7*67e74705SXin Litypedef unsigned int NSUInteger; 8*67e74705SXin Litypedef struct _NSZone NSZone; 9*67e74705SXin Li@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; 10*67e74705SXin Li@protocol NSObject - (BOOL)isEqual:(id)object; @end 11*67e74705SXin Li@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end 12*67e74705SXin Li@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end 13*67e74705SXin Li@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end 14*67e74705SXin Li@interface NSObject <NSObject> {} - (id)init; @end 15*67e74705SXin Liextern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); 16*67e74705SXin Li@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> 17*67e74705SXin Li- (NSUInteger)length; 18*67e74705SXin Li+ (id)stringWithUTF8String:(const char *)nullTerminatedCString; 19*67e74705SXin Li@end extern NSString * const NSBundleDidLoadNotification; 20*67e74705SXin Li@interface NSAssertionHandler : NSObject {} 21*67e74705SXin Li+ (NSAssertionHandler *)currentHandler; 22*67e74705SXin Li- (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...; 23*67e74705SXin Li- (void)handleFailureInFunction:(NSString *)functionName file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...; 24*67e74705SXin Li@end 25*67e74705SXin Liextern NSString * const NSConnectionReplyMode; 26*67e74705SXin Li 27*67e74705SXin Li//----------------------------------------------------------------------------// 28*67e74705SXin Li// The following test case was filed in PR 2593: 29*67e74705SXin Li// http://llvm.org/bugs/show_bug.cgi?id=2593 30*67e74705SXin Li// 31*67e74705SXin Li// There should be no null dereference flagged by the checker because of 32*67e74705SXin Li// NSParameterAssert and NSAssert. 33*67e74705SXin Li 34*67e74705SXin Li 35*67e74705SXin Li@interface TestAssert : NSObject {} 36*67e74705SXin Li@end 37*67e74705SXin Li 38*67e74705SXin Li@implementation TestAssert 39*67e74705SXin Li 40*67e74705SXin Li- (id)initWithPointer: (int*)x 41*67e74705SXin Li{ 42*67e74705SXin Li // Expansion of: NSParameterAssert( x != 0 ); 43*67e74705SXin Li do { if (!((x != 0))) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:"CFRetainRelease_NSAssertionHandler.m"] lineNumber:21 description:(@"Invalid parameter not satisfying: %s"), ("x != 0"), (0), (0), (0), (0)]; } } while(0); 44*67e74705SXin Li 45*67e74705SXin Li if( (self = [super init]) != 0 ) 46*67e74705SXin Li { 47*67e74705SXin Li *x = 1; // no-warning 48*67e74705SXin Li } 49*67e74705SXin Li 50*67e74705SXin Li return self; 51*67e74705SXin Li} 52*67e74705SXin Li 53*67e74705SXin Li- (id)initWithPointer2: (int*)x 54*67e74705SXin Li{ 55*67e74705SXin Li // Expansion of: NSAssert( x != 0, @"" ); 56*67e74705SXin Li do { if (!((x != 0))) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:"CFRetainRelease_NSAssertionHandler.m"] lineNumber:33 description:((@"")), (0), (0), (0), (0), (0)]; } } while(0); 57*67e74705SXin Li 58*67e74705SXin Li if( (self = [super init]) != 0 ) 59*67e74705SXin Li { 60*67e74705SXin Li *x = 1; // no-warning 61*67e74705SXin Li } 62*67e74705SXin Li 63*67e74705SXin Li return self; 64*67e74705SXin Li} 65*67e74705SXin Li 66*67e74705SXin Li@end 67*67e74705SXin Li 68*67e74705SXin Livoid pointerFunction (int *x) { 69*67e74705SXin Li // Manual expansion of NSCAssert( x != 0, @"") 70*67e74705SXin Li do { if (!((x != 0))) { [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] file:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ description:((@""))]; } } while(0); 71*67e74705SXin Li 72*67e74705SXin Li *x = 1; // no-warning 73*67e74705SXin Li} 74