[cfe-commits] r88995 - /cfe/trunk/lib/CodeGen/CGCXX.cpp

Eli Friedman eli.friedman at gmail.com
Mon Nov 16 15:34:12 PST 2009


Author: efriedma
Date: Mon Nov 16 17:34:11 2009
New Revision: 88995

URL: http://llvm.org/viewvc/llvm-project?rev=88995&view=rev
Log:
Reorganize EmitMemberInitializer to put anonymous unions on the common codepath.


Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=88995&r1=88994&r2=88995&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Nov 16 17:34:11 2009
@@ -1515,11 +1515,7 @@
   
   // non-static data member initializers.
   FieldDecl *Field = MemberInit->getMember();
-  QualType FieldType = CGF.getContext().getCanonicalType((Field)->getType());
-  const ConstantArrayType *Array =
-    CGF.getContext().getAsConstantArrayType(FieldType);
-  if (Array)
-    FieldType = CGF.getContext().getBaseElementType(FieldType);
+  QualType FieldType = CGF.getContext().getCanonicalType(Field->getType());
 
   llvm::Value *ThisPtr = CGF.LoadCXXThis();
   LValue LHS;
@@ -1532,32 +1528,38 @@
   } else {
     LHS = CGF.EmitLValueForField(ThisPtr, Field, ClassDecl->isUnion(), 0);
   }
+
+  // If we are initializing an anonymous union field, drill down to the field.
+  if (MemberInit->getAnonUnionMember()) {
+    Field = MemberInit->getAnonUnionMember();
+    LHS = CGF.EmitLValueForField(LHS.getAddress(), Field,
+                                 /*IsUnion=*/true, 0);
+    FieldType = Field->getType();
+  }
+
+  // If the field is an array, branch based on the element type.
+  const ConstantArrayType *Array =
+    CGF.getContext().getAsConstantArrayType(FieldType);
+  if (Array)
+    FieldType = CGF.getContext().getBaseElementType(FieldType);
+
   if (FieldType->getAs<RecordType>()) {
-    if (!Field->isAnonymousStructOrUnion()) {
-      assert(MemberInit->getConstructor() &&
-             "EmitCtorPrologue - no constructor to initialize member");
-      if (Array) {
-        const llvm::Type *BasePtr = CGF.ConvertType(FieldType);
-        BasePtr = llvm::PointerType::getUnqual(BasePtr);
-        llvm::Value *BaseAddrPtr =
-          CGF.Builder.CreateBitCast(LHS.getAddress(), BasePtr);
-        CGF.EmitCXXAggrConstructorCall(MemberInit->getConstructor(),
-                                       Array, BaseAddrPtr);
-      }
-      else
-        CGF.EmitCXXConstructorCall(MemberInit->getConstructor(),
-                                   Ctor_Complete, LHS.getAddress(),
-                                   MemberInit->const_arg_begin(),
-                                   MemberInit->const_arg_end());
-      return;
-    }
-    else {
-      // Initializing an anonymous union data member.
-      FieldDecl *anonMember = MemberInit->getAnonUnionMember();
-      LHS = CGF.EmitLValueForField(LHS.getAddress(), anonMember,
-                                   /*IsUnion=*/true, 0);
-      FieldType = anonMember->getType();
+    assert(MemberInit->getConstructor() &&
+           "EmitCtorPrologue - no constructor to initialize member");
+    if (Array) {
+      const llvm::Type *BasePtr = CGF.ConvertType(FieldType);
+      BasePtr = llvm::PointerType::getUnqual(BasePtr);
+      llvm::Value *BaseAddrPtr =
+        CGF.Builder.CreateBitCast(LHS.getAddress(), BasePtr);
+      CGF.EmitCXXAggrConstructorCall(MemberInit->getConstructor(),
+                                     Array, BaseAddrPtr);
     }
+    else
+      CGF.EmitCXXConstructorCall(MemberInit->getConstructor(),
+                                 Ctor_Complete, LHS.getAddress(),
+                                 MemberInit->const_arg_begin(),
+                                 MemberInit->const_arg_end());
+    return;
   }
 
   assert(MemberInit->getNumArgs() == 1 && "Initializer count must be 1 only");





More information about the cfe-commits mailing list