aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/unions.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-10-10 23:23:21 +0000
committerJordan Rose <jordan_rose@apple.com>2012-10-10 23:23:21 +0000
commit786e6204e55cc01094a3e86104c82932a65fb2ca (patch)
tree24744df20b5da3d7be27ef37c696d0d30253cfba /test/Analysis/unions.cpp
parent3ea19c8307932655092235b57f04a5e6658bbc46 (diff)
Reapply "[analyzer] Treat fields of unions as having symbolic offsets."
This time, actually uncomment the code that's supposed to fix the problem. This reverts r165671 / 8ceb837585ed973dc36fba8dfc57ef60fc8f2735. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165676 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/unions.cpp')
-rw-r--r--test/Analysis/unions.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/Analysis/unions.cpp b/test/Analysis/unions.cpp
new file mode 100644
index 0000000000..e7671a90b9
--- /dev/null
+++ b/test/Analysis/unions.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core %s -verify
+
+namespace PR14054_reduced {
+ struct Definition;
+ struct ParseNode {
+ union {
+ Definition *lexdef;
+ ParseNode *data;
+ } pn_u;
+ };
+ struct Definition : public ParseNode { };
+
+ void CloneParseTree(ParseNode *opn, ParseNode *pn, ParseNode *x) {
+ // This used to cause an assertion failure because:
+ // 1. The implicit operator= for unions assigns all members of the union,
+ // not just the active one (b/c there's no way to know which is active).
+ // 2. RegionStore dutifully stored all the variants at the same offset;
+ // the last one won.
+ // 3. We asked for the value of the first variant but got back a conjured
+ // symbol for the second variant.
+ // 4. We ended up trying to add a base cast to a region of the wrong type.
+ //
+ // Now (at the time this test was added), we instead treat all variants of
+ // a union as different offsets, but only allow one to be active at a time.
+ *pn = *opn;
+ x = pn->pn_u.lexdef->pn_u.lexdef;
+ }
+}
+
+namespace PR14054_original {
+ struct Definition;
+ struct ParseNode {
+ union {
+ struct {
+ union {};
+ Definition *lexdef;
+ } name;
+ class {
+ int *target;
+ ParseNode *data;
+ } xmlpi;
+ } pn_u;
+ };
+ struct Definition : public ParseNode { };
+
+ void CloneParseTree(ParseNode *opn, ParseNode *pn, ParseNode *x) {
+ pn->pn_u = opn->pn_u;
+ x = pn->pn_u.name.lexdef->pn_u.name.lexdef;
+ }
+}