99 lines · plain
1// RUN: %clang_analyze_cc1 -Wno-error=return-type -triple i386-apple-darwin8 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.1 2>&12// RUN: FileCheck -input-file=%t.1 -check-prefix=CHECK-darwin8 %s3// RUN: %clang_analyze_cc1 -Wno-error=return-type -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.2 2>&14// RUN: FileCheck -input-file=%t.2 -check-prefix=CHECK-darwin9 %s5// RUN: %clang_analyze_cc1 -Wno-error=return-type -triple thumbv6-apple-ios4.0 -analyzer-checker=core,alpha.core -Wno-objc-root-class %s > %t.3 2>&16// RUN: FileCheck -input-file=%t.3 -check-prefix=CHECK-darwin9 %s7 8@interface MyClass {}9- (void *)voidPtrM;10- (int)intM;11- (long long)longlongM;12- (unsigned long long)unsignedLongLongM;13- (double)doubleM;14- (long double)longDoubleM;15- (void)voidM;16@end17@implementation MyClass18- (void *)voidPtrM { return (void *)0; }19- (int)intM { return 0; }20- (long long)longlongM { return 0; }21- (unsigned long long)unsignedLongLongM { return 0; }22- (double)doubleM { return 0.0; }23- (long double)longDoubleM { return 0.0; }24- (void)voidM {}25@end26 27void createFoo(void) {28 MyClass *obj = 0; 29 30 void *v = [obj voidPtrM]; // no-warning31 int i = [obj intM]; // no-warning32}33 34void createFoo2(void) {35 MyClass *obj = 0; 36 37 long double ld = [obj longDoubleM];38}39 40void createFoo3(void) {41 MyClass *obj;42 obj = 0; 43 44 long long ll = [obj longlongM];45}46 47void createFoo4(void) {48 MyClass *obj = 0; 49 50 double d = [obj doubleM];51}52 53void createFoo5(void) {54 MyClass *obj = (id)@""; 55 56 double d = [obj doubleM]; // no-warning57}58 59void createFoo6(void) {60 MyClass *obj;61 obj = 0; 62 63 unsigned long long ull = [obj unsignedLongLongM];64}65 66void handleNilPruneLoop(MyClass *obj) {67 if (!!obj)68 return;69 70 // Test if [obj intM] evaluates to 0, thus pruning the entire loop.71 for (int i = 0; i < [obj intM]; i++) {72 long long j = [obj longlongM];73 }74 75 long long j = [obj longlongM];76}77 78int handleVoidInComma(void) {79 MyClass *obj = 0;80 return [obj voidM], 0;81}82 83int marker(void) { // non-void function does not return a value84}85 86// CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage87// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage88// CHECK-darwin8: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage89// CHECK-darwin8: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage90// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage91 92// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage93// CHECK-darwin9-NOT: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage94// CHECK-darwin9-NOT: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage95// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage96// CHECK-darwin9-NOT: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage97// CHECK-darwin9: 1 warning generated98 99