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