1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,osx.cocoa.NonNilReturnValue,debug.ExprInspection -analyzer-store=region -verify %s 2 3 void clang_analyzer_eval(int); 4 5 typedef signed char BOOL; 6 typedef long NSInteger; 7 typedef unsigned long NSUInteger; 8 @interface NSString @end 9 @interface NSString (NSStringExtensionMethods) 10 + (id)stringWithUTF8String:(const char *)nullTerminatedCString; 11 @end 12 13 @interface NSNumber 14 + (NSNumber *)numberWithChar:(char)value; 15 + (NSNumber *)numberWithUnsignedChar:(unsigned char)value; 16 + (NSNumber *)numberWithShort:(short)value; 17 + (NSNumber *)numberWithUnsignedShort:(unsigned short)value; 18 + (NSNumber *)numberWithInt:(int)value; 19 + (NSNumber *)numberWithUnsignedInt:(unsigned int)value; 20 + (NSNumber *)numberWithLong:(long)value; 21 + (NSNumber *)numberWithUnsignedLong:(unsigned long)value; 22 + (NSNumber *)numberWithLongLong:(long long)value; 23 + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; 24 + (NSNumber *)numberWithFloat:(float)value; 25 + (NSNumber *)numberWithDouble:(double)value; 26 + (NSNumber *)numberWithBool:(BOOL)value; 27 + (NSNumber *)numberWithInteger:(NSInteger)value ; 28 + (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ; 29 @end 30 31 32 extern char *strdup(const char *str); 33 34 id constant_string() { 35 return @("boxed constant string."); 36 } 37 38 id dynamic_string() { 39 return @(strdup("boxed dynamic string")); // expected-warning{{Potential memory leak}} 40 } 41 42 id const_char_pointer(int *x) { 43 if (x) 44 return @(3); 45 return @(*x); // expected-warning {{Dereference of null pointer (loaded from variable 'x')}} 46 } 47 48 void checkNonNil() { 49 clang_analyzer_eval(!!@3); // expected-warning{{TRUE}} 50 clang_analyzer_eval(!!@(3+4)); // expected-warning{{TRUE}} 51 clang_analyzer_eval(!!@(57.0)); // expected-warning{{TRUE}} 52 53 const char *str = "abc"; 54 clang_analyzer_eval(!!@(str)); // expected-warning{{TRUE}} 55 clang_analyzer_eval(!!@__objc_yes); // expected-warning{{TRUE}} 56 } 57 58