aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGCXX.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-08-11 18:49:54 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-08-11 18:49:54 +0000
commite64941280877d065a27e8cefd2a9038256d0e3ac (patch)
treeeb1f5ece8bd53df7f0ac1d689f4e7a21debd6c59 /lib/CodeGen/CGCXX.cpp
parentb2fedb46056accb808d42c1754031b9bfa6aa69b (diff)
ir-gen support for anonymous union data member
copying in copy constructors and used in default constructor's initializer list. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78700 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r--lib/CodeGen/CGCXX.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index aff85fa5d4..e9ebf230d6 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -874,8 +874,7 @@ void CodeGenFunction::SynthesizeCXXCopyConstructor(const CXXConstructorDecl *CD,
// FIXME. How about copying arrays!
assert(!getContext().getAsArrayType(FieldType) &&
"FIXME. Copying arrays NYI");
- assert(!Field->isAnonymousStructOrUnion() &&
- "FIXME. anonymous data member NYI in copy constructor synthesis");
+
if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) {
CXXRecordDecl *FieldClassDecl
= cast<CXXRecordDecl>(FieldClassType->getDecl());
@@ -924,23 +923,25 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD) {
QualType FieldType = getContext().getCanonicalType((Field)->getType());
assert(!getContext().getAsArrayType(FieldType)
&& "FIXME. Field arrays initialization unsupported");
- DeclContext *Ctx = Field->getDeclContext();
- RecordDecl *Record = cast<RecordDecl>(Ctx);
- assert(!Record->isAnonymousStructOrUnion() &&
- "FIXME. anonymous union initializer NYI in default constructor");
- (void)Record;
LoadOfThis = LoadCXXThis();
LValue LHS = EmitLValueForField(LoadOfThis, Field, false, 0);
if (FieldType->getAs<RecordType>()) {
-
+ if (!Field->isAnonymousStructOrUnion()) {
assert(Member->getConstructor() &&
"EmitCtorPrologue - no constructor to initialize member");
EmitCXXConstructorCall(Member->getConstructor(),
Ctor_Complete, LHS.getAddress(),
Member->const_arg_begin(),
Member->const_arg_end());
- continue;
+ continue;
+ }
+ else {
+ // Initializing an anonymous union data member.
+ FieldDecl *anonMember = Member->getAnonUnionMember();
+ LHS = EmitLValueForField(LHS.getAddress(), anonMember, false, 0);
+ FieldType = anonMember->getType();
+ }
}
assert(Member->getNumArgs() == 1 && "Initializer count must be 1 only");