https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129221
Bug ID: 129221
Summary: ICE in lhd_decl_printable_name during IPA pass
static-var with -flto -fdump-ipa-static-var and a
namespace-scope structured binding
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: lzy20000419 at outlook dot com
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Fails with trunk (gcc 17.0.0 20261201, afe83e260737) and with every tested
release from 7.5.0 to 16.2.0. Target: x86_64-pc-linux-gnu.
struct S { int a; double b; };
S get () { return { 1, 2.0 }; }
auto [x, y] = get ();
int main () { return 0; }
g++ -std=c++17 -O2 -flto -fdump-ipa-static-var t.cpp
during IPA pass: static-var
lto1: internal compiler error: in lhd_decl_printable_name, at
langhooks.cc:227
lto-wrapper: fatal error: g++ returned 1 exit status
compilation terminated.
ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
Expected: the program compiles and links, and the dump is written.
The ICE is in the WPA stage (lto1 -fwpa). -fdump-ipa-all fails the same way.
Without -fdump-ipa-static-var, or at -O0, or without -flto, the program
compiles and links fine. Releases report the same assert; only the line number
in langhooks.c or langhooks.cc changes.
The structured binding is needed: with S s = get (); instead of auto [x, y] =
get (); the same command compiles and links fine.
Godbolt (trunk): https://godbolt.org/z/WdMfd6Trd
When the dump file is open, ipa_reference_read_optimization_summary in
ipa-reference.cc prints each variable of the "all module statics" set with
fndecl_name (v_decl). In lto1 this goes to the default lhd_decl_printable_name,
which asserts DECL_NAME (decl). The problem seems to be that this dump code
does not expect a variable without a DECL_NAME, such as the unnamed variable
that holds the structured binding object. I have not tested a patch.
Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.