public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105475] New: ICE in coerce_template_parms, at cp/pt.cc:9183
@ 2022-05-04 10:22 asolokha at gmx dot com
  2022-05-04 10:39 ` [Bug c++/105475] " marxin at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: asolokha at gmx dot com @ 2022-05-04 10:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105475
           Summary: ICE in coerce_template_parms, at cp/pt.cc:9183
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: C++-Coroutine, ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: asolokha at gmx dot com
  Target Milestone: ---

g++ 13.0.0 20220501 snapshot (g:75bbc3da3e5f75f683fa33e309045c582efd20eb) ICEs
when compiling test/CodeGenCoroutines/coro-newpm-pipeline.cpp or
test/CodeGenCoroutines/coro-always-inline.cpp w/ -fcoroutines:

namespace std {

struct handle {};

struct awaitable {
  bool await_ready() noexcept { return false; }
  void await_suspend(handle) noexcept {}
  bool await_resume() noexcept { return true; }
};

template <typename T> struct coroutine_handle {
  static handle from_address(void *address) noexcept { return {}; }
};

template <typename T = void> struct coroutine_traits {
  struct promise_type {
    awaitable initial_suspend() { return {}; }
    awaitable final_suspend() noexcept { return {}; }
    void return_void() {}
    T get_return_object() { return T(); }
    void unhandled_exception() {}
  };
};
} // namespace std

void foo() { co_return; }

% g++-13.0.0 -fcoroutines -c test/CodeGenCoroutines/coro-newpm-pipeline.cpp
test/CodeGenCoroutines/coro-newpm-pipeline.cpp: In function 'void foo()':
test/CodeGenCoroutines/coro-newpm-pipeline.cpp:43:14: internal compiler error:
in coerce_template_parms, at cp/pt.cc:9183
   43 | void foo() { co_return; }
      |              ^~~~~~~~~
0x706e6c coerce_template_parms
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/pt.cc:9183
0xb532b5 lookup_template_class_1
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/pt.cc:9966
0xb55150 lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int, int)
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/pt.cc:10353
0x9adfce instantiate_coro_handle_for_promise_type
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/coroutines.cc:400
0x9b099e coro_promise_type_found_p
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/coroutines.cc:455
0x9b277b finish_co_return_stmt(unsigned int, tree_node*)
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/coroutines.cc:1331
0xadbc28 cp_parser_jump_statement
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:14303
0xadbc28 cp_parser_statement
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:12312
0xadbd7d cp_parser_statement_seq_opt
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:12850
0xadbe57 cp_parser_compound_statement
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:12802
0xafca45 cp_parser_function_body
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:25076
0xafca45 cp_parser_ctor_initializer_opt_and_function_body
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:25127
0xafd9fa cp_parser_function_definition_after_declarator
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:31259
0xafecb8 cp_parser_function_definition_from_specifiers_and_declarator
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:31175
0xafecb8 cp_parser_init_declarator
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:22598
0xad87f9 cp_parser_simple_declaration
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:15280
0xb09f85 cp_parser_declaration
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:14966
0xb0a969 cp_parser_toplevel_declaration
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:14987
0xb0a969 cp_parser_translation_unit
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:5010
0xb0a969 c_parse_file()
       
/var/tmp/portage/sys-devel/gcc-13.0.0_p20220501/work/gcc-13-20220501/gcc/cp/parser.cc:48113

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

* [Bug c++/105475] ICE in coerce_template_parms, at cp/pt.cc:9183
  2022-05-04 10:22 [Bug c++/105475] New: ICE in coerce_template_parms, at cp/pt.cc:9183 asolokha at gmx dot com
@ 2022-05-04 10:39 ` marxin at gcc dot gnu.org
  2024-07-18 13:50 ` [Bug c++/105475] coroutines: " arsen at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-05-04 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |iains at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org
   Last reconfirmed|                            |2022-05-04

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
It's there since the beginning of coroutines (r10-6063-g49789fd08378e3ff).

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

* [Bug c++/105475] coroutines: ICE in coerce_template_parms, at cp/pt.cc:9183
  2022-05-04 10:22 [Bug c++/105475] New: ICE in coerce_template_parms, at cp/pt.cc:9183 asolokha at gmx dot com
  2022-05-04 10:39 ` [Bug c++/105475] " marxin at gcc dot gnu.org
@ 2024-07-18 13:50 ` arsen at gcc dot gnu.org
  2024-07-22 16:15 ` arsen at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-07-18 13:50 UTC (permalink / raw)
  To: gcc-bugs

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

Arsen Arsenović <arsen at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arsen at gcc dot gnu.org

--- Comment #2 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
unsure if this code is valid..

anyway, the crash reason is the lack of default in coroutine_handle.  we pass a
NULL_TREE promise type to instantiate_coro_handle_for_promise_type in order to
instantiate the type-erased coro handle and the compiler gets confused:

      /*  We can also instantiate the void coroutine_handle<>  */
      void_coro_handle_type =
        instantiate_coro_handle_for_promise_type (loc, NULL_TREE);
      if (void_coro_handle_type == NULL_TREE)
        return false;

passing void_type_note there fixes that crash and reveals another in
fold_builtin_call_array (so, it could be something else, I'll get back to that
later - I suspect (not too confidently) that it might be unrelated)

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

* [Bug c++/105475] coroutines: ICE in coerce_template_parms, at cp/pt.cc:9183
  2022-05-04 10:22 [Bug c++/105475] New: ICE in coerce_template_parms, at cp/pt.cc:9183 asolokha at gmx dot com
  2022-05-04 10:39 ` [Bug c++/105475] " marxin at gcc dot gnu.org
  2024-07-18 13:50 ` [Bug c++/105475] coroutines: " arsen at gcc dot gnu.org
@ 2024-07-22 16:15 ` arsen at gcc dot gnu.org
  2024-07-27 11:30 ` arsen at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-07-22 16:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
ah, seems that we're missing handling of error_mark_node in a few places while
processing a coroutine, causing the middle-end to be confused later.  I'll
leave that for later.

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

* [Bug c++/105475] coroutines: ICE in coerce_template_parms, at cp/pt.cc:9183
  2022-05-04 10:22 [Bug c++/105475] New: ICE in coerce_template_parms, at cp/pt.cc:9183 asolokha at gmx dot com
                   ` (2 preceding siblings ...)
  2024-07-22 16:15 ` arsen at gcc dot gnu.org
@ 2024-07-27 11:30 ` arsen at gcc dot gnu.org
  2024-08-02 18:34 ` cvs-commit at gcc dot gnu.org
  2024-08-29 12:17 ` arsen at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-07-27 11:30 UTC (permalink / raw)
  To: gcc-bugs

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

Arsen Arsenović <arsen at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |arsen at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #4 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
Created attachment 58768
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58768&action=edit
possible fix

I have a patch committed on a branch for this, but I am certain this is invalid
code by now, so I've marked the PR as ICE-on-invalid-code.

I haven't regression-tested it, so I can't post it yet.

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

* [Bug c++/105475] coroutines: ICE in coerce_template_parms, at cp/pt.cc:9183
  2022-05-04 10:22 [Bug c++/105475] New: ICE in coerce_template_parms, at cp/pt.cc:9183 asolokha at gmx dot com
                   ` (3 preceding siblings ...)
  2024-07-27 11:30 ` arsen at gcc dot gnu.org
@ 2024-08-02 18:34 ` cvs-commit at gcc dot gnu.org
  2024-08-29 12:17 ` arsen at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-08-02 18:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Arsen Arsenovic <arsen@gcc.gnu.org>:

https://gcc.gnu.org/g:5b4476a165565cb20729c0a97a3f43b060595209

commit r15-2702-g5b4476a165565cb20729c0a97a3f43b060595209
Author: Arsen ArsenoviÄ <arsen@aarsen.me>
Date:   Thu Jul 25 22:41:34 2024 +0200

    c++/coroutines: check for members we use in handle_types [PR105475]

    Currently, it is possible to ICE GCC by giving it sufficiently broken
    code, where sufficiently broken means a std::coroutine_handle missing a
    default on the promise_type template argument, and missing members.
    As the code generator relies on lookups in the coroutine_handle never
    failing (and has no way to signal that error), lets do it ahead of time,
    save the result, and use that.  This saves us some lookups and allows us
    to propagate an error.

    PR c++/105475 - coroutines: ICE in coerce_template_parms, at cp/pt.cc:9183

    gcc/cp/ChangeLog:

            PR c++/105475
            * coroutines.cc (struct coroutine_info): Add from_address.
            Carries the from_address member we looked up earlier.
            (coro_resume_identifier): Remove.  Unused.
            (coro_init_identifiers): Do not initialize the above.
            (void_coro_handle_address): New variable.  Contains the baselink
            for the std::coroutine_handle<void>::address() instance method.
            (get_handle_type_address): New function.  Looks up and validates
            handle_type::address in a given handle_type.
            (get_handle_type_from_address): New function.  Looks up and
            validates handle_type::from_address in a given handle_type.
            (coro_promise_type_found_p): Remove reliance on
            coroutine_handle<> defaulting the promise type to void.  Store
            get_handle_type_* results where appropriate.
            (get_coroutine_from_address): New helper.  Gets the
            handle_type::from_address BASELINK from a coroutine_info.
            (build_actor_fn): Use the get_coroutine_from_address helper and
            void_coro_handle_address.

    gcc/testsuite/ChangeLog:

            PR c++/105475
            * g++.dg/coroutines/pr103868.C: Add std::coroutine_handle
            members we check for now.
            * g++.dg/coroutines/pr105287.C: Ditto.
            * g++.dg/coroutines/pr105301.C: Ditto.
            * g++.dg/coroutines/pr94528.C: Ditto.
            * g++.dg/coroutines/pr94879-folly-1.C: Ditto.
            * g++.dg/coroutines/pr94883-folly-2.C: Ditto.
            * g++.dg/coroutines/pr98118.C: Ditto.
            * g++.dg/coroutines/pr105475.C: New test.
            * g++.dg/coroutines/pr105475-1.C: New test.
            * g++.dg/coroutines/pr105475-2.C: New test.
            * g++.dg/coroutines/pr105475-3.C: New test.
            * g++.dg/coroutines/pr105475-4.C: New test.
            * g++.dg/coroutines/pr105475-5.C: New test.
            * g++.dg/coroutines/pr105475-6.C: New test.
            * g++.dg/coroutines/pr105475-broken-spec.C: New test.
            * g++.dg/coroutines/pr105475-broken-spec-2.C: New test.

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

* [Bug c++/105475] coroutines: ICE in coerce_template_parms, at cp/pt.cc:9183
  2022-05-04 10:22 [Bug c++/105475] New: ICE in coerce_template_parms, at cp/pt.cc:9183 asolokha at gmx dot com
                   ` (4 preceding siblings ...)
  2024-08-02 18:34 ` cvs-commit at gcc dot gnu.org
@ 2024-08-29 12:17 ` arsen at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-08-29 12:17 UTC (permalink / raw)
  To: gcc-bugs

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

Arsen Arsenović <arsen at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |WAITING

--- Comment #6 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
fixed on trunk, maybe a backport candidate

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

end of thread, other threads:[~2024-08-29 12:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04 10:22 [Bug c++/105475] New: ICE in coerce_template_parms, at cp/pt.cc:9183 asolokha at gmx dot com
2022-05-04 10:39 ` [Bug c++/105475] " marxin at gcc dot gnu.org
2024-07-18 13:50 ` [Bug c++/105475] coroutines: " arsen at gcc dot gnu.org
2024-07-22 16:15 ` arsen at gcc dot gnu.org
2024-07-27 11:30 ` arsen at gcc dot gnu.org
2024-08-02 18:34 ` cvs-commit at gcc dot gnu.org
2024-08-29 12:17 ` arsen 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).