Ted Kremenek | 0187a1b | 2012-09-08 04:26:37 +0000 | [diff] [blame] | 1 | // 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 |
Tim Northover | 931a4fe | 2013-08-12 12:51:05 +0000 | [diff] [blame] | 2 | // RUN: FileCheck -input-file=%t.1 -check-prefix=CHECK-darwin8 %s |
Ted Kremenek | 0187a1b | 2012-09-08 04:26:37 +0000 | [diff] [blame] | 3 | // 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 |
Tim Northover | 931a4fe | 2013-08-12 12:51:05 +0000 | [diff] [blame] | 4 | // RUN: FileCheck -input-file=%t.2 -check-prefix=CHECK-darwin9 %s |
Ted Kremenek | 0187a1b | 2012-09-08 04:26:37 +0000 | [diff] [blame] | 5 | // 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 |
Tim Northover | 931a4fe | 2013-08-12 12:51:05 +0000 | [diff] [blame] | 6 | // RUN: FileCheck -input-file=%t.3 -check-prefix=CHECK-darwin9 %s |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 7 | |
| 8 | @interface MyClass {} |
| 9 | - (void *)voidPtrM; |
| 10 | - (int)intM; |
| 11 | - (long long)longlongM; |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 12 | - (unsigned long long)unsignedLongLongM; |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 13 | - (double)doubleM; |
| 14 | - (long double)longDoubleM; |
Ted Kremenek | fe630b9 | 2009-04-09 05:45:56 +0000 | [diff] [blame] | 15 | - (void)voidM; |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 16 | @end |
| 17 | @implementation MyClass |
| 18 | - (void *)voidPtrM { return (void *)0; } |
| 19 | - (int)intM { return 0; } |
| 20 | - (long long)longlongM { return 0; } |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 21 | - (unsigned long long)unsignedLongLongM { return 0; } |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 22 | - (double)doubleM { return 0.0; } |
| 23 | - (long double)longDoubleM { return 0.0; } |
Ted Kremenek | fe630b9 | 2009-04-09 05:45:56 +0000 | [diff] [blame] | 24 | - (void)voidM {} |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 25 | @end |
| 26 | |
| 27 | void createFoo() { |
| 28 | MyClass *obj = 0; |
| 29 | |
| 30 | void *v = [obj voidPtrM]; // no-warning |
| 31 | int i = [obj intM]; // no-warning |
| 32 | } |
| 33 | |
| 34 | void createFoo2() { |
| 35 | MyClass *obj = 0; |
| 36 | |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 37 | long double ld = [obj longDoubleM]; |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void createFoo3() { |
Ted Kremenek | 0c31317 | 2009-05-13 19:16:35 +0000 | [diff] [blame] | 41 | MyClass *obj; |
| 42 | obj = 0; |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 43 | |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 44 | long long ll = [obj longlongM]; |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void createFoo4() { |
| 48 | MyClass *obj = 0; |
| 49 | |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 50 | double d = [obj doubleM]; |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void createFoo5() { |
Fariborz Jahanian | f64bc20 | 2012-02-23 22:51:36 +0000 | [diff] [blame] | 54 | MyClass *obj = (id)@""; |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 55 | |
| 56 | double d = [obj doubleM]; // no-warning |
| 57 | } |
| 58 | |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 59 | void createFoo6() { |
| 60 | MyClass *obj; |
| 61 | obj = 0; |
| 62 | |
| 63 | unsigned long long ull = [obj unsignedLongLongM]; |
| 64 | } |
| 65 | |
Ted Kremenek | da9ae60 | 2009-04-08 18:51:08 +0000 | [diff] [blame] | 66 | void 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++) { |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 72 | long long j = [obj longlongM]; |
Ted Kremenek | da9ae60 | 2009-04-08 18:51:08 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 75 | long long j = [obj longlongM]; |
Ted Kremenek | da9ae60 | 2009-04-08 18:51:08 +0000 | [diff] [blame] | 76 | } |
Ted Kremenek | fe630b9 | 2009-04-09 05:45:56 +0000 | [diff] [blame] | 77 | |
| 78 | int handleVoidInComma() { |
| 79 | MyClass *obj = 0; |
| 80 | return [obj voidM], 0; |
| 81 | } |
Ted Kremenek | 7e08dca | 2009-11-24 22:56:53 +0000 | [diff] [blame] | 82 | |
| 83 | int marker(void) { // control reaches end of non-void function |
| 84 | } |
| 85 | |
Ted Kremenek | 371b477 | 2012-07-02 20:21:48 +0000 | [diff] [blame] | 86 | // CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage |
Ted Kremenek | c4bac8e | 2012-08-16 17:45:23 +0000 | [diff] [blame] | 87 | // CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage |
| 88 | // CHECK-darwin8: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage |
| 89 | // CHECK-darwin8: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage |
| 90 | // CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage |
Anna Zaks | b990d03 | 2012-03-13 19:32:19 +0000 | [diff] [blame] | 91 | |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 92 | // CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 93 | // CHECK-darwin9-NOT: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage |
Anna Zaks | b990d03 | 2012-03-13 19:32:19 +0000 | [diff] [blame] | 94 | // CHECK-darwin9-NOT: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 95 | // CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage |
Anna Zaks | b990d03 | 2012-03-13 19:32:19 +0000 | [diff] [blame] | 96 | // CHECK-darwin9-NOT: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage |
Chris Lattner | 53eee7b | 2010-04-07 18:47:42 +0000 | [diff] [blame] | 97 | // CHECK-darwin9: 1 warning generated |
Ted Kremenek | 6123874 | 2010-09-30 00:37:10 +0000 | [diff] [blame] | 98 | |