Ted Kremenek | 6c07bdb | 2009-06-26 00:05:51 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -verify %s |
Zhongxing Xu | e8e4d8c | 2008-11-20 00:46:15 +0000 | [diff] [blame] | 2 | |
| 3 | struct s { |
| 4 | int data; |
| 5 | }; |
| 6 | |
| 7 | struct s global; |
| 8 | |
| 9 | void g(int); |
| 10 | |
| 11 | void f4() { |
| 12 | int a; |
| 13 | if (global.data == 0) |
| 14 | a = 3; |
Ted Kremenek | 4226846 | 2008-12-04 02:07:20 +0000 | [diff] [blame] | 15 | if (global.data == 0) // When the true branch is feasible 'a = 3'. |
Zhongxing Xu | e8e4d8c | 2008-11-20 00:46:15 +0000 | [diff] [blame] | 16 | g(a); // no-warning |
| 17 | } |
Ted Kremenek | c761f40 | 2009-08-28 20:25:33 +0000 | [diff] [blame] | 18 | |
| 19 | |
| 20 | // Test uninitialized value due to part of the structure being uninitialized. |
| 21 | struct TestUninit { int x; int y; }; |
| 22 | struct TestUninit test_uninit_aux(); |
| 23 | void test_uninit_pos() { |
| 24 | struct TestUninit v1 = { 0, 0 }; |
| 25 | struct TestUninit v2 = test_uninit_aux(); |
| 26 | int z; |
Ted Kremenek | b107c4b | 2009-11-04 04:24:16 +0000 | [diff] [blame^] | 27 | v1.y = z; // expected-warning{{Assigned value is garbage or undefined}} |
| 28 | test_unit_aux2(v2.x + v1.y); |
Ted Kremenek | c761f40 | 2009-08-28 20:25:33 +0000 | [diff] [blame] | 29 | } |
Ted Kremenek | b107c4b | 2009-11-04 04:24:16 +0000 | [diff] [blame^] | 30 | void test_uninit_pos_2() { |
| 31 | struct TestUninit v1 = { 0, 0 }; |
| 32 | struct TestUninit v2; |
| 33 | test_unit_aux2(v2.x + v1.y); // expected-warning{{The left operand of '+' is a garbage value}} |
| 34 | } |
| 35 | void test_uninit_pos_3() { |
| 36 | struct TestUninit v1 = { 0, 0 }; |
| 37 | struct TestUninit v2; |
| 38 | test_unit_aux2(v1.y + v2.x); // expected-warning{{The right operand of '+' is a garbage value}} |
| 39 | } |
| 40 | |
Ted Kremenek | c761f40 | 2009-08-28 20:25:33 +0000 | [diff] [blame] | 41 | void test_uninit_neg() { |
| 42 | struct TestUninit v1 = { 0, 0 }; |
| 43 | struct TestUninit v2 = test_uninit_aux(); |
| 44 | test_unit_aux2(v2.x + v1.y); // no-warning |
| 45 | } |
| 46 | |