diff options
author | Anders Carlsson <andersca@mac.com> | 2009-11-13 04:34:45 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-11-13 04:34:45 +0000 |
commit | 03d8ed439f55b692634f9c71721ecfabbe347c4d (patch) | |
tree | e91e74e5eaf2fe94a3497442f17d0821469ecd7d /lib/CodeGen/CGCXX.cpp | |
parent | 764d0c23724b3671dcbe20af152fa1ad45f45e15 (diff) |
Fix two bugs with temporaries:
1. For
A f() {
return A();
}
we were incorrectly calling the A destructor on the returned object.
2. For
void f(A);
void g() {
A a;
f(a);
}
we were incorrectly not calling the copy constructor.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87082 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r-- | lib/CodeGen/CGCXX.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 3e9951f83b..9651c1ae83 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -671,8 +671,13 @@ CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest, // Code gen optimization to eliminate copy constructor and return // its first argument instead. if (getContext().getLangOptions().ElideConstructors && E->isElidable()) { - CXXConstructExpr::const_arg_iterator i = E->arg_begin(); - EmitAggExpr((*i), Dest, false); + const Expr *Arg = E->getArg(0); + + if (const CXXBindTemporaryExpr *BindExpr = + dyn_cast<CXXBindTemporaryExpr>(Arg)) + Arg = BindExpr->getSubExpr(); + + EmitAggExpr(Arg, Dest, false); return; } if (Array) { |