https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127340
Bug ID: 127340
Summary: [modules] ICE in import_export_decl when including
gcc-plugin.h before importing std
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mail at tobiasliese dot me
Target Milestone: ---
Including <gcc-plugin.h> in a global module fragment and then importing
std causes an internal compiler error.
Reproducer (repro.cpp):
module;
#include <gcc-plugin.h>
export module repro;
import std;
Commands to reproduce with GCC 16, starting in a fresh directory:
g++ -std=c++26 -fmodules-ts -fmodule-only -x c++ \
-c /usr/include/c++/16/bits/std.cc
g++ -std=c++26 -fmodules-ts \
-I/usr/lib/gcc/x86_64-pc-linux-gnu/16/plugin/include \
-c repro.cpp
Actual result:
For GCC 16:
-freport-bug -std=c++26 -fmodules-ts
-I/usr/lib/gcc/x86_64-pc-linux-gnu/16/plugin/include -c repro.cpp
In file included from /usr/include/c++/16/bits/memoryfwd.h:50,
from /usr/include/c++/16/memory:65,
from
/usr/lib/gcc/x86_64-pc-linux-gnu/16/plugin/include/system.h:231,
from
/usr/lib/gcc/x86_64-pc-linux-gnu/16/plugin/include/gcc-plugin.h:28,
from repro.cpp:2:
/usr/include/c++/16/bits/max_size_type.h: In member function
‘std::basic_ostream<_CharT, _Traits>::__ostream_type&
std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT
= char; _Traits = std::char_traits<char>; __ostream_type =
std::basic_ostream<char>]’:
/usr/include/c++/16/bits/max_size_type.h:204:9: internal compiler error: in
import_export_decl, at cp/decl2.cc:3870
204 | __glibcxx_assert(__r <= _S_rep_bits);
| ^~~~~~~~~~~~~~~~
0x2815bf8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2818207 internal_error(char const*, ...)
???:0
0x7379dd fancy_abort(char const*, int, char const*)
???:0
0x9d0a96 expand_or_defer_fn(tree_node*)
???:0
0x8a56a4 module_state::read_cluster(unsigned int)
???:0
0x8b3755 module_state::load_section(unsigned int, binding_slot*)
???:0
0x8b3805 module_state::lazy_load(unsigned int, binding_slot*)
???:0
0x8b3c35 lazy_load_pendings(tree_node*, tree_node*)
???:0
0x980ba7 instantiate_decl(tree_node*, bool, bool)
???:0
0x98934d instantiate_pending_templates(int)
???:0
0x82d17e c_parse_final_cleanups()
???:0
0xaa564a c_common_parse_file()
???:0
/usr/lib/gcc/x86_64-pc-linux-gnu/16/cc1plus -quiet -I
/usr/lib/gcc/x86_64-pc-linux-gnu/16/plugin/include -D_GNU_SOURCE repro.cpp
-quiet -dumpbase repro.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64
-std=c++26 -freport-bug -fmodules -o /tmp/ccnXqKsI.s
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues>
for instructions.
Preprocessed source stored into /tmp/ccq5Z5Dj.out file, please attach this to
your bugreport.
For GCC 17:
"$CXX" -freport-bug -std=c++26 -fmodules-ts
-I/opt/gcc-17-20260906/lib/gcc/x86_64-pc-linux-gnu/17.0.0/plugin/include -c
repro.cpp
In file included from
/opt/gcc-17-20260906/include/c++/17.0.0/bits/memoryfwd.h:50,
from /opt/gcc-17-20260906/include/c++/17.0.0/memory:65,
from
/opt/gcc-17-20260906/lib/gcc/x86_64-pc-linux-gnu/17.0.0/plugin/include/system.h:242,
from
/opt/gcc-17-20260906/lib/gcc/x86_64-pc-linux-gnu/17.0.0/plugin/include/gcc-plugin.h:28,
from repro.cpp:2:
/opt/gcc-17-20260906/include/c++/17.0.0/bits/max_size_type.h: In member
function ‘std::basic_ostream<_CharT, _Traits>::__ostream_type&
std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT
= char; _Traits = std::char_traits<char>; __ostream_type =
std::basic_ostream<char>]’:
/opt/gcc-17-20260906/include/c++/17.0.0/bits/max_size_type.h:204:9: internal
compiler error: in import_export_decl, at cp/decl2.cc:3871
204 | __glibcxx_assert(__r <= _S_rep_bits);
| ^~~~~~~~~~~~~~~~
0x2e5ce5f internal_error(char const*, ...)
/home/tobias/gcc_build/../gcc/gcc/diagnostic-global-context.cc:787
0xbd2fa7 fancy_abort(char const*, int, char const*)
/home/tobias/gcc_build/../gcc/gcc/diagnostics/context.cc:1813
0x887c6c import_export_decl(tree_node*)
/home/tobias/gcc_build/../gcc/gcc/cp/decl2.cc:3871
0xee933d expand_or_defer_fn_1(tree_node*)
/home/tobias/gcc_build/../gcc/gcc/cp/semantics.cc:5701
0xef5aba expand_or_defer_fn_1(tree_node*)
/home/tobias/gcc_build/../gcc/gcc/cp/semantics.cc:5683
0xef5aba expand_or_defer_fn(tree_node*)
/home/tobias/gcc_build/../gcc/gcc/cp/semantics.cc:5757
0xd9fce2 module_state::read_cluster(unsigned int)
/home/tobias/gcc_build/../gcc/gcc/cp/module.cc:17848
0xda06df module_state::load_section(unsigned int, binding_slot*)
/home/tobias/gcc_build/../gcc/gcc/cp/module.cc:21633
0xda0796 module_state::lazy_load(unsigned int, binding_slot*)
/home/tobias/gcc_build/../gcc/gcc/cp/module.cc:22662
0xda4b3a lazy_load_pendings(tree_node*, tree_node*)
/home/tobias/gcc_build/../gcc/gcc/cp/module.cc:22763
0xeb0577 instantiate_decl(tree_node*, bool, bool)
/home/tobias/gcc_build/../gcc/gcc/cp/pt.cc:29062
0xebb1cb instantiate_pending_templates(int)
/home/tobias/gcc_build/../gcc/gcc/cp/pt.cc:29357
0xd05778 c_parse_final_cleanups()
/home/tobias/gcc_build/../gcc/gcc/cp/decl2.cc:5894
0xfe3f10 c_common_parse_file()
/home/tobias/gcc_build/../gcc/gcc/c-family/c-opts.cc:1455
/opt/gcc-17-20260906/bin/../libexec/gcc/x86_64-pc-linux-gnu/17.0.0/cc1plus
-quiet -I
/opt/gcc-17-20260906/lib/gcc/x86_64-pc-linux-gnu/17.0.0/plugin/include -iprefix
/opt/gcc-17-20260906/bin/../lib/gcc/x86_64-pc-linux-gnu/17.0.0/ -D_GNU_SOURCE
repro.cpp -quiet -dumpbase repro.cpp -dumpbase-ext .cpp -mtune=generic
-march=x86-64 -std=c++26 -freport-bug -fmodules -o /tmp/ccyymRLn.s
Expected result:
Compilation without an internal compiler error.
Confirmed with:
- GCC 16.2.1 20260810 (Arch Linux), x86_64-pc-linux-gnu.
- GCC 17.0.0 20260906 (experimental), x86_64-pc-linux-gnu.
This version fails in import_export_decl at cp/decl2.cc:3871.
Each compiler was tested with its own plugin headers and a freshly built
std module. No CMake, reflection, contracts, or optimization flags are
needed.
Possibly related: PR122774. However, that report concerns includes after
imports and an ICE in lookup_mark involving hidden builtin declarations.
This reproducer includes the header before the import and crashes in
import_export_decl instead.