From 3c9034cb7ff1d6c1e4ecd1b44c98f553df013c7c Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 15 May 2010 00:13:29 +0000 Subject: Recognize when the named return value optimization applies in a "return" statement and mark the corresponding CXXConstructExpr as elidable. Teach CodeGen that eliding a temporary is different from eliding an object construction. This is just a baby step toward NRVO. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103849 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprCXX.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/CodeGen/CGExprCXX.cpp') diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index 3a2882e24b..22626fc519 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -321,11 +321,13 @@ CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest, return; } // Code gen optimization to eliminate copy constructor and return - // its first argument instead. + // its first argument instead, if in fact that argument is a temporary + // object. if (getContext().getLangOptions().ElideConstructors && E->isElidable()) { - const Expr *Arg = E->getArg(0)->getTemporaryObject(); - EmitAggExpr(Arg, Dest, false); - return; + if (const Expr *Arg = E->getArg(0)->getTemporaryObject()) { + EmitAggExpr(Arg, Dest, false); + return; + } } if (Array) { QualType BaseElementTy = getContext().getBaseElementType(Array); -- cgit v1.2.3