diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-14 20:11:43 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-14 20:11:43 +0000 |
commit | 343a3cf57ee950b024bade8b6b0a2b51663f43cd (patch) | |
tree | 26b5ac85a0253f8fd0a24590d63de7d4a9a7e035 | |
parent | f1480eee38b59d15438fb7bc50865ac7c7e22403 (diff) |
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
-rw-r--r-- | lib/CodeGen/CGCXX.cpp | 13 | ||||
-rw-r--r-- | test/CodeGenCXX/copy-constructor-elim.cpp | 15 |
2 files changed, 27 insertions, 1 deletions
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<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); 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); } |