blob: 180faf8fd72d40692621a0e0e2cff3f7eceba149 [file] [log] [blame]
Ted Kremenek565e4652010-02-05 02:06:54 +00001// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range %s -verify
Ted Kremenekd4e5a602009-08-06 21:43:54 +00002
3//===-- unions-region.m ---------------------------------------------------===//
4//
5// This file tests the analyzer's reasoning about unions.
6//
7//===----------------------------------------------------------------------===//
8
Ted Kremenek566a6fa2009-08-06 22:33:36 +00009// [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'.
Ted Kremenekd4e5a602009-08-06 21:43:54 +000012union u_testA {
13 unsigned i;
14 float f;
15};
16
17float 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
Ted Kremenek566a6fa2009-08-06 22:33:36 +000032// [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'.
35void 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