Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -warn-dead-stores -verify %s |
| 2 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -warn-dead-stores -verify %s |
| 3 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -warn-dead-stores -verify %s |
| 4 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -warn-dead-stores -verify %s |
| 5 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -warn-dead-stores -verify %s |
Mike Stump | 0979d80 | 2009-07-22 22:56:04 +0000 | [diff] [blame] | 6 | |
Ted Kremenek | 43f19e3 | 2009-12-15 04:12:12 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
| 8 | // Basic dead store checking (but in C++ mode). |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
Mike Stump | 0979d80 | 2009-07-22 22:56:04 +0000 | [diff] [blame] | 11 | int j; |
Ted Kremenek | 852274d | 2009-12-16 03:18:58 +0000 | [diff] [blame^] | 12 | void test1() { |
Mike Stump | 0979d80 | 2009-07-22 22:56:04 +0000 | [diff] [blame] | 13 | int x = 4; |
| 14 | |
| 15 | ++x; // expected-warning{{never read}} |
| 16 | |
| 17 | switch (j) { |
| 18 | case 1: |
| 19 | throw 1; |
| 20 | (void)x; |
| 21 | break; |
| 22 | } |
| 23 | } |
Ted Kremenek | 43f19e3 | 2009-12-15 04:12:12 +0000 | [diff] [blame] | 24 | |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | // Dead store checking involving constructors. |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | |
Ted Kremenek | 852274d | 2009-12-16 03:18:58 +0000 | [diff] [blame^] | 29 | class Test2 { |
Ted Kremenek | 43f19e3 | 2009-12-15 04:12:12 +0000 | [diff] [blame] | 30 | int &x; |
| 31 | public: |
Ted Kremenek | 852274d | 2009-12-16 03:18:58 +0000 | [diff] [blame^] | 32 | Test2(int &y) : x(y) {} |
| 33 | ~Test2() { ++x; } |
Ted Kremenek | 43f19e3 | 2009-12-15 04:12:12 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
Ted Kremenek | 852274d | 2009-12-16 03:18:58 +0000 | [diff] [blame^] | 36 | int test2(int x) { |
| 37 | { Test2 a(x); } // no-warning |
Ted Kremenek | 43f19e3 | 2009-12-15 04:12:12 +0000 | [diff] [blame] | 38 | return x; |
| 39 | } |
Ted Kremenek | 852274d | 2009-12-16 03:18:58 +0000 | [diff] [blame^] | 40 | |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | // Test references. |
| 43 | //===----------------------------------------------------------------------===// |
| 44 | |
| 45 | void test3_a(int x) { |
| 46 | ++x; // expected-warning{{never read}} |
| 47 | } |
| 48 | |
| 49 | void test3_b(int &x) { |
| 50 | ++x; // no-warninge |
| 51 | } |
| 52 | |
| 53 | void test3_c(int x) { |
| 54 | int &y = x; |
| 55 | // Shows the limitation of dead stores tracking. The write is really |
| 56 | // dead since the value cannot escape the function. |
| 57 | ++y; // no-warning |
| 58 | } |
| 59 | |
| 60 | void test3_d(int &x) { |
| 61 | int &y = x; |
| 62 | ++y; // no-warning |
| 63 | } |
| 64 | |
| 65 | void test3_e(int &x) { |
| 66 | int &y = x; |
| 67 | } |
| 68 | |