1 // RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core,unix.Malloc,debug.ExprInspection %s -analyzer-config eagerly-assume=false -verify
3 extern void clang_analyzer_eval(bool);
4 extern void clang_analyzer_warnIfReached();
5 extern "C" char *strdup(const char *s
);
7 namespace PR14054_reduced
{
15 struct Definition
: public ParseNode
{ };
17 void CloneParseTree(ParseNode
*opn
, ParseNode
*pn
, ParseNode
*x
) {
18 // This used to cause an assertion failure because:
19 // 1. The implicit operator= for unions assigns all members of the union,
20 // not just the active one (b/c there's no way to know which is active).
21 // 2. RegionStore dutifully stored all the variants at the same offset;
23 // 3. We asked for the value of the first variant but got back a conjured
24 // symbol for the second variant.
25 // 4. We ended up trying to add a base cast to a region of the wrong type.
27 // Now (at the time this test was added), we instead treat all variants of
28 // a union as different offsets, but only allow one to be active at a time.
30 x
= pn
->pn_u
.lexdef
->pn_u
.lexdef
;
34 namespace PR14054_original
{
39 union {}; // expected-warning {{does not declare anything}}
48 struct Definition
: public ParseNode
{ };
50 void CloneParseTree(ParseNode
*opn
, ParseNode
*pn
, ParseNode
*x
) {
52 x
= pn
->pn_u
.name
.lexdef
->pn_u
.name
.lexdef
;
62 extern void process(IntOrString
);
73 } // expected-warning{{leak}}
78 clang_analyzer_eval(uu
.i
== 4); // expected-warning{{TRUE}}
83 clang_analyzer_eval(uu
.i
== 5); // expected-warning{{TRUE}}
86 void testInvalidation() {
95 } // expected-warning{{leak}}
97 void testIndirectInvalidation() {
102 clang_analyzer_eval(uu
.s
[0] == 'a'); // expected-warning{{TRUE}}
105 clang_analyzer_eval(uu
.s
[0] == 'a'); // expected-warning{{UNKNOWN}}
109 namespace assume_union_contents
{
122 y
= 1 / y
; // no-warning
124 } // end namespace assume_union_contents
126 namespace pr37688_deleted_union_destructor
{
141 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
143 } // end namespace pr37688_deleted_union_destructor