Created attachment 57822 [details] Preprocessed source The following C++ 20 code causes an ICE when compiled with -flto: #include <string_view> #include <array> inline constexpr auto make_it() { constexpr std::string_view view{"", 0}; std::array<char, 1> arr; arr[view.size()] = 'a'; // using 0 here won't cause an ICE return arr; } inline constexpr auto foo = make_it(); auto bar = foo; --- The same bug happens from GCC 10 to the current version listed as (trunc) on compiler-explorer: https://godbolt.org/z/xve6h5qhh. I'm using GCC 13.2.0 below. I've included the .ii file as the attachment. The code was compiled with g++ -std=c++20 foo.cpp -o foo.o -c -flto. Output of gcc -v -save-temps <all-your-options> <source-file>: Using built-in specs. COLLECT_GCC=gcc Target: x86_64-linux-gnu Configured with: /usr/src/gcc/configure --build=x86_64-linux-gnu --disable-multilib --enable-languages=c,c++,fortran,go Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-c' '-flto' '-freport-bug' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc/x86_64-linux-gnu/13.2.0/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE foo.cpp -mtune=generic -march=x86-64 -std=c++20 -flto -freport-bug -fpch-preprocess -o foo.ii ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/local/lib/gcc/x86_64-linux-gnu/13.2.0/include-fixed/x86_64-linux-gnu" ignoring nonexistent directory "/usr/local/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0 /usr/local/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/x86_64-linux-gnu /usr/local/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/backward /usr/local/lib/gcc/x86_64-linux-gnu/13.2.0/include /usr/local/include /usr/local/lib/gcc/x86_64-linux-gnu/13.2.0/include-fixed /usr/include/x86_64-linux-gnu /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-c' '-flto' '-freport-bug' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc/x86_64-linux-gnu/13.2.0/cc1plus -fpreprocessed foo.ii -quiet -dumpbase foo.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++20 -version -flto -freport-bug -o foo.s GNU C++20 (GCC) version 13.2.0 (x86_64-linux-gnu) compiled by GNU C version 13.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 4919020133b793ebcf160ec1288a96cd during IPA pass: modref foo.cpp:13:15: internal compiler error: in streamer_write_chain, at tree-streamer-out.cc:543 13 | auto bar = foo; | ^ 0x1c989f6 internal_error(char const*, ...) ???:0 0x75eba6 fancy_abort(char const*, int, char const*) ???:0 0x106eece streamer_write_tree_body(output_block*, tree_node*) ???:0 0xd18d4d DFS::DFS(output_block*, tree_node*, bool, bool, bool) ???:0 0xd1a1f9 lto_output_tree(output_block*, tree_node*, bool, bool) ???:0 0xd1cc43 produce_asm_for_decls() ???:0 0xd9c852 ipa_write_summaries() ???:0 0xa67be7 symbol_table::finalize_compilation_unit() ???:0 Please submit a full bug report, with preprocessed source. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. The bug is not reproducible, so it is likely a hardware or OS problem.
/* We avoid outputting external vars or functions by reference to the global decls section as we do not want to have them enter decl merging. We should not need to do this anymore because free_lang_data removes them from block scopes. */ gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
Reducing ...
Created attachment 57825 [details] Reduced most of the way (C++14 code now)
With my reduced testcase it worked in GCC 8.5.0 but started to ICE in GCC 9. Confirmed.
Created attachment 57826 [details] Reduced the rest of the way
Changing he return type of size to be size_t rather than size_type fixes the issue. So does adding: constexpr basic_string_view view; to the toplevel namespace.
The assert basically verifies free-lang-data does its job.
This can be downgraded from P1 given we released with it.
It was also reported against 13.2.
GCC 11 branch is being closed.
Note that this is not modref related - it is just last pass run before streaming. We miss some free lang data I guess. Will take a look