Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Douglas Gregor | caaf29a | 2008-12-10 23:01:14 +0000 | [diff] [blame] | 2 | // rdar://6425550 |
| 3 | int bar(); |
| 4 | void do_something(int); |
Douglas Gregor | 9c4b838 | 2009-11-05 17:49:26 +0000 | [diff] [blame] | 5 | int *get_ptr(); |
Douglas Gregor | caaf29a | 2008-12-10 23:01:14 +0000 | [diff] [blame] | 6 | |
| 7 | int foo() { |
| 8 | if (int X = bar()) { |
| 9 | return X; |
| 10 | } else { |
| 11 | do_something(X); // expected-warning{{'X' is always zero in this context}} |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 12 | return 0; |
Douglas Gregor | caaf29a | 2008-12-10 23:01:14 +0000 | [diff] [blame] | 13 | } |
| 14 | } |
| 15 | |
| 16 | bool foo2() { |
| 17 | if (bool B = bar()) { |
| 18 | if (int Y = bar()) { |
| 19 | return B; |
| 20 | } else { |
| 21 | do_something(Y); // expected-warning{{'Y' is always zero in this context}} |
| 22 | return B; |
| 23 | } |
| 24 | } else { |
| 25 | if (bool B2 = B) { // expected-warning{{'B' is always false in this context}} |
| 26 | do_something(B); // expected-warning{{'B' is always false in this context}} |
| 27 | } else if (B2) { // expected-warning{{'B2' is always false in this context}} |
| 28 | do_something(B); // expected-warning{{'B' is always false in this context}} |
Douglas Gregor | 9c4b838 | 2009-11-05 17:49:26 +0000 | [diff] [blame] | 29 | do_something(B2); // expected-warning{{'B2' is always false in this context}} |
Douglas Gregor | caaf29a | 2008-12-10 23:01:14 +0000 | [diff] [blame] | 30 | } |
| 31 | return B; // expected-warning{{'B' is always false in this context}} |
| 32 | } |
| 33 | } |
Douglas Gregor | 9c4b838 | 2009-11-05 17:49:26 +0000 | [diff] [blame] | 34 | |
| 35 | void foo3() { |
| 36 | if (int *P1 = get_ptr()) |
| 37 | do_something(*P1); |
| 38 | else if (int *P2 = get_ptr()) { |
| 39 | do_something(*P1); // expected-warning{{'P1' is always NULL in this context}} |
| 40 | do_something(*P2); |
| 41 | } else { |
| 42 | do_something(*P1); // expected-warning{{'P1' is always NULL in this context}} |
| 43 | do_something(*P2); // expected-warning{{'P2' is always NULL in this context}} |
| 44 | } |
| 45 | } |