https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125495
Bug ID: 125495
Summary: ICE in co-routine iteration
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: patrick at stwcx dot xyz
Target Milestone: ---
This is a regression that was introduced in 15.2 and continues through 16.x and
trunk. Iteration on a co_await'd value causes an ICE.
Example:
```
for (auto& str : co_await vector_of_strings())
```
This is the ICE from 15.2 series, but the ICE backtrace is different in 16.x
and trunk:
```
during RTL pass: expand
<source>: In function 'void example_task(_Z12example_taskv.Frame*)':
<source>:10:49: internal compiler error: in make_decl_rtl, at varasm.cc:1459
10 | for (auto& str : co_await vector_of_strings())
| ^
0x228dd45 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
???:0
0x229f296 internal_error(char const*, ...)
???:0
0x7d44da fancy_abort(char const*, int, char const*)
???:0
0xc16075 expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
???:0
0xaeeac9 expand_call(tree_node*, rtx_def*, int)
???:0
0xc1758e expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
???:0
0xc22c2e store_expr(tree_node*, rtx_def*, int, bool, bool)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```
The most trivial recreate I can seem to create is available on Compiler
Explorer, but does rely on stdexec in order to get a basic 'task'
implementation. Any alternative task implementation should reveal the same
ICE.
https://godbolt.org/z/836rsox8c
```
#include <exec/task.hpp>
#include <iostream>
#include <string>
#include <vector>
auto vector_of_strings() -> stdexec::task<std::vector<std::string>>;
auto example_task() -> stdexec::task<>
{
for (auto& str : co_await vector_of_strings())
{
std::cout << str << std::endl;
}
co_return;
}
```