[clang] [Clang] Propagate elide safe context through [[clang::coro_must_await]] (PR #108474)

Yuxuan Chen via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 15 09:34:32 PDT 2024


================
@@ -8261,12 +8261,19 @@ def CoroAwaitElidableDoc : Documentation {
 The ``[[clang::coro_await_elidable]]`` is a class attribute which can be applied
 to a coroutine return type.
 
-When a coroutine function that returns such a type calls another coroutine function,
-the compiler performs heap allocation elision when the call to the coroutine function
-is immediately co_awaited as a prvalue. In this case, the coroutine frame for the
-callee will be a local variable within the enclosing braces in the caller's stack
-frame. And the local variable, like other variables in coroutines, may be collected
-into the coroutine frame, which may be allocated on the heap.
+When a coroutine function returns such a type, a direct call expression therein
+that returns a prvalue of a type attributed ``[[clang::coro_await_elidable]]``
+is said to be under a safe elide context if one of the following is true:
----------------
yuxuanchen1997 wrote:

> If I am reading the code correctly, it is not actually a requirement that the containing / callee coroutine itself is also annotated as coro_await_elidable.

It is required. See `CurFnAwaitElidable`. Your example call to `foo()` of `NonElidableTask` won't have any elisions because we don't control `NonElidableTask::Promise::await_transform`.

https://github.com/llvm/llvm-project/pull/108474


More information about the cfe-commits mailing list