summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaCoroutine.cpp
diff options
context:
space:
mode:
authorBrian Gesiak <modocache@gmail.com>2018-10-08 03:08:39 +0000
committerBrian Gesiak <modocache@gmail.com>2018-10-08 03:08:39 +0000
commit0b5683001175f2e321c90f6608ade719c0a34fab (patch)
tree044e904420ae2741374f6e7625f23020935b2e25 /clang/lib/Sema/SemaCoroutine.cpp
parentc058a68784d25309f786a0f98f6af1c549126607 (diff)
downloadbcm5719-llvm-0b5683001175f2e321c90f6608ade719c0a34fab.tar.gz
bcm5719-llvm-0b5683001175f2e321c90f6608ade719c0a34fab.zip
[coro]Pass rvalue reference for named local variable to return_value
Summary: Addressing https://bugs.llvm.org/show_bug.cgi?id=37265. Implements [class.copy]/33 of coroutines TS. When the criteria for elision of a copy/move operation are met, but not for an exception-declaration, and the object to be copied is designated by an lvalue, or when the expression in a return or co_return statement is a (possibly parenthesized) id-expression that names an object with automatic storage duration declared in the body or parameter-declaration-clause of the innermost enclosing function or lambda-expression, overload resolution to select the constructor for the copy or the return_value overload to call is first performed as if the object were designated by an rvalue. Patch by Tanoy Sinha! Reviewers: modocache, GorNishanov Reviewed By: modocache, GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51741 llvm-svn: 343949
Diffstat (limited to 'clang/lib/Sema/SemaCoroutine.cpp')
-rw-r--r--clang/lib/Sema/SemaCoroutine.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 826cd48a8a5..9c9d266d3d8 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -841,6 +841,19 @@ StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, Expr *E,
E = R.get();
}
+ // Move the return value if we can
+ if (E) {
+ auto NRVOCandidate = this->getCopyElisionCandidate(E->getType(), E, CES_AsIfByStdMove);
+ if (NRVOCandidate) {
+ InitializedEntity Entity =
+ InitializedEntity::InitializeResult(Loc, E->getType(), NRVOCandidate);
+ ExprResult MoveResult = this->PerformMoveOrCopyInitialization(
+ Entity, NRVOCandidate, E->getType(), E);
+ if (MoveResult.get())
+ E = MoveResult.get();
+ }
+ }
+
// FIXME: If the operand is a reference to a variable that's about to go out
// of scope, we should treat the operand as an xvalue for this overload
// resolution.
OpenPOWER on IntegriCloud