nil-receiver-undefined-larger-than-voidptr-ret.m revision da9ae6088b9543134a6561a412b79530e290408d
1// RUN: clang-cc -analyze -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s -verify 2 3@interface MyClass {} 4- (void *)voidPtrM; 5- (int)intM; 6- (long long)longlongM; 7- (double)doubleM; 8- (long double)longDoubleM; 9@end 10@implementation MyClass 11- (void *)voidPtrM { return (void *)0; } 12- (int)intM { return 0; } 13- (long long)longlongM { return 0; } 14- (double)doubleM { return 0.0; } 15- (long double)longDoubleM { return 0.0; } 16@end 17 18void createFoo() { 19 MyClass *obj = 0; 20 21 void *v = [obj voidPtrM]; // no-warning 22 int i = [obj intM]; // no-warning 23} 24 25void createFoo2() { 26 MyClass *obj = 0; 27 28 long double ld = [obj longDoubleM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}} 29} 30 31void createFoo3() { 32 MyClass *obj = 0; 33 34 long long ll = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}} 35} 36 37void createFoo4() { 38 MyClass *obj = 0; 39 40 double d = [obj doubleM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}} 41} 42 43void createFoo5() { 44 MyClass *obj = @""; 45 46 double d = [obj doubleM]; // no-warning 47} 48 49void handleNilPruneLoop(MyClass *obj) { 50 if (!!obj) 51 return; 52 53 // Test if [obj intM] evaluates to 0, thus pruning the entire loop. 54 for (int i = 0; i < [obj intM]; i++) { 55 long long j = [obj longlongM]; // no-warning 56 } 57 58 long long j = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}} 59} 60