1 // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-store=region -analyzer-constraints=range %s -verify 2 3 //===-- unions-region.m ---------------------------------------------------===// 4 // 5 // This file tests the analyzer's reasoning about unions. 6 // 7 //===----------------------------------------------------------------------===// 8 9 // [testA] When using RegionStore, this test case previously had a 10 // false positive of a 'pass-by-value argument is uninitialized' 11 // warning at the call to 'testA_aux' and 'testA_aux_2'. 12 union u_testA { 13 unsigned i; 14 float f; 15 }; 16 17 float testA(float f) { 18 int testA_aux(unsigned x); 19 int testA_aux_2(union u_testA z); 20 21 union u_testA swap; 22 swap.f = f; 23 24 if (testA_aux(swap.i)) // no-warning 25 swap.i = ((swap.i & 0xffff0000) >> 16) | ((swap.i & 0x0000fffff) << 16); 26 27 testA_aux_2(swap); // no-warning 28 29 return swap.f; 30 } 31 32 // [testB] When using RegionStore, this test case previously had a 33 // false positive of a 'pass-by-value argument is uninitialized' 34 // warning at the call to 'testB_aux'. 35 void testB(int i) { 36 void testB_aux(short z); 37 union { short x[2]; unsigned y; } val; 38 val.y = 10; 39 testB_aux(val.x[1]); // no-warning 40 } 41 42