blob: e927a92576e2d435b770cf92c46e16d0d344f9b6 [file] [log] [blame]
Ted Kremenek6c07bdb2009-06-26 00:05:51 +00001// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -verify %s
Zhongxing Xue8e4d8c2008-11-20 00:46:15 +00002
3struct s {
4 int data;
5};
6
7struct s global;
8
9void g(int);
10
11void f4() {
12 int a;
13 if (global.data == 0)
14 a = 3;
Ted Kremenek42268462008-12-04 02:07:20 +000015 if (global.data == 0) // When the true branch is feasible 'a = 3'.
Zhongxing Xue8e4d8c2008-11-20 00:46:15 +000016 g(a); // no-warning
17}
Ted Kremenekc761f402009-08-28 20:25:33 +000018
19
20// Test uninitialized value due to part of the structure being uninitialized.
21struct TestUninit { int x; int y; };
22struct TestUninit test_uninit_aux();
23void test_uninit_pos() {
24 struct TestUninit v1 = { 0, 0 };
25 struct TestUninit v2 = test_uninit_aux();
26 int z;
Ted Kremenekb107c4b2009-11-04 04:24:16 +000027 v1.y = z; // expected-warning{{Assigned value is garbage or undefined}}
28 test_unit_aux2(v2.x + v1.y);
Ted Kremenekc761f402009-08-28 20:25:33 +000029}
Ted Kremenekb107c4b2009-11-04 04:24:16 +000030void 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}
35void 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 Kremenekc761f402009-08-28 20:25:33 +000041void 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