From: Fariborz Jahanian Date: Fri, 14 Aug 2009 20:11:43 +0000 (+0000) Subject: ir-gen for generation of trvial copy constructor X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=343a3cf57ee950b024bade8b6b0a2b51663f43cd;p=clang ir-gen for generation of trvial copy constructor call. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79034 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 04da0ee175..a36c887eaa 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -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(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); diff --git a/test/CodeGenCXX/copy-constructor-elim.cpp b/test/CodeGenCXX/copy-constructor-elim.cpp index 5a1109d7f7..2a6be90bc6 100644 --- a/test/CodeGenCXX/copy-constructor-elim.cpp +++ b/test/CodeGenCXX/copy-constructor-elim.cpp @@ -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); }