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