Ted Kremenek | 565e465 | 2010-02-05 02:06:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -verify %s -analyzer-constraints=basic -analyzer-store=basic |
| 2 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -verify %s -analyzer-constraints=range -analyzer-store=basic |
| 3 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -verify %s -analyzer-constraints=basic -analyzer-store=region |
| 4 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -verify %s -analyzer-constraints=range -analyzer-store=region |
Ted Kremenek | 17a61db | 2008-07-24 18:47:16 +0000 | [diff] [blame] | 5 | |
| 6 | typedef struct objc_selector *SEL; |
| 7 | typedef signed char BOOL; |
| 8 | typedef int NSInteger; |
| 9 | typedef unsigned int NSUInteger; |
| 10 | typedef 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 |
| 17 | extern 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 |
| 26 | extern 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 |