internal compiler error while compiling system headers as modules

Bug #1915640 reported by Alexander Lelyakin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc
Fix Released
Medium
gcc-11 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Issue following three commands in empty directory:
--------------
g++-11 -std=c++20 -fmodules-ts -x c++-system-header iostream
g++-11 -std=c++20 -fmodules-ts -x c++-system-header utility
g++-11 -std=c++20 -fmodules-ts -x c++-system-header algorithm
----------------
The third command results in:
-------------------------
/usr/include/c++/11/bits/iterator_concepts.h:919:54: internal compiler error: tree check: expected binding_vector, have overload in maybe_record_mergeable_decl, at cp/name-lookup.c:3562
  919 | operator==(unreachable_sentinel_t, const _It&) noexcept
      | ^~~~~~~~
0xe33760 tree_check_failed(tree_node const*, char const*, int, char const*, ...)
 ../../src/gcc/tree.c:9814
0xbfb767 tree_check(tree_node*, char const*, int, char const*, tree_code)
 ../../src/gcc/tree.h:3349
0xbfb767 maybe_record_mergeable_decl
 ../../src/gcc/cp/name-lookup.c:3562
0x5ea899 do_pushdecl
 ../../src/gcc/cp/name-lookup.c:3864
0x12d067d do_pushdecl_with_scope
 ../../src/gcc/cp/name-lookup.c:4886
0x12d2fc7 pushdecl_namespace_level(tree_node*, bool)
 ../../src/gcc/cp/name-lookup.c:6250
0x14328dc push_template_decl(tree_node*, bool)
 ../../src/gcc/cp/pt.c:6052
0x192e00e do_friend(tree_node*, tree_node*, tree_node*, tree_node*, overload_flags, bool)
 ../../src/gcc/cp/friend.c:608
0x134810d grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*, decl_context, int, tree_node**)
 ../../src/gcc/cp/decl.c:13600
0x13a4d39 grokmethod(cp_decl_specifier_seq*, cp_declarator const*, tree_node*)
 ../../src/gcc/cp/decl.c:17476
0x13a4450 cp_parser_save_member_function_body
 ../../src/gcc/cp/parser.c:30580
0x133881c cp_parser_init_declarator
 ../../src/gcc/cp/parser.c:21557
0x140decf cp_parser_single_declaration
 ../../src/gcc/cp/parser.c:30434
0x762047 cp_parser_template_declaration_after_parameters
 ../../src/gcc/cp/parser.c:30006
0x7543ea cp_parser_explicit_template_declaration
 ../../src/gcc/cp/parser.c:30272
0x1342784 cp_parser_member_specification_opt
 ../../src/gcc/cp/parser.c:25734
0x1342784 cp_parser_class_specifier_1
 ../../src/gcc/cp/parser.c:24818
0x13334c0 cp_parser_class_specifier
 ../../src/gcc/cp/parser.c:25128
0x13334c0 cp_parser_type_specifier
 ../../src/gcc/cp/parser.c:18381
0x1331cee cp_parser_decl_specifier_seq
 ../../src/gcc/cp/parser.c:15003
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.
----------------------
g++-11 (Ubuntu 11-20210203-0ubuntu1) 11.0.0 20210203 (experimental) [master revision e8c87bc07b5:def4749fcba:84110515b93a6709de24240d6658ac207db5129f]
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Tags: c++20 modules
Revision history for this message
In , Matthias Klose (doko) wrote :

seen with trunk 20210207, with an installed compiler, empty directory:

$ g++-11 -std=c++20 -fmodules-ts -x c++-system-header iostream
$ g++-11 -std=c++20 -fmodules-ts -x c++-system-header utility
$ g++-11 -std=c++20 -fmodules-ts -x c++-system-header algorithm
In file included from /usr/include/c++/11/bits/stl_iterator_base_types.h:71,
                 from /usr/include/c++/11/bits/stl_algobase.h:65,
                 from /usr/include/c++/11/algorithm:61:
/usr/include/c++/11/bits/iterator_concepts.h:919:54: internal compiler error: tree check: expected binding_vector, have overload in maybe_record_mergeable_decl, at cp/name-lookup.c:3562
  919 | operator==(unreachable_sentinel_t, const _It&) noexcept
      | ^~~~~~~~
0xe2c617 tree_check_failed(tree_node const*, char const*, int, char const*, ...)
        ../../src/gcc/tree.c:9814
0xbfc27c tree_check(tree_node*, char const*, int, char const*, tree_code)
        ../../src/gcc/tree.h:3349
0xbfc27c maybe_record_mergeable_decl
        ../../src/gcc/cp/name-lookup.c:3562
0x5ea96a do_pushdecl
        ../../src/gcc/cp/name-lookup.c:3864
0x12cad8d do_pushdecl_with_scope
        ../../src/gcc/cp/name-lookup.c:4886
0x12cd607 pushdecl_namespace_level(tree_node*, bool)
        ../../src/gcc/cp/name-lookup.c:6251
0x142aeac push_template_decl(tree_node*, bool)
        ../../src/gcc/cp/pt.c:6054
0x192f6fe do_friend(tree_node*, tree_node*, tree_node*, tree_node*, overload_flags, bool)
        ../../src/gcc/cp/friend.c:608
0x13418db grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*, decl_context, int, tree_node**)
        ../../src/gcc/cp/decl.c:13613
0x139e169 grokmethod(cp_decl_specifier_seq*, cp_declarator const*, tree_node*)
        ../../src/gcc/cp/decl.c:17489
0x139d880 cp_parser_save_member_function_body
        ../../src/gcc/cp/parser.c:30587
0x1331fcc cp_parser_init_declarator
        ../../src/gcc/cp/parser.c:21557
0x1406b5f cp_parser_single_declaration
        ../../src/gcc/cp/parser.c:30441
0x761a2f cp_parser_template_declaration_after_parameters
        ../../src/gcc/cp/parser.c:30013
0x7544b0 cp_parser_explicit_template_declaration
        ../../src/gcc/cp/parser.c:30279
0x133bef4 cp_parser_member_specification_opt
        ../../src/gcc/cp/parser.c:25740
0x133bef4 cp_parser_class_specifier_1
        ../../src/gcc/cp/parser.c:24818
0x132c600 cp_parser_class_specifier
        ../../src/gcc/cp/parser.c:25134
0x132c600 cp_parser_type_specifier
        ../../src/gcc/cp/parser.c:18381
0x132b40e cp_parser_decl_specifier_seq
        ../../src/gcc/cp/parser.c:15003
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.

Changed in gcc:
importance: Unknown → Medium
status: Unknown → In Progress
Revision history for this message
In , Natoan (natoan) wrote :

I think this is a duplicate of 99071, which hadn't been done when Mattias tested.

However, I am getting a different ICE:
devvm1702:235>./xg++ -B./ -nostdinc++ -I../x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu -I../x86_64-pc-linux-gnu/libstdc++-v3/include -I../../..//src/libstdc++-v3/libsupc++ -I../../../src/libstdc++-v3/include/backward -I../../../src/libstdc++-v3/testsuite/util -std=c++20 -fmodules-ts -x c++-system-header iostream
devvm1702:236>./xg++ -B./ -nostdinc++ -I../x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu -I../x86_64-pc-linux-gnu/libstdc++-v3/include -I../../..//src/libstdc++-v3/libsupc++ -I../../../src/libstdc++-v3/include/backward -I../../../src/libstdc++-v3/testsuite/util -std=c++20 -fmodules-ts -x c++-system-header utility
devvm1702:237>./xg++ -B./ -nostdinc++ -I../x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu -I../x86_64-pc-linux-gnu/libstdc++-v3/include -I../../..//src/libstdc++-v3/libsupc++ -I../../../src/libstdc++-v3/include/backward -I../../../src/libstdc++-v3/testsuite/util -std=c++20 -fmodules-ts -x c++-system-header algorithm
../x86_64-pc-linux-gnu/libstdc++-v3/include/algorithm: internal compiler error: in make_dependency, at cp/module.cc:12514
0xd06a9a depset::hash::make_dependency(tree_node*, depset::entity_kind)
 ../../../src/gcc/cp/module.cc:12514
0xd07ae1 depset::hash::add_dependency(tree_node*, depset::entity_kind)
 ../../../src/gcc/cp/module.cc:12712
0xcf24e0 trees_out::decl_node(tree_node*, walk_kind)
 ../../../src/gcc/cp/module.cc:8605
0xcf4a73 trees_out::tree_node(tree_node*)
 ../../../src/gcc/cp/module.cc:9168
0xce2700 trees_out::vec_chained_decls(tree_node*)
 ../../../src/gcc/cp/module.cc:4981
0xd02052 trees_out::write_class_def(tree_node*)
 ../../../src/gcc/cp/module.cc:11737

which does appear to be new.

Revision history for this message
In , Natoan (natoan) wrote :

// B_a.ii
template<typename _T1>
struct pair
{
  inline void Frob ();
};

// B_b.ii
import "./B_a.ii"

template<class _T1>
inline void pair<_T1>::Frob()
{ }

./cc1plus -quiet -std=c++20 -fmodule-header -fpreprocessed B_a.ii && ./cc1plus -quiet -std=c++20 -fmodule-header -fpreprocessed B_b.ii
B_b.ii:1: internal compiler error: in make_dependency, at cp/module.cc:12523
    1 | import "./B_a.ii" [[__translated]];
      |
0xcd61da depset::hash::make_dependency(tree_node*, depset::entity_kind)
 ../../../src/gcc/cp/module.cc:12523
0xcd7f54 depset::hash::add_class_entities(vec<tree_node*, va_gc, vl_embed>*)
 ../../../src/gcc/cp/module.cc:12942
0xce60bb module_state::write(elf_out*, cpp_reader*)
 ../../../src/gcc/cp/module.cc:17604

The module flags on the TEMPLATE_DECL do not match those of the DECL_TEMPLATE_RESULT.

Revision history for this message
In , Cvs-commit (cvs-commit) wrote :

The master branch has been updated by Nathan Sidwell <email address hidden>:

https://gcc.gnu.org/g:c49fcfddaa47f2828fe2af11ae857cd67f53e23f

commit r11-7322-gc49fcfddaa47f2828fe2af11ae857cd67f53e23f
Author: Nathan Sidwell <email address hidden>
Date: Mon Feb 22 06:43:32 2021 -0800

    c++: cross-header-unit template definitions [PR 99153]

    A member function can be defined in a different header-file than the
    one defining the class. In such situations we must unmark the decl as
    imported. When the entity is a template we failed to unmark the
    template_decl.

    Perhaps the duplication of these flags on the template_decl from the
    underlying decl is an error. I set on the fence about it for a long
    time during development, but I don't think now is the time to change
    that (barring catastrophic bugs).

            PR c++/99153
            gcc/cp/
            * decl.c (duplicate_decls): Move DECL_MODULE_IMPORT_P propagation
            to common-path.
            * module.cc (set_defining_module): Add assert.
            gcc/testsuite/
            * g++.dg/modules/pr99153_a.H: New.
            * g++.dg/modules/pr99153_b.H: New.

Revision history for this message
In , Natoan (natoan) wrote :

 c49fcfddaa4 2021-02-22 | c++: cross-header-unit template definitions [PR 99153]

I have verified that iostream, utility and algorithm can be built

Revision history for this message
Alexander Lelyakin (alexander-lelyakin) wrote :
Download full text (5.6 KiB)

On new version of g++-11, just compiled from trunk:
g++ (GCC) 11.0.0 20210223 (experimental)

Again in empty dir:
g++ -std=c++20 -fmodules-ts -x c++-system-header utility
g++ -std=c++20 -fmodules-ts -x c++-system-header algorithm
g++ -std=c++20 -fmodules-ts -x c++-system-header iostream
g++ -std=c++20 -fmodules-ts -x c++-system-header ranges
g++ -std=c++20 -fmodules-ts -x c++-system-header vector
g++ -std=c++20 -fmodules-ts -x c++-system-header array
g++ -std=c++20 -fmodules-ts -x c++-system-header string
g++ -std=c++20 -fmodules-ts -x c++-system-header functional

Result:
/usr/local/include/c++/11.0.0/functional:138:49: internal compiler error: in install_entity, at cp/module.cc:7584
  138 | using _Arity = integral_constant<size_t, 0>;
      | ^
0xa59f3d trees_in::install_entity(tree_node*)
 ../../gcc/gcc/cp/module.cc:7584
0xa63fda trees_in::decl_value()
 ../../gcc/gcc/cp/module.cc:8106
0xa65b47 trees_in::tree_node(bool)
 ../../gcc/gcc/cp/module.cc:9249
0xa6c303 module_state::read_cluster(unsigned int)
 ../../gcc/gcc/cp/module.cc:14943
0xa6c6ad module_state::load_section(unsigned int, binding_slot*)
 ../../gcc/gcc/cp/module.cc:18095
0xa6c76f module_state::lazy_load(unsigned int, binding_slot*)
 ../../gcc/gcc/cp/module.cc:18747
0xa669b0 trees_in::tree_node(bool)
 ../../gcc/gcc/cp/module.cc:9760
0xa68002 trees_in::lang_decl_vals(tree_node*)
 ../../gcc/gcc/cp/module.cc:6982
0xa63dba trees_in::tree_node_vals(tree_node*)
 ../../gcc/gcc/cp/module.cc:7175
0xa63dba trees_in::decl_value()
 ../../gcc/gcc/cp/module.cc:8068
0xa65b47 trees_in::tree_node(bool)
 ../../gcc/gcc/cp/module.cc:9249
0xa66cfc trees_in::chained_decls()
 ../../gcc/gcc/cp/module.cc:4954
0xa67aa9 trees_in::core_vals(tree_node*)
 ../../gcc/gcc/cp/module.cc:6656
0xa6df67 trees_in::tree_node_vals(tree_node*)
 ../../gcc/gcc/cp/module.cc:7173
0xa6df67 trees_in::tree_value()
 ../../gcc/gcc/cp/module.cc:9026
0xa6564f trees_in::tree_node(bool)
 ../../gcc/gcc/cp/module.cc:9244
0xa67ab7 trees_in::core_vals(tree_node*)
 ../../gcc/gcc/cp/module.cc:6658
0xa6df67 trees_in::tree_node_vals(tree_node*)
 ../../gcc/gcc/cp/module.cc:7173
0xa6df67 trees_in::tree_value()
 ../../gcc/gcc/cp/module.cc:9026
0xa6564f trees_in::tree_node(bool)
 ../../gcc/gcc/cp/module.cc:9244
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Sorry, I don't find a shorter sequence of system headers.
Every header is compilable when alone,
but if you do it in sequence in the same directory
after 5-7 system headers it usually crashes.

Another sequence:
g++ -std=c++20 -fmodules-ts -x c++-system-header concepts
g++ -std=c++20 -fmodules-ts -x c++-system-header functional
g++ -std=c++20 -fmodules-ts -x c++-system-header ranges
g++ -std=c++20 -fmodules-ts -x c++-system-header vector
g++ -std=c++20 -fmodules-ts -x c++-system-header string
g++ -std=c++20 -fmodules-ts -x c++-system-header algorithm
-------
In file included from /usr/local/include/c++/11.0.0/bits/functexcept.h:40,
                 from /usr/local/include/c++/11.0.0/bits/stl_algobase.h:6...

Read more...

Revision history for this message
In , Alexander Lelyakin (alexander-lelyakin) wrote :

I have found two another sequences of system headers that cannot be compiled:

-------------
g++ -std=c++20 -fmodules-ts -x c++-system-header utility
g++ -std=c++20 -fmodules-ts -x c++-system-header algorithm
g++ -std=c++20 -fmodules-ts -x c++-system-header iostream
g++ -std=c++20 -fmodules-ts -x c++-system-header ranges
g++ -std=c++20 -fmodules-ts -x c++-system-header vector
g++ -std=c++20 -fmodules-ts -x c++-system-header array
g++ -std=c++20 -fmodules-ts -x c++-system-header string
g++ -std=c++20 -fmodules-ts -x c++-system-header functional
--------------
g++ -std=c++20 -fmodules-ts -x c++-system-header concepts
g++ -std=c++20 -fmodules-ts -x c++-system-header functional
g++ -std=c++20 -fmodules-ts -x c++-system-header ranges
g++ -std=c++20 -fmodules-ts -x c++-system-header vector
g++ -std=c++20 -fmodules-ts -x c++-system-header string
g++ -std=c++20 -fmodules-ts -x c++-system-header algorithm
--------------

Tried on last version from git:

commit e03e58c1844d04678f95b278f3eff2a5fbaeff7

g++ (GCC) 11.0.0 20210223 (experimental)

Revision history for this message
In , Alexander Lelyakin (alexander-lelyakin) wrote :

Another, shorter sequence:
----
g++ -std=c++20 -fmodules-ts -x c++-system-header new
g++ -std=c++20 -fmodules-ts -x c++-system-header initializer_list
g++ -std=c++20 -fmodules-ts -x c++-system-header typeinfo
g++ -std=c++20 -fmodules-ts -x c++-system-header type_traits
g++ -std=c++20 -fmodules-ts -x c++-system-header exception
----
/usr/local/include/c++/11.0.0/exception: internal compiler error: in write_cluster, at cp/module.cc:14600
0x6e2d56 module_state::write_cluster(elf_out*, depset**, unsigned int, depset::hash&, unsigned int*, unsigned int*)
 ../../gcc/gcc/cp/module.cc:14600
0xa62be8 module_state::write(elf_out*, cpp_reader*)
 ../../gcc/gcc/cp/module.cc:17734
0xa638fc finish_module_processing(cpp_reader*)
 ../../gcc/gcc/cp/module.cc:19860
0x9f72cb c_parse_final_cleanups()
 ../../gcc/gcc/cp/decl2.c:5175

Revision history for this message
In , Alexander Lelyakin (alexander-lelyakin) wrote :

I write a shell script to try to compile c++ system headers in random order:
Results so far:

Shortest sequences up to internal compiler error:
-----
type_traits
thread
-----
clocale
barrier
-----

Longest sequence is:
-----
stop_token
ccomplex
version
cassert
csetjmp
condition_variable
shared_mutex
csignal
map
cstdalign
bitset
scoped_allocator
codecvt
barrier
span
mutex
optional
ctgmath
cstdio
typeindex
cctype
cwctype
cfloat
iosfwd
iostream
----

Anyway there is no way to compile all system headers :(

Revision history for this message
In , Natoan (natoan) wrote :

99222 and 99223 filed. Please file each case as a separate issue. So far, they've all been different underlying causes.

It might make sense to have a meta-bug referring to this class of issue.

Changed in gcc:
status: In Progress → Fix Released
Revision history for this message
Matthias Klose (doko) wrote :

fixed, at least in hirsute-proposed

Changed in gcc-11 (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.