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