Simplify EmitClassAggrMemberwiseCopy.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102848 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp
index b4a5cba..38b2a67 100644
--- a/lib/CodeGen/CGClass.cpp
+++ b/lib/CodeGen/CGClass.cpp
@@ -407,13 +407,8 @@
 //  FIXME. Consolidate this with EmitCXXAggrConstructorCall.
 void CodeGenFunction::EmitClassAggrMemberwiseCopy(llvm::Value *Dest,
                                             llvm::Value *Src,
-                                            const ArrayType *Array,
-                                            const CXXRecordDecl *BaseClassDecl,
-                                            QualType Ty) {
-  const ConstantArrayType *CA = dyn_cast<ConstantArrayType>(Array);
-  assert(CA && "VLA cannot be copied over");
-  bool BitwiseCopy = BaseClassDecl->hasTrivialCopyConstructor();
-
+                                            const ConstantArrayType *Array,
+                                            const CXXRecordDecl *ClassDecl) {
   // Create a temporary for the loop index and initialize it with 0.
   llvm::Value *IndexPtr = CreateTempAlloca(llvm::Type::getInt64Ty(VMContext),
                                            "loop.index");
@@ -429,7 +424,7 @@
   llvm::BasicBlock *ForBody = createBasicBlock("for.body");
   // Generate: if (loop-index < number-of-elements fall to the loop body,
   // otherwise, go to the block after the for-loop.
-  uint64_t NumElements = getContext().getConstantArrayElementCount(CA);
+  uint64_t NumElements = getContext().getConstantArrayElementCount(Array);
   llvm::Value * NumElementsPtr =
     llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), NumElements);
   llvm::Value *Counter = Builder.CreateLoad(IndexPtr);
@@ -444,12 +439,8 @@
   Counter = Builder.CreateLoad(IndexPtr);
   Src = Builder.CreateInBoundsGEP(Src, Counter, "srcaddress");
   Dest = Builder.CreateInBoundsGEP(Dest, Counter, "destaddress");
-  if (BitwiseCopy)
-    EmitAggregateCopy(Dest, Src, Ty);
-  else if (CXXConstructorDecl *BaseCopyCtor =
-           BaseClassDecl->getCopyConstructor(getContext(), 0))
-    EmitCopyCtorCall(*this, BaseCopyCtor, Ctor_Complete, Dest, 0, Src);
-
+  EmitClassMemberwiseCopy(Dest, Src, ClassDecl);
+  
   EmitBlock(ContinueBlock);
 
   // Emit the increment of the loop counter.
@@ -602,9 +593,7 @@
   CXXConstructorDecl *CopyCtor = ClassDecl->getCopyConstructor(getContext(), 0);
   assert(CopyCtor && "Did not have copy ctor!");
 
-  llvm::Value *VTT = GetVTTParameter(*this, GlobalDecl(CopyCtor, 
-                                                       Ctor_Complete));
-  EmitCopyCtorCall(*this, CopyCtor, Ctor_Complete, Dest, VTT, Src);
+  EmitCopyCtorCall(*this, CopyCtor, Ctor_Complete, Dest, 0, Src);
 }
 
 /// EmitClassCopyAssignment - This routine generates code to copy assign a class
@@ -703,7 +692,7 @@
         llvm::Value *SrcBaseAddrPtr =
           Builder.CreateBitCast(RHS.getAddress(), BasePtr);
         EmitClassAggrMemberwiseCopy(DestBaseAddrPtr, SrcBaseAddrPtr, Array,
-                                    FieldClassDecl, FieldType);
+                                    FieldClassDecl);
       }
       else
         EmitClassMemberwiseCopy(LHS.getAddress(), RHS.getAddress(),