misc-ps-region-store.m revision d104a09d30ec35cb67931051d5d0c1ff2ee2d697
1// RUN: clang -analyze -checker-cfref --analyzer-store=region --verify -fblocks %s
2
3//---------------------------------------------------------------------------
4// Test case 'checkaccess_union' differs for region store and basic store.
5// The basic store doesn't reason about compound literals, so the code
6// below won't fire an "uninitialized value" warning.
7//---------------------------------------------------------------------------
8
9// PR 2948 (testcase; crash on VisitLValue for union types)
10// http://llvm.org/bugs/show_bug.cgi?id=2948
11
12void checkaccess_union() {
13  int ret = 0, status;
14  if (((((__extension__ (((union {  // expected-warning {{ Branch condition evaluates to an uninitialized value.}}
15    __typeof (status) __in; int __i;}
16    )
17    {
18      .__in = (status)}
19      ).__i))) & 0xff00) >> 8) == 1)
20        ret = 1;
21}
22
23
24// Check our handling of fields being invalidated by function calls.
25struct test2_struct { int x; int y; char* s; };
26void test2_helper(struct test2_struct* p);
27
28char test2() {
29  struct test2_struct s;
30  test2_help(&s);
31  char *p = 0;
32  
33  if (s.x > 1) {
34    if (s.s != 0) {
35      p = "hello";
36    }
37  }
38  
39  if (s.x > 1) {
40    if (s.s != 0) {
41      return *p;
42    }
43  }
44
45  return 'a';
46}
47