[C++20] [Coroutines] Implement return value optimization for get_return_object
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 10 Jan 2022 11:18:33 +0000 (19:18 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Wed, 16 Feb 2022 05:38:00 +0000 (13:38 +0800)
commitd30ca5e2e23fe50dcd8d5d602bf7cfc61b4c1561
tree38c7910c57076b06470609d8cbf7451393d50ceb
parent2aed07e96c7a4f777e854fec619842c4289f8fbd
[C++20] [Coroutines] Implement return value optimization for get_return_object

This patch tries to implement RVO for coroutine's return object got from
get_return_object.
From [dcl.fct.def.coroutine]/p7 we could know that the return value of
get_return_object is either a reference or a prvalue. So it makes sense
to do copy elision for the return value. The return object should be
constructed directly into the storage where they would otherwise be
copied/moved to.

Test Plan: folly, check-all

Reviewed By: junparser

Differential revision: https://reviews.llvm.org/D117087
16 files changed:
clang/include/clang/AST/StmtCXX.h
clang/lib/AST/StmtCXX.cpp
clang/lib/CodeGen/CGCoroutine.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CodeGenCoroutines/coro-alloc-exp-namespace.cpp
clang/test/CodeGenCoroutines/coro-alloc.cpp
clang/test/CodeGenCoroutines/coro-gro-exp-namespace.cpp
clang/test/CodeGenCoroutines/coro-gro.cpp
clang/test/CodeGenCoroutines/coro-gro2-exp-namespace.cpp [moved from clang/test/CodeGenCoroutines/coro-gro-nrvo-exp-namespace.cpp with 91% similarity]
clang/test/CodeGenCoroutines/coro-gro2.cpp [moved from clang/test/CodeGenCoroutines/coro-gro-nrvo.cpp with 66% similarity]
clang/test/CodeGenCoroutines/coro-promise-dtor-exp-namespace.cpp
clang/test/CodeGenCoroutines/coro-promise-dtor.cpp
clang/test/SemaCXX/coroutine-no-move-ctor.cpp [new file with mode: 0644]
clang/test/SemaCXX/coroutines-exp-namespace.cpp
clang/test/SemaCXX/coroutines.cpp