diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index 7b9ee20abafa..b0f23af8200b 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/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/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index b70b0dccb75e..f29300e4acb4 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/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/clang/test/CodeGenCXX/copy-constructor-elim-2.cpp b/clang/test/CodeGenCXX/copy-constructor-elim-2.cpp new file mode 100644 index 000000000000..3a06c10ff186 --- /dev/null +++ b/clang/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