]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/coros: do not assume coros don't nest [PR113457]
authorArsen Arsenović <arsen@aarsen.me>
Fri, 23 Aug 2024 18:19:05 +0000 (20:19 +0200)
committerArsen Arsenović <arsen@gcc.gnu.org>
Mon, 26 Aug 2024 22:59:52 +0000 (00:59 +0200)
commit5cca7517c5868b7b9aa13992145eb6082ac5d5b9
treea383afd49f1194a8d58d12d23179256eeea1f203
parentc73d7f3c66c0b5865edd6880cd0d6be723cfbb8d
c++/coros: do not assume coros don't nest [PR113457]

In the testcase presented in the PR, during template expansion, an
tsubst of an operand causes a lambda coroutine to be processed, causing
it to get an initial suspend and final suspend.  The code for assigning
awaitable var names (get_awaitable_var) assumed that the sequence Is ->
Is -> Fs -> Fs is impossible (i.e. that one could only 'open' one
coroutine before closing it at a time), and reset the counter used for
unique numbering each time a final suspend occured.  This assumption is
false in a few cases, usually when lambdas are involved.

Instead of storing this counter in a static-storage variable, we can
store it in coroutine_info.  This struct is local to each function, so
we don't need to worry about "cross-contamination" nor resetting.

PR c++/113457

gcc/cp/ChangeLog:

* coroutines.cc (struct coroutine_info): Add integer field
awaitable_number.  This is a counter used for assigning unique
names to awaitable temporaries.
(get_awaitable_var): Use awaitable_number from coroutine_info
instead of the static int awn.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr113457-1.C: New test.
* g++.dg/coroutines/pr113457.C: New test.
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/pr113457-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr113457.C [new file with mode: 0644]