public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99047] New: ICE on simple task coroutine example
@ 2021-02-09 22:46 redbeard0531 at gmail dot com
  2021-03-14 13:27 ` [Bug c++/99047] " iains at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: redbeard0531 at gmail dot com @ 2021-02-09 22:46 UTC (permalink / raw)
  To: gcc-bugs

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]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99047] ICE on simple task coroutine example
  2021-02-09 22:46 [Bug c++/99047] New: ICE on simple task coroutine example redbeard0531 at gmail dot com
@ 2021-03-14 13:27 ` iains at gcc dot gnu.org
  2021-03-14 14:49 ` iains at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: iains at gcc dot gnu.org @ 2021-03-14 13:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99047

Iain Sandoe <iains at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-03-14
           Assignee|unassigned at gcc dot gnu.org      |iains at gcc dot gnu.org
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
   Target Milestone|---                         |10.3

--- Comment #1 from Iain Sandoe <iains at gcc dot gnu.org> ---
(In reply to Mathias Stearn from comment #0)
> https://godbolt.org/z/ecxEbb Code compiles on MSVC and clang, and at least
> on clang produces the expected output.

>                 std::false_type await_ready() noexcept {
>                     return {};
>                 }

This seems to be where the ICE is coming from - the current implementation is
not handling it.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99047] ICE on simple task coroutine example
  2021-02-09 22:46 [Bug c++/99047] New: ICE on simple task coroutine example redbeard0531 at gmail dot com
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: iains at gcc dot gnu.org @ 2021-03-14 14:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99047

--- Comment #2 from Iain Sandoe <iains at gcc dot gnu.org> ---
Created attachment 50385
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50385&action=edit
Patch under test

had omitted the conversion to bool (it seems that almost all coroutines do use
a boolean type here).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99047] ICE on simple task coroutine example
  2021-02-09 22:46 [Bug c++/99047] New: ICE on simple task coroutine example redbeard0531 at gmail dot com
  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
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-15 16:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99047

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain D Sandoe <iains@gcc.gnu.org>:

https://gcc.gnu.org/g:541840b891d61ea70cddd046c96698bb70d7f52c

commit r11-7677-g541840b891d61ea70cddd046c96698bb70d7f52c
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Sun Mar 14 14:42:52 2021 +0000

    coroutines : Convert await_ready () expressions to bool [PR99047].

    The awaiter.await_ready() should be converted per [expr.await]/3

    (3.6) await-ready is the expression e.await_ready(), contextually
          converted to bool.

    gcc/cp/ChangeLog:

            PR c++/99047
            * coroutines.cc (expand_one_await_expression): If the
            await_ready() expression is not a boolean then convert it
            as required.

    gcc/testsuite/ChangeLog:

            PR c++/99047
            * g++.dg/coroutines/pr99047.C: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99047] ICE on simple task coroutine example
  2021-02-09 22:46 [Bug c++/99047] New: ICE on simple task coroutine example redbeard0531 at gmail dot com
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-22 22:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99047

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Iain D Sandoe
<iains@gcc.gnu.org>:

https://gcc.gnu.org/g:6bc35b091c9f5368060bac4b5ed3f7d4cb484daa

commit r10-9518-g6bc35b091c9f5368060bac4b5ed3f7d4cb484daa
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Sun Mar 14 14:42:52 2021 +0000

    coroutines : Convert await_ready () expressions to bool [PR99047].

    The awaiter.await_ready() should be converted per [expr.await]/3

    (3.6) await-ready is the expression e.await_ready(), contextually
          converted to bool.

    gcc/cp/ChangeLog:

            PR c++/99047
            * coroutines.cc (expand_one_await_expression): If the
            await_ready() expression is not a boolean then convert it
            as required.

    gcc/testsuite/ChangeLog:

            PR c++/99047
            * g++.dg/coroutines/pr99047.C: New test.

    (cherry picked from commit 541840b891d61ea70cddd046c96698bb70d7f52c)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99047] ICE on simple task coroutine example
  2021-02-09 22:46 [Bug c++/99047] New: ICE on simple task coroutine example redbeard0531 at gmail dot com
                   ` (3 preceding siblings ...)
  2021-03-22 22:04 ` cvs-commit at gcc dot gnu.org
@ 2021-03-24 12:41 ` iains at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: iains at gcc dot gnu.org @ 2021-03-24 12:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99047

Iain Sandoe <iains at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Iain Sandoe <iains at gcc dot gnu.org> ---
fixed for master and 10.3

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-24 12:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 22:46 [Bug c++/99047] New: ICE on simple task coroutine example redbeard0531 at gmail dot com
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

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).