https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99047
Bug ID: 99047 Summary: ICE on simple task coroutine example Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redbeard0531 at gmail dot com Target Milestone: --- https://godbolt.org/z/ecxEbb Code compiles on MSVC and clang, and at least on clang produces the expected output. #include <optional> #include <coroutine> template <typename T> struct [[nodiscard]] task { struct promise_type { std::suspend_always initial_suspend() { return {}; } auto final_suspend() noexcept { struct awaiter { std::false_type await_ready() noexcept { return {}; } std::coroutine_handle<> await_suspend(std::coroutine_handle<>) noexcept { return next; } void await_resume() noexcept { } std::coroutine_handle<> next; }; return awaiter{next}; } void unhandled_exception() noexcept { std::terminate(); } auto get_return_object() { return task(this); } auto coro() { return std::coroutine_handle<promise_type>::from_promise(*this); } void return_value(T val) { result.emplace(std::move(val)); } std::coroutine_handle<> next; std::optional<T> result; }; task(task&& source) : p(std::exchange(source.p, nullptr)) {} explicit task(promise_type* p) : p(p) {} ~task() { if (p) p->coro().destroy(); } bool await_ready() noexcept { return p->coro().done(); } std::coroutine_handle<> await_suspend(std::coroutine_handle<> next) noexcept { p->next = next; return p->coro(); } const T& await_resume() const& noexcept { return *p->result; } promise_type* p; }; task<int> five() { co_return 5; } task<int> six() { co_return (co_await five()) + 1; } int main() { auto task = six(); task.p->next = std::noop_coroutine(); task.p->coro().resume(); return *task.p->result; } <source>: In function 'void _Z4fivev.actor(five()::_Z4fivev.frame*)': <source>:92:11: internal compiler error: in fold_convert_loc, at fold-const.c:2430 92 | task<int> five() { | ^~~~ 0x1ce6f09 internal_error(char const*, ...) ???:0 0x6b6f43 fancy_abort(char const*, int, char const*) ???:0 0xc92cd4 fold_convert_loc(unsigned int, tree_node*, tree_node*) ???:0 0xd126ae gimple_boolify(tree_node*) ???:0 0xd1b720 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ???:0 0xd1bb4a gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) [snipping many more frames]