Created attachment 58071 [details] aarch64.i compiling binutils fails on Fedora 40 binutils was configured like this ../binutils-2.28/configure '--build=x86_64-build_pc-linux-gnu' '--host=x86_64-build_pc-linux-gnu' '--target=arm-bbs-linux-gnueabihf' '--disable-werror' '--enable-ld=default' '--enable-gold=yes' '--enable-threads' '--enable-plugins' '--with-pkgversion=crosstool-NG ' '--disable-multilib' '--with-float=hard' i have build gcc from source and compiled the failed file here ist the output ../../binutils-2.28/gold/aarch64.cc: In constructor ‘{anonymous}::Stub_template_repertoire<big_endian>::Stub_template_repertoire()’: ../../binutils-2.28/gold/aarch64.cc:800:141: internal compiler error: in comptypes, at cp/typeck.cc:1681 0x7ca470 comptypes(tree_node*, tree_node*, int) ../../gcc/gcc/cp/typeck.cc:1681 0xcaf094 cp_build_binary_op(op_location_t const&, tree_code, tree_node*, tree_node*, int) ../../gcc/gcc/cp/typeck.cc:5505 0xa1a67b build_new_op(op_location_t const&, tree_code, int, tree_node*, tree_node*, tree_node*, tree_node*, tree_node**, int) ../../gcc/gcc/cp/call.cc:7516 0xc9e710 build_x_binary_op(op_location_t const&, tree_code, tree_node*, tree_code, tree_node*, tree_code, tree_node*, tree_node**, int) ../../gcc/gcc/cp/typeck.cc:4735 0xb9d700 cp_parser_binary_expression ../../gcc/gcc/cp/parser.cc:10579 0xb9e234 cp_parser_assignment_expression ../../gcc/gcc/cp/parser.cc:10737 0xb9f37d cp_parser_constant_expression ../../gcc/gcc/cp/parser.cc:11027 0xba0446 cp_parser_initializer_clause ../../gcc/gcc/cp/parser.cc:26144 0xb9fa81 cp_parser_initializer_list ../../gcc/gcc/cp/parser.cc:26439 0xb9fa81 cp_parser_braced_list ../../gcc/gcc/cp/parser.cc:26186 0xba04ac cp_parser_initializer_clause ../../gcc/gcc/cp/parser.cc:26149 0xba5214 cp_parser_initializer ../../gcc/gcc/cp/parser.cc:26083 0xbdb253 cp_parser_init_declarator ../../gcc/gcc/cp/parser.cc:23571 0xbaecb4 cp_parser_simple_declaration ../../gcc/gcc/cp/parser.cc:15900 0xbd4e60 cp_parser_declaration_statement ../../gcc/gcc/cp/parser.cc:14936 0xbdcd9e cp_parser_statement ../../gcc/gcc/cp/parser.cc:12892 0xbb1b97 cp_parser_statement_seq_opt ../../gcc/gcc/cp/parser.cc:13418 0xbb1dc7 cp_parser_compound_statement ../../gcc/gcc/cp/parser.cc:13272 0xbd4fd5 cp_parser_function_body ../../gcc/gcc/cp/parser.cc:25987 0xbd4fd5 cp_parser_ctor_initializer_opt_and_function_body ../../gcc/gcc/cp/parser.cc:26038
Reduced testcase: template <typename> struct A { struct B {} *b; static const int c { sizeof (b) / sizeof (b[0]) }; }; A<int> c; const int d = A<int>::c;
Started with r14-4793-gdad311874ac3b3cf4eca1c04f67cae80c953f7b8
Seems we're missing a dependence check in the sizeof / sizeof code: diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index e5a52dc2b39..284f6e29e36 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -5500,7 +5500,7 @@ cp_build_binary_op (const op_location_t &location, type0 = TREE_TYPE (type0); if (!TYPE_P (type1)) type1 = TREE_TYPE (type1); - if (type0 + if (type0 && type1 && INDIRECT_TYPE_P (type0) && same_type_p (TREE_TYPE (type0), type1)) {
(In reply to Patrick Palka from comment #3) > Seems we're missing a dependence check in the sizeof / sizeof code: > > diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc > index e5a52dc2b39..284f6e29e36 100644 > --- a/gcc/cp/typeck.cc > +++ b/gcc/cp/typeck.cc > @@ -5500,7 +5500,7 @@ cp_build_binary_op (const op_location_t &location, > type0 = TREE_TYPE (type0); > if (!TYPE_P (type1)) > type1 = TREE_TYPE (type1); > - if (type0 > + if (type0 && type1 > && INDIRECT_TYPE_P (type0) > && same_type_p (TREE_TYPE (type0), type1)) > { Yeah, I was about to suggest that too (just with && on a separate line. I wonder if TREE_TYPE (type0) could be NULL even when type0 is INDIRECT_TYPE_P, if yes, we should be testing also && TREE_TYPE (type0) after the INDIRECT_TYPE_P check.
Though, I think both build_pointer_type and build_reference_type would segfault if it was called on NULL_TREE to_type, and I don't see any spot in the FE that would create pointer/reference types without those routines. SO I think just && type1 should be right.
Yeah I think the TREE_TYPE of a compound type should never be null, at least as far as type dependence is concerned.
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:3900e944b0ac9db77380c5bb8635977dfd3b0691 commit r15-56-g3900e944b0ac9db77380c5bb8635977dfd3b0691 Author: Patrick Palka <ppalka@redhat.com> Date: Mon Apr 29 21:14:18 2024 -0400 c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888] In the sizeof / sizeof operator expression handling we're missing a dependence check for the second operand. PR c++/114888 gcc/cp/ChangeLog: * typeck.cc (cp_build_binary_op) <case *_DIV_*>: Add missing dependence check for the second sizeof operand. gcc/testsuite/ChangeLog: * g++.dg/template/sizeof19.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
The releases/gcc-14 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:3c925ac349b03ae9439c632fb1c042cdc8d78f40 commit r14-10149-g3c925ac349b03ae9439c632fb1c042cdc8d78f40 Author: Patrick Palka <ppalka@redhat.com> Date: Mon Apr 29 21:14:18 2024 -0400 c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888] In the sizeof / sizeof operator expression handling we're missing a dependence check for the second operand. PR c++/114888 gcc/cp/ChangeLog: * typeck.cc (cp_build_binary_op) <case *_DIV_*>: Add missing dependence check for the second sizeof operand. gcc/testsuite/ChangeLog: * g++.dg/template/sizeof19.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 3900e944b0ac9db77380c5bb8635977dfd3b0691)
Fixed.