blob: b17a51a673cbea1bc3b9d73ec8cbe0710b776708 [file] [log] [blame]
Ted Kremenek17a61db2008-07-24 18:47:16 +00001// RUN: clang -checker-cfref -verify %s
2
3typedef struct objc_selector *SEL;
4typedef signed char BOOL;
5typedef int NSInteger;
6typedef unsigned int NSUInteger;
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 NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end
12@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
13@interface NSObject <NSObject> {} - (id)init; @end
14extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
15@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
16- (NSUInteger)length;
17+ (id)stringWithUTF8String:(const char *)nullTerminatedCString;
18@end extern NSString * const NSBundleDidLoadNotification;
19@interface NSAssertionHandler : NSObject {}
20+ (NSAssertionHandler *)currentHandler;
21- (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...;
22@end
23extern NSString * const NSConnectionReplyMode;
24
25//----------------------------------------------------------------------------//
26// The following test case was filed in PR 2593:
27// http://llvm.org/bugs/show_bug.cgi?id=2593
28//
29// There should be no null dereference flagged by the checker because of
30// NSParameterAssert and NSAssert.
31
32
33@interface TestAssert : NSObject {}
34@end
35
36@implementation TestAssert
37
38- (id)initWithPointer: (int*)x
39{
40 // Expansion of: NSParameterAssert( x != 0 );
41 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);
42
43 if( (self = [super init]) != 0 )
44 {
45 *x = 1; // no-warning
46 }
47
48 return self;
49}
50
51- (id)initWithPointer2: (int*)x
52{
53 // Expansion of: NSAssert( x != 0, @"" );
54 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);
55
56 if( (self = [super init]) != 0 )
57 {
58 *x = 1; // no-warning
59 }
60
61 return self;
62}
63
64@end