From: Fariborz Jahanian Date: Mon, 10 Aug 2009 23:56:17 +0000 (+0000) Subject: Support for anonymous union in ctor's initializer and X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c64e007d9b2f719613f7d79b0b32d2f50da9332;p=clang Support for anonymous union in ctor's initializer and bunch of FIXMEs for their is-gen. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78623 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index e07eae7b20..a068c23835 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -583,7 +583,7 @@ CXXConstructorDecl::setBaseOrMemberInitializers( if (Member->isBaseInitializer()) AllBaseFields[Member->getBaseClass()->getAs()] = Member; else - AllBaseFields[Member->getMember()] = Member; + AllBaseFields[Member->getMember()] = Member; } // Push virtual bases before others. @@ -635,7 +635,23 @@ CXXConstructorDecl::setBaseOrMemberInitializers( // non-static data members. for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), E = ClassDecl->field_end(); Field != E; ++Field) { - if (CXXBaseOrMemberInitializer *Value = AllBaseFields.lookup(*Field)) { + if ((*Field)->isAnonymousStructOrUnion()) { + if (const RecordType *FieldClassType = + Field->getType()->getAs()) { + CXXRecordDecl *FieldClassDecl + = cast(FieldClassType->getDecl()); + for(RecordDecl::field_iterator FA = FieldClassDecl->field_begin(), + EA = FieldClassDecl->field_end(); FA != EA; FA++) { + if (CXXBaseOrMemberInitializer *Value = AllBaseFields.lookup(*FA)) { + AllToInit.push_back(Value); + break; + } + } + } + continue; + } + if (CXXBaseOrMemberInitializer *Value = + AllBaseFields.lookup(*Field)) { AllToInit.push_back(Value); continue; } diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 417dcf748c..18c06cffb6 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -855,7 +855,8 @@ 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()) { CXXRecordDecl *FieldClassDecl = cast(FieldClassType->getDecl()); @@ -904,7 +905,12 @@ 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(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()) { @@ -921,10 +927,7 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD) { assert(Member->getNumArgs() == 1 && "Initializer count must be 1 only"); Expr *RhsExpr = *Member->arg_begin(); llvm::Value *RHS = EmitScalarExpr(RhsExpr, true); - if (LHS.isBitfield()) - EmitStoreThroughBitfieldLValue(RValue::get(RHS), LHS, FieldType, 0); - else - EmitStoreThroughLValue(RValue::get(RHS), LHS, FieldType); + EmitStoreThroughLValue(RValue::get(RHS), LHS, FieldType); } } diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index df9b341ac9..59f44de26a 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -699,6 +699,8 @@ void CodeGenModule::DeferredCopyConstructorToEmit(GlobalDecl CopyCtorDecl) { for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), FieldEnd = ClassDecl->field_end(); Field != FieldEnd; ++Field) { + assert(!(*Field)->isAnonymousStructOrUnion() && + "FIXME. Anonymous union NYI - DeferredCopyConstructorToEmit"); QualType FieldType = Context.getCanonicalType((*Field)->getType()); if (const ArrayType *Array = Context.getAsArrayType(FieldType)) FieldType = Array->getElementType();