https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118014
Bug ID: 118014 Summary: address computation for coroutine frame differs between BasePromise and MostDerivedPromise Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: giel+gcc at mortis dot eu Target Milestone: --- Created attachment 59845 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59845&action=edit reproduction scenario Given the signature of std::coroutine_handle<Promise>::from_promise(Promise& p) (from: ) I expect to be able to do struct MostDerivedPromise final : BasePromise { auto await_transform(auto&& x) { return wrapped_awaitable(std::coroutine_handle<BasePromise>::from_promise(*this)); } }; And then be able to use the produced handle both to access the (base part of the) promise and to call .resume()/.destroy()/.done() on it. Converting back to the promise reference works just fine. But .resume() and .destroy() end up calling a NULL function pointer. This appears to be caused by the conversion functions from/to handles&promises depend on the alignment of the promise: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/coroutine-passes.cc;h=c0d6eca7c070bbff391a07ce51d05d7010ff24c9;hb=04696df09633baf97cdbbdd6e9929b9d472161d3#l118 And obviously the alignment of MostDerivedPromise is unknown to std::coroutine_handle<BasePromise> causing wrong offset calculations for this scenario. I've attached a reproduction scenario that has a single assertion for my expectation that the underlying address produced for coroutine_handle<BasePromise>::from_promise and coroutine_handle<MostDerivedPromise> is the same. That assertion holds when MostDerivedPromise' alignment is equal to that of BasePromise but fails otherwise.