From: Eli Friedman Date: Thu, 24 Dec 2009 23:33:34 +0000 (+0000) Subject: Make copy constructor elimination work in more cases; the case in question X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb48f8a60ad26b56d299cca9a57f8ea683d8a909;p=clang Make copy constructor elimination work in more cases; the case in question here affects clang-on-clang. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92151 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 7b9ee20aba..b0f23af820 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -590,6 +590,9 @@ CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest, Arg = ICE->getSubExpr(); } + if (const CXXFunctionalCastExpr *FCE = dyn_cast(Arg)) + Arg = FCE->getSubExpr(); + if (const CXXBindTemporaryExpr *BindExpr = dyn_cast(Arg)) Arg = BindExpr->getSubExpr(); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index b70b0dccb7..f29300e4ac 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3793,6 +3793,8 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, if (ImplicitCastExpr *ICE = dyn_cast(E)) if (ICE->getCastKind() == CastExpr::CK_NoOp) E = ICE->getSubExpr(); + if (CXXFunctionalCastExpr *FCE = dyn_cast(E)) + E = FCE->getSubExpr(); while (CXXBindTemporaryExpr *BE = dyn_cast(E)) E = BE->getSubExpr(); if (ImplicitCastExpr *ICE = dyn_cast(E)) @@ -3803,6 +3805,8 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, Elidable = !CE->getCallReturnType()->isReferenceType(); else if (isa(E)) Elidable = true; + else if (isa(E)) + Elidable = true; } return BuildCXXConstructExpr(ConstructLoc, DeclInitType, Constructor, diff --git a/test/CodeGenCXX/copy-constructor-elim-2.cpp b/test/CodeGenCXX/copy-constructor-elim-2.cpp new file mode 100644 index 0000000000..3a06c10ff1 --- /dev/null +++ b/test/CodeGenCXX/copy-constructor-elim-2.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +struct A { int x; A(int); ~A(); }; +A f() { return A(0); } +// CHECK: define void @_Z1fv +// CHECK: call void @_ZN1AC1Ei +// CHECK-NEXT: ret void