]> granicus.if.org Git - clang/commitdiff
Support for anonymous union in ctor's initializer and
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 10 Aug 2009 23:56:17 +0000 (23:56 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 10 Aug 2009 23:56:17 +0000 (23:56 +0000)
bunch of FIXMEs for their is-gen.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78623 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclCXX.cpp
lib/CodeGen/CGCXX.cpp
lib/CodeGen/CodeGenModule.cpp

index e07eae7b20a1f7bb1fb972532e2c71bfab5f16fa..a068c2383538422b6ded054dfee89cd7cdce28f7 100644 (file)
@@ -583,7 +583,7 @@ CXXConstructorDecl::setBaseOrMemberInitializers(
     if (Member->isBaseInitializer())
       AllBaseFields[Member->getBaseClass()->getAs<RecordType>()] = 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<RecordType>()) {
+        CXXRecordDecl *FieldClassDecl
+          = cast<CXXRecordDecl>(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;
     }
index 417dcf748c704d3fd96551d18ad6a575546d79b5..18c06cffb68efcb18e6afb12f12a7f49bac4d99c 100644 (file)
@@ -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<RecordType>()) {
       CXXRecordDecl *FieldClassDecl
         = cast<CXXRecordDecl>(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<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>()) {
@@ -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);
     }
   }
 
index df9b341ac9b55795b9002c762779dc48b6e7e7a2..59f44de26adc40d460fce2f5591da76d28a7db6e 100644 (file)
@@ -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();