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
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index aff85fa..e9ebf23 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -874,8 +874,7 @@
     // 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 @@
       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");