Ted Kremenek | 565e465 | 2010-02-05 02:06:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range %s -verify |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 2 | |
| 3 | //===-- unions-region.m ---------------------------------------------------===// |
| 4 | // |
| 5 | // This file tests the analyzer's reasoning about unions. |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 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'. |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 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 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 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 | |