From f27e5a09a0d815b8a4814152954ff87dadfdefc0 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 2 Jun 2009 17:58:47 +0000 Subject: Import Clang, at r72732. --- test/Analysis/CFRetainRelease_NSAssertionHandler.m | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/Analysis/CFRetainRelease_NSAssertionHandler.m (limited to 'test/Analysis/CFRetainRelease_NSAssertionHandler.m') diff --git a/test/Analysis/CFRetainRelease_NSAssertionHandler.m b/test/Analysis/CFRetainRelease_NSAssertionHandler.m new file mode 100644 index 0000000..1ff9507 --- /dev/null +++ b/test/Analysis/CFRetainRelease_NSAssertionHandler.m @@ -0,0 +1,67 @@ +// RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=basic && +// RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=basic && +// RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=region && +// RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=region + +typedef struct objc_selector *SEL; +typedef signed char BOOL; +typedef int NSInteger; +typedef unsigned int NSUInteger; +typedef struct _NSZone NSZone; +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; +@protocol NSObject - (BOOL)isEqual:(id)object; @end +@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end +@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end +@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end +@interface NSObject {} - (id)init; @end +extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); +@interface NSString : NSObject +- (NSUInteger)length; ++ (id)stringWithUTF8String:(const char *)nullTerminatedCString; +@end extern NSString * const NSBundleDidLoadNotification; +@interface NSAssertionHandler : NSObject {} ++ (NSAssertionHandler *)currentHandler; +- (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...; +@end +extern NSString * const NSConnectionReplyMode; + +//----------------------------------------------------------------------------// +// The following test case was filed in PR 2593: +// http://llvm.org/bugs/show_bug.cgi?id=2593 +// +// There should be no null dereference flagged by the checker because of +// NSParameterAssert and NSAssert. + + +@interface TestAssert : NSObject {} +@end + +@implementation TestAssert + +- (id)initWithPointer: (int*)x +{ + // Expansion of: NSParameterAssert( x != 0 ); + 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); + + if( (self = [super init]) != 0 ) + { + *x = 1; // no-warning + } + + return self; +} + +- (id)initWithPointer2: (int*)x +{ + // Expansion of: NSAssert( x != 0, @"" ); + 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); + + if( (self = [super init]) != 0 ) + { + *x = 1; // no-warning + } + + return self; +} + +@end -- cgit v1.1