https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129041
Bug ID: 129041
Summary: [9/10/11/12/13/14/15/16/17 Regression] -fcompare-debug
failure (length) in insert_backedge_copies from stale
statement UIDs
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: compare-debug-failure
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: lzy20000419 at outlook dot com
CC: rguenth at gcc dot gnu.org
Target Milestone: ---
Fails with trunk (gcc 17.0.0 20261126, d1dbc89caa56) and with 9.1.0 through
16.2.0; 7.5.0 and 8.5.0 work.
Target: x86_64-pc-linux-gnu.
int n, t;
unsigned g;
void f (void)
{
unsigned x = 6, y = 5;
for (int i = 0; i < n; i++)
{
t = y + x;
y = g;
x = i;
g = i + 7u;
}
}
The test is expected to compile successfully with -fcompare-debug. On a native
x86_64-pc-linux-gnu build of GCC 17.0.0 20261126 (experimental), git commit
d1dbc89caa56, compiling with -O1 -fcompare-debug, -O2 -fcompare-debug or -O3
-fcompare-debug fails with: xgcc: error: t.c: '-fcompare-debug' failure
(length). The same failure occurs on 9.1.0 through 16.2.0. Compilation succeeds
at -O0 and -Os, and also at -O1 -fcompare-debug -fno-var-tracking-assignments.
7.5.0 and 8.5.0 compile successfully with -O1 -fcompare-debug.
The function has defined behavior. A small driver that calls f() with n = 0 and
n = 8 exits 0 when compiled at -O0 with -fsanitize=undefined,address and at -O1
and -O2.
Godbolt: https://godbolt.org/z/rKo6qePqM
insert_backedge_copies in tree-outof-ssa.cc uses stale statement UIDs because
maybe_renumber_stmts_bb numbers a block once and then clears bb->aux, so a
later inserted copy keeps UID 0 and the -g and -g0 compilations differ in
length.
This is not a duplicate of PR70359 or PR86270. Both are RESOLVED FIXED and
concerned code size or an extra register or instruction, not this compare-debug
length failure from stale statement UIDs.
A possible direction is to renumber statements in the block after
insert_backedge_copies inserts a copy, or to avoid leaving a newly inserted
copy with UID 0. I have not tested a patch.
Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.