1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-checker=core,alpha.core -analyzer-constraints=range -analyzer-store=region -Wno-objc-root-class %s > %t.1 2>&1 2*f4a2713aSLionel Sambuc// RUN: FileCheck -input-file=%t.1 -check-prefix=CHECK-darwin8 %s 3*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-checker=core,alpha.core -analyzer-constraints=range -analyzer-store=region -Wno-objc-root-class %s > %t.2 2>&1 4*f4a2713aSLionel Sambuc// RUN: FileCheck -input-file=%t.2 -check-prefix=CHECK-darwin9 %s 5*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple thumbv6-apple-ios4.0 -analyze -analyzer-checker=core,alpha.core -analyzer-constraints=range -analyzer-store=region -Wno-objc-root-class %s > %t.3 2>&1 6*f4a2713aSLionel Sambuc// RUN: FileCheck -input-file=%t.3 -check-prefix=CHECK-darwin9 %s 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc@interface MyClass {} 9*f4a2713aSLionel Sambuc- (void *)voidPtrM; 10*f4a2713aSLionel Sambuc- (int)intM; 11*f4a2713aSLionel Sambuc- (long long)longlongM; 12*f4a2713aSLionel Sambuc- (unsigned long long)unsignedLongLongM; 13*f4a2713aSLionel Sambuc- (double)doubleM; 14*f4a2713aSLionel Sambuc- (long double)longDoubleM; 15*f4a2713aSLionel Sambuc- (void)voidM; 16*f4a2713aSLionel Sambuc@end 17*f4a2713aSLionel Sambuc@implementation MyClass 18*f4a2713aSLionel Sambuc- (void *)voidPtrM { return (void *)0; } 19*f4a2713aSLionel Sambuc- (int)intM { return 0; } 20*f4a2713aSLionel Sambuc- (long long)longlongM { return 0; } 21*f4a2713aSLionel Sambuc- (unsigned long long)unsignedLongLongM { return 0; } 22*f4a2713aSLionel Sambuc- (double)doubleM { return 0.0; } 23*f4a2713aSLionel Sambuc- (long double)longDoubleM { return 0.0; } 24*f4a2713aSLionel Sambuc- (void)voidM {} 25*f4a2713aSLionel Sambuc@end 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambucvoid createFoo() { 28*f4a2713aSLionel Sambuc MyClass *obj = 0; 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc void *v = [obj voidPtrM]; // no-warning 31*f4a2713aSLionel Sambuc int i = [obj intM]; // no-warning 32*f4a2713aSLionel Sambuc} 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambucvoid createFoo2() { 35*f4a2713aSLionel Sambuc MyClass *obj = 0; 36*f4a2713aSLionel Sambuc 37*f4a2713aSLionel Sambuc long double ld = [obj longDoubleM]; 38*f4a2713aSLionel Sambuc} 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambucvoid createFoo3() { 41*f4a2713aSLionel Sambuc MyClass *obj; 42*f4a2713aSLionel Sambuc obj = 0; 43*f4a2713aSLionel Sambuc 44*f4a2713aSLionel Sambuc long long ll = [obj longlongM]; 45*f4a2713aSLionel Sambuc} 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambucvoid createFoo4() { 48*f4a2713aSLionel Sambuc MyClass *obj = 0; 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambuc double d = [obj doubleM]; 51*f4a2713aSLionel Sambuc} 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambucvoid createFoo5() { 54*f4a2713aSLionel Sambuc MyClass *obj = (id)@""; 55*f4a2713aSLionel Sambuc 56*f4a2713aSLionel Sambuc double d = [obj doubleM]; // no-warning 57*f4a2713aSLionel Sambuc} 58*f4a2713aSLionel Sambuc 59*f4a2713aSLionel Sambucvoid createFoo6() { 60*f4a2713aSLionel Sambuc MyClass *obj; 61*f4a2713aSLionel Sambuc obj = 0; 62*f4a2713aSLionel Sambuc 63*f4a2713aSLionel Sambuc unsigned long long ull = [obj unsignedLongLongM]; 64*f4a2713aSLionel Sambuc} 65*f4a2713aSLionel Sambuc 66*f4a2713aSLionel Sambucvoid handleNilPruneLoop(MyClass *obj) { 67*f4a2713aSLionel Sambuc if (!!obj) 68*f4a2713aSLionel Sambuc return; 69*f4a2713aSLionel Sambuc 70*f4a2713aSLionel Sambuc // Test if [obj intM] evaluates to 0, thus pruning the entire loop. 71*f4a2713aSLionel Sambuc for (int i = 0; i < [obj intM]; i++) { 72*f4a2713aSLionel Sambuc long long j = [obj longlongM]; 73*f4a2713aSLionel Sambuc } 74*f4a2713aSLionel Sambuc 75*f4a2713aSLionel Sambuc long long j = [obj longlongM]; 76*f4a2713aSLionel Sambuc} 77*f4a2713aSLionel Sambuc 78*f4a2713aSLionel Sambucint handleVoidInComma() { 79*f4a2713aSLionel Sambuc MyClass *obj = 0; 80*f4a2713aSLionel Sambuc return [obj voidM], 0; 81*f4a2713aSLionel Sambuc} 82*f4a2713aSLionel Sambuc 83*f4a2713aSLionel Sambucint marker(void) { // control reaches end of non-void function 84*f4a2713aSLionel Sambuc} 85*f4a2713aSLionel Sambuc 86*f4a2713aSLionel Sambuc// CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage 87*f4a2713aSLionel Sambuc// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage 88*f4a2713aSLionel Sambuc// CHECK-darwin8: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage 89*f4a2713aSLionel Sambuc// CHECK-darwin8: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage 90*f4a2713aSLionel Sambuc// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage 91*f4a2713aSLionel Sambuc 92*f4a2713aSLionel Sambuc// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage 93*f4a2713aSLionel Sambuc// CHECK-darwin9-NOT: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage 94*f4a2713aSLionel Sambuc// CHECK-darwin9-NOT: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage 95*f4a2713aSLionel Sambuc// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage 96*f4a2713aSLionel Sambuc// CHECK-darwin9-NOT: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage 97*f4a2713aSLionel Sambuc// CHECK-darwin9: 1 warning generated 98*f4a2713aSLionel Sambuc 99