Bug 114501 - [12/13/14/15 Regression] ICE during lto streaming
Summary: [12/13/14/15 Regression] ICE during lto streaming
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 13.2.0
: P2 normal
Target Milestone: 12.5
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, lto
Depends on:
Blocks:
 
Reported: 2024-03-27 20:55 UTC by Johannes Grunenberg
Modified: 2024-07-22 14:11 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 8.5.0
Known to fail: 9.1.0
Last reconfirmed: 2024-03-28 00:00:00


Attachments
Preprocessed source (62.73 KB, text/plain)
2024-03-27 20:55 UTC, Johannes Grunenberg
Details
Reduced most of the way (C++14 code now) (329 bytes, text/plain)
2024-03-28 02:56 UTC, Andrew Pinski
Details
Reduced the rest of the way (197 bytes, text/plain)
2024-03-28 03:03 UTC, Andrew Pinski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Grunenberg 2024-03-27 20:55:31 UTC
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.
Comment 1 Andrew Pinski 2024-03-28 01:55:49 UTC
      /* 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));
Comment 2 Andrew Pinski 2024-03-28 02:29:09 UTC
Reducing ...
Comment 3 Andrew Pinski 2024-03-28 02:56:19 UTC
Created attachment 57825 [details]
Reduced most of the way (C++14 code now)
Comment 4 Andrew Pinski 2024-03-28 02:58:16 UTC
With my reduced testcase it worked in GCC 8.5.0 but started to ICE in GCC 9.

Confirmed.
Comment 5 Andrew Pinski 2024-03-28 03:03:55 UTC
Created attachment 57826 [details]
Reduced the rest of the way
Comment 6 Andrew Pinski 2024-03-28 03:05:36 UTC
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.
Comment 7 Richard Biener 2024-03-28 08:06:46 UTC
The assert basically verifies free-lang-data does its job.
Comment 8 Sam James 2024-04-08 09:44:47 UTC
This can be downgraded from P1 given we released with it.
Comment 9 Richard Biener 2024-04-08 09:50:25 UTC
It was also reported against 13.2.
Comment 10 Richard Biener 2024-07-19 13:24:15 UTC
GCC 11 branch is being closed.
Comment 11 Jan Hubicka 2024-07-22 14:11:16 UTC
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