Ted Kremenek | c21fed3 | 2011-01-18 21:18:58 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only %s -verify |
| 2 | |
| 3 | int test1_aux(int &x); |
| 4 | int test1() { |
| 5 | int x; |
| 6 | test1_aux(x); |
| 7 | return x; // no-warning |
| 8 | } |
| 9 | |
| 10 | int test2_aux() { |
| 11 | int x; |
| 12 | int &y = x; |
| 13 | return x; // no-warning |
| 14 | } |
| 15 | |
Ted Kremenek | 2d4bed1 | 2011-01-20 21:25:31 +0000 | [diff] [blame] | 16 | // Handle cases where the CFG may constant fold some branches, thus |
| 17 | // mitigating the need for some path-sensitivity in the analysis. |
| 18 | unsigned test3_aux(); |
| 19 | unsigned test3() { |
| 20 | unsigned x = 0; |
| 21 | const bool flag = true; |
| 22 | if (flag && (x = test3_aux()) == 0) { |
| 23 | return x; |
| 24 | } |
| 25 | return x; |
| 26 | } |
| 27 | unsigned test3_b() { |
| 28 | unsigned x ; |
| 29 | const bool flag = true; |
| 30 | if (flag && (x = test3_aux()) == 0) { |
| 31 | x = 1; |
| 32 | } |
| 33 | return x; // no-warning |
| 34 | } |
| 35 | unsigned test3_c() { |
| 36 | unsigned x ; |
| 37 | const bool flag = false; |
| 38 | if (flag && (x = test3_aux()) == 0) { |
| 39 | x = 1; |
| 40 | } |
| 41 | return x; // expected-warning{{use of uninitialized variable 'x'}} |
| 42 | } |
| 43 | |