]> granicus.if.org Git - clang/commitdiff
Array member construction in prologue of user-declared
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 21 Aug 2009 17:09:38 +0000 (17:09 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 21 Aug 2009 17:09:38 +0000 (17:09 +0000)
constructors.

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

lib/CodeGen/CGCXX.cpp
test/CodeGenCXX/constructor-init.cpp

index 15979be7902903b4cd66cadaf33f3401b873bef0..5bc8b40c63730394973a92bb218935e88cd3fbcc 100644 (file)
@@ -1362,8 +1362,10 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD) {
       // non-static data member initilaizers.
       FieldDecl *Field = Member->getMember();
       QualType FieldType = getContext().getCanonicalType((Field)->getType());
-      assert(!getContext().getAsArrayType(FieldType) 
-             && "FIXME. Field arrays initialization unsupported");
+      const ConstantArrayType *Array = 
+      getContext().getAsConstantArrayType(FieldType);
+      if (Array)
+        FieldType = getContext().getBaseElementType(FieldType);
       
       LoadOfThis = LoadCXXThis();
       LValue LHS = EmitLValueForField(LoadOfThis, Field, false, 0);
@@ -1371,10 +1373,19 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD) {
         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());
+          if (Array) {
+            const llvm::Type *BasePtr = ConvertType(FieldType);
+            BasePtr = llvm::PointerType::getUnqual(BasePtr);
+            llvm::Value *BaseAddrPtr = 
+            Builder.CreateBitCast(LHS.getAddress(), BasePtr);
+            EmitCXXAggrConstructorCall(Member->getConstructor(), 
+                                       Array, BaseAddrPtr);
+          }
+          else
+            EmitCXXConstructorCall(Member->getConstructor(),
+                                   Ctor_Complete, LHS.getAddress(),
+                                   Member->const_arg_begin(), 
+                                   Member->const_arg_end());
           continue;
         }
         else {
index a9d5c289e26c208df15b1261e4c2c63cb411f240..de86d41552b3666c11ad7d43c1bd3851434eabf5 100644 (file)
@@ -46,6 +46,9 @@ struct N : M , P, Q {
             }
   float ld;
   float ff;
+  M arr_m[3];
+  P arr_p[1][3];
+  Q arr_q[2][3][4];
 };
 
 int main() {