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 04da0ee..a36c887 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -338,6 +338,19 @@
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 5a1109d..2a6be90 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 @@
}
};
+
+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);
}