[Bug c++/105989] Coroutine frame space for temporaries in a co_await expression is not reused
michal.jankovic59 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Jun 15 09:49:14 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105989
--- Comment #1 from Michal Jankovič <michal.jankovic59 at gmail dot com> ---
Exploring further, this seems to be a symptom of a deeper issue - the coroutine
frame contains space for ALL variables of the coroutine, not just for the
maximally sized subset of the variables that can be alive across suspension.
Temporaries in co_await are just promoted to stored variables, so exhibit the
same problem.
This is easy to see when changing coro_1() body to:
{ std::byte _[500]; co_await coro_2(); }
{ std::byte _[500]; co_await coro_2(); }
{ std::byte _[500]; co_await coro_2(); }
{ std::byte _[500]; co_await coro_2(); }
{ std::byte _[500]; co_await coro_2(); }
The size of coro_1's frame is now 3408 - all of the variables are allocated
separately, even though they cannot be alive at the same time.
I would not call this a missed optimization - this seems like something that
should work on -O0, by using a smarter allocation scheme for the coroutine
frame.
More information about the Gcc-bugs
mailing list