[cfe-commits] r79034 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/copy-constructor-elim.cpp
Fariborz Jahanian
fjahanian at apple.com
Fri Aug 14 13:11:43 PDT 2009
Author: fjahanian
Date: Fri Aug 14 15:11:43 2009
New Revision: 79034
URL: http://llvm.org/viewvc/llvm-project?rev=79034&view=rev
Log:
ir-gen for generation of trvial copy constructor
call.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/test/CodeGenCXX/copy-constructor-elim.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=79034&r1=79033&r2=79034&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Aug 14 15:11:43 2009
@@ -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);
Modified: cfe/trunk/test/CodeGenCXX/copy-constructor-elim.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/copy-constructor-elim.cpp?rev=79034&r1=79033&r2=79034&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/copy-constructor-elim.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/copy-constructor-elim.cpp Fri Aug 14 15:11:43 2009
@@ -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);
}
More information about the cfe-commits
mailing list