https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118491
Bug ID: 118491 Summary: coroutines: ICE when co_awaiting l-value awaitable from range-based loop. Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: email at miropalmu dot cc Target Milestone: --- The code snipped below (https://godbolt.org/z/hx3Ps9WqP) produces ICE on gcc 15.0.1 20250115. Interesting part is that ICE requires a range-based loop and a l-value reference. It is also reproducible with co_yielding a l-value. ``` #include <coroutine> // For std::suspend_always struct task { struct promise_type { task get_return_object() { return {}; } std::suspend_always initial_suspend() { return {}; } std::suspend_always final_suspend() noexcept { return {}; } std::suspend_always yield_value(double value) { return {}; } void unhandled_exception() { throw; } }; }; task do_task() { const int arr[]{1, 2, 3}; // No ICE if classic loop and not range-based one. // for (auto i = 0; i < 10; ++i) { // No ICE if these are moved out of the loop. // auto x = std::suspend_always{}; // co_await x; for (auto _ : arr) { auto x = std::suspend_always{}; co_await x; // Alternatively: // auto bar = 42.; // co_yield bar; // No ICE if r-values: // co_await std::suspend_always{}; // co_yield 42.; } } ``` Output: ``` <source>: In function 'void do_task(_Z7do_taskv.Frame*)': <source>:25:18: internal compiler error: in gimplify_var_or_parm_decl, at gimplify.cc:3346 25 | co_await x; | ^ 0x28fd265 diagnostic_context::diagnostic_impl(rich_location*, diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag (*) [1], diagnostic_t) ???:0 0x2914066 internal_error(char const*, ...) ???:0 0xacb118 fancy_abort(char const*, int, char const*) ???:0 0x10fa6b9 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fb91c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x110e4e3 gimplify_arg(tree_node**, gimple**, unsigned long, bool) ???:0 0xb6c837 cp_gimplify_expr(tree_node**, gimple**, gimple**) ???:0 0x10f97ab gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fc1e5 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fa3f2 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fbb85 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fb957 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fdd7a gimplify_stmt(tree_node**, gimple**) ???:0 0x10fb24b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fbb85 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fdd7a gimplify_stmt(tree_node**, gimple**) ???:0 0x10fbb9c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fdd7a gimplify_stmt(tree_node**, gimple**) ???:0 0x10fbb9c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0x10fdd7a gimplify_stmt(tree_node**, gimple**) ???: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 ```