1 // RUN: %clang_analyze_cc1 -analyzer-store=region -analyzer-checker=core -verify %s
15 if (global.data == 0) // When the true branch is feasible 'a = 3'.
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_unit_aux2(int);
24 void test_uninit_pos() {
25 struct TestUninit v1 = { 0, 0 };
26 struct TestUninit v2 = test_uninit_aux();
28 v1.y = z; // expected-warning{{Assigned value is garbage or undefined}}
29 test_unit_aux2(v2.x + v1.y);
31 void test_uninit_pos_2() {
32 struct TestUninit v1 = { 0, 0 };
34 test_unit_aux2(v2.x + v1.y); // expected-warning{{The left operand of '+' is a garbage value}}
36 void test_uninit_pos_3() {
37 struct TestUninit v1 = { 0, 0 };
39 test_unit_aux2(v1.y + v2.x); // expected-warning{{The right operand of '+' is a garbage value}}
42 void test_uninit_neg() {
43 struct TestUninit v1 = { 0, 0 };
44 struct TestUninit v2 = test_uninit_aux();
45 test_unit_aux2(v2.x + v1.y);
48 extern void test_uninit_struct_arg_aux(struct TestUninit arg);
49 void test_uninit_struct_arg() {
51 test_uninit_struct_arg_aux(x); // expected-warning{{Passed-by-value struct argument contains uninitialized data (e.g., field: 'x')}}
55 - (void) passVal:(struct TestUninit)arg;
57 void testFoo(Foo *o) {
59 [o passVal:x]; // expected-warning{{Passed-by-value struct argument contains uninitialized data (e.g., field: 'x')}}
62 // Test case from <rdar://problem/7780304>. That shows an uninitialized value
63 // being used in the LHS of a compound assignment.
65 typedef struct s_r7780304 { int x; } s_r7780304;
67 b.x |= 1; // expected-warning{{The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage}}
71 // The flip side of PR10163 -- float arrays that are actually uninitialized
72 // (The main test is in uninit-vals.m)
73 void test_PR10163(float);
76 test_PR10163(x[1]); // expected-warning{{uninitialized value}}
83 void swap(struct MyStr *To, struct MyStr *From) {
84 // This is not really a swap but close enough for our test.
86 To->y = From->y; // no warning
88 int test_undefined_member_assignment_in_swap(struct MyStr *s2) {
92 return s2->y; // expected-warning{{Undefined or garbage value returned to caller}}