aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-09-02 21:14:47 +0000
committerAnders Carlsson <andersca@mac.com>2009-09-02 21:14:47 +0000
commitc186b8fe4a308b53569fe839a3224de70d92ab0e (patch)
tree40f4eafa4aec4f0d28d2cc88347debef8cd0c22c
parent9ab605acf4a08a795d222c5602fdc595ce70348f (diff)
Fix an assertion when initializing a union using a member initializer. (We weren't casting from the union type to the initializer type correctly).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80837 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGCXX.cpp3
-rw-r--r--test/CodeGenCXX/anonymous-union-member-initializer.cpp12
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index 9e59a0a5a2..c8e3d88e00 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -1658,7 +1658,8 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD) {
else {
// Initializing an anonymous union data member.
FieldDecl *anonMember = Member->getAnonUnionMember();
- LHS = EmitLValueForField(LHS.getAddress(), anonMember, false, 0);
+ LHS = EmitLValueForField(LHS.getAddress(), anonMember,
+ /*IsUnion=*/true, 0);
FieldType = anonMember->getType();
}
}
diff --git a/test/CodeGenCXX/anonymous-union-member-initializer.cpp b/test/CodeGenCXX/anonymous-union-member-initializer.cpp
new file mode 100644
index 0000000000..2030f4053c
--- /dev/null
+++ b/test/CodeGenCXX/anonymous-union-member-initializer.cpp
@@ -0,0 +1,12 @@
+// RUN: clang-cc -emit-llvm -o - %s
+
+struct A {
+ union {
+ int a;
+ void* b;
+ };
+
+ A() : a(0) { }
+};
+
+A a;