[clang] [llvm] [clang][CodeGen] Extends lifetime of coroutine promise(CWG2563) (PR #151067)

Weibo He via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 15 20:00:53 PDT 2025


NewSigma wrote:

> I don't understand the title and the cited issue. The cited issue is about the point of GRO. How does that relates to the lifetime of promise?

In the cited issue, the GRO conversion function reads coro promise. However, since control has flowed off final_suspend, the promise has already been destroyed. We will encounter a heap-use-after-free at -O0. This patch defers the destruction after GRO conversion, thereby extending the lifetime of the promise.

> IIUC, if there is problem, we need to promote the point of GRO.

I thought it is more natural to promote the point of GRO and tried it yesterday. But it appears tricky to properly place GRO. On one side, `coro.end` must dominate GRO and `ret` so that ramp function and resume function have different return types. On the other side, `coro.end` must not dominate `coro.cleanup`, which would prevent ramp function and resume function from sharing it.

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


More information about the cfe-commits mailing list