]> granicus.if.org Git - clang/commitdiff
ir-gen for generation of trvial copy constructor
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 14 Aug 2009 20:11:43 +0000 (20:11 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 14 Aug 2009 20:11:43 +0000 (20:11 +0000)
call.

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

lib/CodeGen/CGCXX.cpp
test/CodeGenCXX/copy-constructor-elim.cpp

index 04da0ee1751bb933d93d4987989a8102f518bfb8..a36c887eaadf4f3c4efcd1b41d41eb9e4331b174 100644 (file)
@@ -338,6 +338,19 @@ CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
                                         llvm::Value *This,
                                         CallExpr::const_arg_iterator ArgBeg,
                                         CallExpr::const_arg_iterator ArgEnd) {
+  if (D->isCopyConstructor(getContext())) {
+    const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(D->getDeclContext());
+    if (ClassDecl->hasTrivialCopyConstructor()) {
+      assert(!ClassDecl->hasUserDeclaredCopyConstructor() &&
+             "EmitCXXConstructorCall - user declared copy constructor");
+      const Expr *E = (*ArgBeg);
+      QualType Ty = E->getType();
+      llvm::Value *Src = EmitLValue(E).getAddress();
+      EmitAggregateCopy(This, Src, Ty);
+      return;
+    }
+  }
+  
   llvm::Value *Callee = CGM.GetAddrOfCXXConstructor(D, Type);
 
   EmitCXXMemberCall(D, Callee, This, ArgBeg, ArgEnd);
index 5a1109d7f7532d87d12e92ff6d2c5a3588d25ce2..2a6be90bc6b82b06b5fd7d6e94d4bbd952045555 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: clang-cc -emit-llvm -o %t %s &&
-// RUN: grep "_ZN1CC1ERK1C" %t | count 0
+// RUN: grep "_ZN1CC1ERK1C" %t | count 0 &&
+// RUN: grep "_ZN1SC1ERK1S" %t | count 0 &&
+// RUN: true
 
 extern "C" int printf(...);
 
@@ -22,10 +24,21 @@ public:
        }
 };
 
+
+struct S {
+  S();
+};
+
+S::S() { printf("S()\n"); }
+
+void Call(S) {};
+
 int main()
 {
        X a(1);
        X b(a, 2);
        X c = b;
        X d(a, 5, 6);
+        S s;
+        Call(s);
 }