https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129150
Bug ID: 129150
Summary: ICE in ipa_comdats, at ipa-comdats.cc:356 with -O2
-flto
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: voelker at embedded dot rwth-aachen.de
Target Milestone: ---
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Created attachment 66334
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66334&action=edit
Reduced testcase, TU 1 of 2 (compile both with -O2 -flto and link together)
Linking two C++ translation units with -O2 -flto ICEs during WPA:
$ g++ -O2 -flto -c a.ii -o a.o
$ g++ -O2 -flto -c b.ii -o b.o
$ g++ -O2 -flto a.o b.o -o x
lto1: internal compiler error: in ipa_comdats, at ipa-comdats.cc:356
0x2256cab diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x224f4a5 internal_error(char const*, ...)
???:0
0x7addd7 fancy_abort(char const*, int, char const*)
???:0
0x20f99ef (anonymous namespace)::pass_ipa_comdats::execute(function*)
???:0
lto-wrapper: fatal error: g++ returned 1 exit status
compilation terminated.
ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
The reduced testcase (manual and cvise) leaves several functions undefined, so
without the ICE the link fails with undefined
references. The original program was complete and valid.
The testcase relies on C++20 (the GCC 16 default). With older GCCs, add
-std=gnu++20: 14.2.1, 14.3.0, 15.2.0 and 15.3.0 then get through LTO and
stop at the expected undefined references, with no ICE. Not tested on trunk.
It reproduces reliably. It ICEs with -no-pie as well as with PIE, and also
with -fwhole-program, -flto-partition=one, -flto-partition=none,
-fno-ipa-icf, -fno-ipa-sra, -fno-ipa-modref, -fno-ipa-vrp and
-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations.
There is no ICE with any of:
-fno-devirtualize-speculatively, -fno-devirtualize, -fno-ipa-cp,
-fno-inline, -fno-early-inlining, -fno-ipa-pure-const,
-fno-use-linker-plugin, -O3, or when linking with -shared or -r.
The testcase is very sensitive to code size and inlining. For example,
replacing any one of the three __builtin_trap() calls with a return
statement makes the ICE go away.
=== gcc -v ===
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-16.2.0/configure
--prefix=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-16.2.0
--with-gmp-include=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gmp-with-cxx-6.3.0-dev/include
--with-gmp-lib=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gmp-with-cxx-6.3.0/lib
--with-mpfr-include=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpfr-4.2.2-dev/include
--with-mpfr-lib=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpfr-4.2.2/lib
--with-mpc=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-libmpc-1.4.1
--with-native-system-header-dir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-glibc-2.44-57-dev/include
--with-build-sysroot=/
--with-gxx-include-dir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gcc-16.2.0/include/c++/16.2.0/
--program-prefix= --enable-lto --disable-libstdcxx-pch
--without-included-gettext --with-system-zlib --enable-static
--enable-languages=c,c++ --disable-multilib --enable-plugin
--with-isl=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-isl-0.20
--disable-bootstrap --enable-default-pie --build=x86_64-unknown-linux-gnu
--host=x86_64-unknown-linux-gnu --target=x86_64-unknown-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.2.0 (GCC)
This is the NixOS (nixpkgs) build of GCC. Its compiler wrapper adds
-fPIE -pie -fcf-protection=none -fno-omit-frame-pointer
-mno-omit-leaf-frame-pointer -mtls-dialect=gnu2. The ICE does not depend
on PIE or on the frame-pointer flags (checked with -no-pie -fno-PIE and with
-fomit-frame-pointer).