]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Analysis/uninit-vals-ps-region.c
Update clang to r96341.
[FreeBSD/FreeBSD.git] / test / Analysis / uninit-vals-ps-region.c
1 // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s
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;
15   if (global.data == 0) // When the true branch is feasible 'a = 3'.
16     g(a); // no-warning
17 }
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_unit_aux2(int);
24 void test_uninit_pos() {
25   struct TestUninit v1 = { 0, 0 };
26   struct TestUninit v2 = test_uninit_aux();
27   int z;
28   v1.y = z; // expected-warning{{Assigned value is garbage or undefined}}
29   test_unit_aux2(v2.x + v1.y);
30 }
31 void test_uninit_pos_2() {
32   struct TestUninit v1 = { 0, 0 };
33   struct TestUninit v2;
34   test_unit_aux2(v2.x + v1.y);  // expected-warning{{The left operand of '+' is a garbage value}}
35 }
36 void test_uninit_pos_3() {
37   struct TestUninit v1 = { 0, 0 };
38   struct TestUninit v2;
39   test_unit_aux2(v1.y + v2.x);  // expected-warning{{The right operand of '+' is a garbage value}}
40 }
41
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); // no-warning
46 }
47