1786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose// RUN: %clang_cc1 -analyze -analyzer-checker=core %s -verify 28e8fb3be5bd78f0564444eca02b404566a5f3b5dAndy Gibbs// expected-no-diagnostics 3786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose 4786e6204e55cc01094a3e86104c82932a65fb2caJordan Rosenamespace PR14054_reduced { 5786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose struct Definition; 6786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose struct ParseNode { 7786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose union { 8786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose Definition *lexdef; 9786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose ParseNode *data; 10786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose } pn_u; 11786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose }; 12786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose struct Definition : public ParseNode { }; 13786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose 14786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose void CloneParseTree(ParseNode *opn, ParseNode *pn, ParseNode *x) { 15786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // This used to cause an assertion failure because: 16786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // 1. The implicit operator= for unions assigns all members of the union, 17786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // not just the active one (b/c there's no way to know which is active). 18786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // 2. RegionStore dutifully stored all the variants at the same offset; 19786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // the last one won. 20786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // 3. We asked for the value of the first variant but got back a conjured 21786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // symbol for the second variant. 22786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // 4. We ended up trying to add a base cast to a region of the wrong type. 23786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // 24786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // Now (at the time this test was added), we instead treat all variants of 25786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose // a union as different offsets, but only allow one to be active at a time. 26786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose *pn = *opn; 27786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose x = pn->pn_u.lexdef->pn_u.lexdef; 28786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose } 29786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose} 30786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose 31786e6204e55cc01094a3e86104c82932a65fb2caJordan Rosenamespace PR14054_original { 32786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose struct Definition; 33786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose struct ParseNode { 34786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose union { 35786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose struct { 36786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose union {}; 37786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose Definition *lexdef; 38786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose } name; 39786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose class { 40786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose int *target; 41786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose ParseNode *data; 42786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose } xmlpi; 43786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose } pn_u; 44786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose }; 45786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose struct Definition : public ParseNode { }; 46786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose 47786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose void CloneParseTree(ParseNode *opn, ParseNode *pn, ParseNode *x) { 48786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose pn->pn_u = opn->pn_u; 49786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose x = pn->pn_u.name.lexdef->pn_u.name.lexdef; 50786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose } 51786e6204e55cc01094a3e86104c82932a65fb2caJordan Rose} 52