1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount,alpha.core -verify %s
2 // expected-no-diagnostics
4 typedef struct objc_selector *SEL;
5 typedef signed char BOOL;
7 typedef unsigned int NSUInteger;
8 typedef struct _NSZone NSZone;
9 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
10 @protocol NSObject - (BOOL)isEqual:(id)object; @end
11 @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
12 @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end
13 @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
14 @interface NSObject <NSObject> {} - (id)init; @end
15 extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
16 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
18 + (id)stringWithUTF8String:(const char *)nullTerminatedCString;
19 @end extern NSString * const NSBundleDidLoadNotification;
20 @interface NSAssertionHandler : NSObject {}
21 + (NSAssertionHandler *)currentHandler;
22 - (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...;
23 - (void)handleFailureInFunction:(NSString *)functionName file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...;
25 extern NSString * const NSConnectionReplyMode;
27 //----------------------------------------------------------------------------//
28 // The following test case was filed in PR 2593:
29 // http://llvm.org/bugs/show_bug.cgi?id=2593
31 // There should be no null dereference flagged by the checker because of
32 // NSParameterAssert and NSAssert.
35 @interface TestAssert : NSObject {}
38 @implementation TestAssert
40 - (id)initWithPointer: (int*)x
42 // Expansion of: NSParameterAssert( x != 0 );
43 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);
45 if( (self = [super init]) != 0 )
53 - (id)initWithPointer2: (int*)x
55 // Expansion of: NSAssert( x != 0, @"" );
56 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);
58 if( (self = [super init]) != 0 )
68 void pointerFunction (int *x) {
69 // Manual expansion of NSCAssert( x != 0, @"")
70 do { if (!((x != 0))) { [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] file:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ description:((@""))]; } } while(0);