[cfe-commits] r78516 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/copy-constructor-synthesis.cpp

Fariborz Jahanian fjahanian at apple.com
Sat Aug 8 16:32:23 PDT 2009


Author: fjahanian
Date: Sat Aug  8 18:32:22 2009
New Revision: 78516

URL: http://llvm.org/viewvc/llvm-project?rev=78516&view=rev
Log:
ir-gen for initialization, in synthesize copy constructor, 
 of base/field which have trivial copy constructor.


Added:
    cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sat Aug  8 18:32:22 2009
@@ -761,27 +761,27 @@
 /// object from SrcValue to DestValue. Copying can be either a bitwise copy
 /// of via a copy constructor call.
 void CodeGenFunction::EmitClassMemberwiseCopy(
-                        llvm::Value *DestValue, llvm::Value *SrcValue,
+                        llvm::Value *Dest, llvm::Value *Src,
                         const CXXRecordDecl *ClassDecl, 
-                        const CXXRecordDecl *BaseClassDecl) {
-  // FIXME. Do bitwise copy of trivial copy constructors.
-  if (BaseClassDecl->hasTrivialCopyConstructor())
+                        const CXXRecordDecl *BaseClassDecl, QualType Ty) {
+  if (ClassDecl) {
+    Dest = AddressCXXOfBaseClass(Dest, ClassDecl, BaseClassDecl);
+    Src = AddressCXXOfBaseClass(Src, ClassDecl, BaseClassDecl) ;
+  }
+  if (BaseClassDecl->hasTrivialCopyConstructor()) {
+    EmitAggregateCopy(Dest, Src, Ty);
     return;
+  }
+  
   if (CXXConstructorDecl *BaseCopyCtor = 
       BaseClassDecl->getCopyConstructor(getContext(), 0)) {
     llvm::Value *Callee = CGM.GetAddrOfCXXConstructor(BaseCopyCtor, 
                                                       Ctor_Complete);
-    
-    llvm::Value *Dest = ClassDecl ?
-      AddressCXXOfBaseClass(DestValue, ClassDecl, BaseClassDecl) : DestValue;
-    
     CallArgList CallArgs;
     // Push the this (Dest) ptr.
     CallArgs.push_back(std::make_pair(RValue::get(Dest),
                                       BaseCopyCtor->getThisType(getContext())));
     
-    llvm::Value *Src = ClassDecl ?
-      AddressCXXOfBaseClass(SrcValue, ClassDecl, BaseClassDecl) : SrcValue;
     // Push the Src ptr.
     CallArgs.push_back(std::make_pair(RValue::get(Src),
                                       BaseCopyCtor->getThisType(getContext())));
@@ -832,7 +832,8 @@
     
     CXXRecordDecl *BaseClassDecl
       = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
-    EmitClassMemberwiseCopy(LoadOfThis, LoadOfSrc, ClassDecl, BaseClassDecl);
+    EmitClassMemberwiseCopy(LoadOfThis, LoadOfSrc, ClassDecl, BaseClassDecl,
+                            Base->getType());
   }
   
   for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
@@ -849,8 +850,9 @@
         = cast<CXXRecordDecl>(FieldClassType->getDecl());
       LValue LHS = EmitLValueForField(LoadOfThis, *Field, false, 0);
       LValue RHS = EmitLValueForField(LoadOfSrc, *Field, false, 0);
+      
       EmitClassMemberwiseCopy(LHS.getAddress(), RHS.getAddress(), 
-                              0 /*ClassDecl*/, FieldClassDecl);
+                              0 /*ClassDecl*/, FieldClassDecl, FieldType);
       continue;
     }
     // FIXME. Do a built-in assignment of scalar data members.

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=78516&r1=78515&r2=78516&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Aug  8 18:32:22 2009
@@ -557,7 +557,8 @@
   
   void EmitClassMemberwiseCopy(llvm::Value *DestValue, llvm::Value *SrcValue,
                                const CXXRecordDecl *ClassDecl, 
-                               const CXXRecordDecl *BaseClassDecl);
+                               const CXXRecordDecl *BaseClassDecl,
+                               QualType Ty);
   
   void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, 
                               llvm::Value *This,

Added: cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis.cpp?rev=78516&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis.cpp Sat Aug  8 18:32:22 2009
@@ -0,0 +1,55 @@
+// RUNX: clang-cc -triple x86_64-apple-darwin -S %s -o %t-64.s &&
+// RUNX: FileCheck -check-prefix LP64 --input-file=%t-64.s %s &&
+// RUN: clang-cc -triple i386-apple-darwin -S %s -o %t-32.s &&
+// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s &&
+// RUN: true
+
+extern "C" int printf(...);
+
+int init = 100;
+
+struct M {
+  int iM;
+  M() : iM(init++) {}
+};
+
+struct N {
+  int iN;
+  N() : iN(200) {}
+  N(N const & arg){this->iN = arg.iN; }
+};
+
+struct P {
+  int iP;
+  P() : iP(init++) {}
+};
+
+
+struct X  : M, N, P { // ...
+	X(){}
+        P p0;
+	void pr() { printf("iM = %d iN = %d, m1.iM = %d\n", iM, iN, m1.iM); 
+                    printf("im = %d p0.iP = %d, p1.iP = %d\n", iP, p0.iP, p1.iP); }
+	M m1;
+        P p1;
+};
+
+int main()
+{
+	X a;
+	X b(a);
+        b.pr();
+	X x;
+	X c(x);
+        c.pr();
+}
+#if 0
+// -m64 does not work due to unrelated llvm bug!
+// CHECK-LP64: .globl  __ZN1XC1ERK1X
+// CHECK-LP64: .weak_definition __ZN1XC1ERK1X
+// CHECK-LP64: __ZN1XC1ERK1X:
+#endif
+
+// CHECK-LP32: .globl  __ZN1XC1ERK1X
+// CHECK-LP32: .weak_definition __ZN1XC1ERK1X
+// CHECK-LP32: __ZN1XC1ERK1X:





More information about the cfe-commits mailing list