Daniel Dunbar | 748dd20 | 2009-04-08 23:02:51 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -triple i386-apple-darwin9 -analyze -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s -verify |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 2 | |
| 3 | @interface MyClass {} |
| 4 | - (void *)voidPtrM; |
| 5 | - (int)intM; |
| 6 | - (long long)longlongM; |
| 7 | - (double)doubleM; |
| 8 | - (long double)longDoubleM; |
Ted Kremenek | fe630b9 | 2009-04-09 05:45:56 +0000 | [diff] [blame^] | 9 | - (void)voidM; |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 10 | @end |
| 11 | @implementation MyClass |
| 12 | - (void *)voidPtrM { return (void *)0; } |
| 13 | - (int)intM { return 0; } |
| 14 | - (long long)longlongM { return 0; } |
| 15 | - (double)doubleM { return 0.0; } |
| 16 | - (long double)longDoubleM { return 0.0; } |
Ted Kremenek | fe630b9 | 2009-04-09 05:45:56 +0000 | [diff] [blame^] | 17 | - (void)voidM {} |
Ted Kremenek | 899b3de | 2009-04-08 03:07:17 +0000 | [diff] [blame] | 18 | @end |
| 19 | |
| 20 | void createFoo() { |
| 21 | MyClass *obj = 0; |
| 22 | |
| 23 | void *v = [obj voidPtrM]; // no-warning |
| 24 | int i = [obj intM]; // no-warning |
| 25 | } |
| 26 | |
| 27 | void createFoo2() { |
| 28 | MyClass *obj = 0; |
| 29 | |
| 30 | long double ld = [obj longDoubleM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}} |
| 31 | } |
| 32 | |
| 33 | void createFoo3() { |
| 34 | MyClass *obj = 0; |
| 35 | |
| 36 | long long ll = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}} |
| 37 | } |
| 38 | |
| 39 | void createFoo4() { |
| 40 | MyClass *obj = 0; |
| 41 | |
| 42 | double d = [obj doubleM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}} |
| 43 | } |
| 44 | |
| 45 | void createFoo5() { |
| 46 | MyClass *obj = @""; |
| 47 | |
| 48 | double d = [obj doubleM]; // no-warning |
| 49 | } |
| 50 | |
Ted Kremenek | da9ae60 | 2009-04-08 18:51:08 +0000 | [diff] [blame] | 51 | void handleNilPruneLoop(MyClass *obj) { |
| 52 | if (!!obj) |
| 53 | return; |
| 54 | |
| 55 | // Test if [obj intM] evaluates to 0, thus pruning the entire loop. |
| 56 | for (int i = 0; i < [obj intM]; i++) { |
| 57 | long long j = [obj longlongM]; // no-warning |
| 58 | } |
| 59 | |
| 60 | long long j = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}} |
| 61 | } |
Ted Kremenek | fe630b9 | 2009-04-09 05:45:56 +0000 | [diff] [blame^] | 62 | |
| 63 | int handleVoidInComma() { |
| 64 | MyClass *obj = 0; |
| 65 | return [obj voidM], 0; |
| 66 | } |