public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redbeard0531 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/99047] New: ICE on simple task coroutine example
Date: Tue, 09 Feb 2021 22:46:35 +0000	[thread overview]
Message-ID: <bug-99047-4@http.gcc.gnu.org/bugzilla/> (raw)

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]

             reply	other threads:[~2021-02-09 22:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 22:46 redbeard0531 at gmail dot com [this message]
2021-03-14 13:27 ` [Bug c++/99047] " iains at gcc dot gnu.org
2021-03-14 14:49 ` iains at gcc dot gnu.org
2021-03-15 16:00 ` cvs-commit at gcc dot gnu.org
2021-03-22 22:04 ` cvs-commit at gcc dot gnu.org
2021-03-24 12:41 ` iains at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99047-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).