Bug 99153 - [11 Regression] ICE: depset::hash::make_dependency
Summary: [11 Regression] ICE: depset::hash::make_dependency
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: 11.0
Assignee: Nathan Sidwell
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 99227
  Show dependency treegraph
 
Reported: 2021-02-18 15:49 UTC by Matthias Klose
Modified: 2021-02-23 18:35 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 11.0
Last reconfirmed: 2021-02-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2021-02-18 15:49:55 UTC
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.
Comment 1 Nathan Sidwell 2021-02-19 13:21:48 UTC
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.
Comment 2 Nathan Sidwell 2021-02-19 22:35:33 UTC
// 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.
Comment 3 CVS Commits 2021-02-22 14:52:26 UTC
The master branch has been updated by Nathan Sidwell <nathan@gcc.gnu.org>:

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

commit r11-7322-gc49fcfddaa47f2828fe2af11ae857cd67f53e23f
Author: Nathan Sidwell <nathan@acm.org>
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.
Comment 4 Nathan Sidwell 2021-02-22 14:53:04 UTC
 c49fcfddaa4 2021-02-22 | c++: cross-header-unit template definitions [PR 99153] 

I have verified that iostream, utility and algorithm can be built
Comment 5 Alexander Lelyakin 2021-02-23 16:52:56 UTC
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)
Comment 6 Alexander Lelyakin 2021-02-23 17:04:12 UTC
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
Comment 7 Alexander Lelyakin 2021-02-23 17:34:48 UTC
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 :(
Comment 8 Nathan Sidwell 2021-02-23 18:01:40 UTC
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.