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