brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 2237b56 Raw
74 lines · plain
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount,alpha.core -verify %s2// expected-no-diagnostics3 4typedef struct objc_selector *SEL;5typedef signed char BOOL;6typedef int NSInteger;7typedef unsigned int NSUInteger;8typedef struct _NSZone NSZone;9@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;10@protocol NSObject  - (BOOL)isEqual:(id)object; @end11@protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end12@protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone; @end13@protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end14@interface NSObject <NSObject> {} - (id)init; @end15extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);16@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>17- (NSUInteger)length;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,...;24@end25extern NSString * const NSConnectionReplyMode;26 27//----------------------------------------------------------------------------//28// The following test case was filed in PR 2593:29//   http://llvm.org/bugs/show_bug.cgi?id=259330//31// There should be no null dereference flagged by the checker because of32// NSParameterAssert and NSAssert.33 34 35@interface TestAssert : NSObject {}36@end37 38@implementation TestAssert39 40- (id)initWithPointer: (int*)x41{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);44 45  if( (self = [super init]) != 0 )46  {47    *x = 1; // no-warning48  }49 50  return self;51}52 53- (id)initWithPointer2: (int*)x54{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);  57 58  if( (self = [super init]) != 0 )59  {60    *x = 1; // no-warning61  }62 63  return self;64}65 66@end67 68void 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);  71 72  *x = 1; // no-warning73}74