https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129294
Bug ID: 129294
Summary: [17 Regression] wrong code at -O2 -fwrapv /
-fno-strict-overflow: VN's wrapping-type fallback in
vn_nary_build_or_lookup_avail hands out a value with a
non-dominating leader's range (PR128747 fix
incomplete)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: 0599jiangyc at gmail dot com
Target Milestone: ---
The following code:
```c
unsigned g[4];
unsigned f0 (unsigned *p, int n, unsigned k)
{
if (n <= 0)
return k;
return *p ^ f0 (&g[3], n - 1, 0);
}
unsigned f1 (int n, unsigned k, unsigned u)
{
return f0 (&g[n & 3], n, k) >> (u & 7);
}
int main ()
{
unsigned h = 1;
for (int n = -1; n <= 7; n++)
h = h ^ f0 (&g[1], n, 3) ^ f1 (n, 85, (unsigned) n - 2);
if (h != 2)
__builtin_abort ();
return 0;
}
```
This is gcc.dg/torture/pr128747.c with the struct parameter removed.
Resulted in this output:
```
$ gcc -O2 -fwrapv repro.c && ./a.out
Aborted (core dumped)
(also -O3 -fwrapv and -O2 -fno-strict-overflow; -O2 without -fwrapv, -O1
-fwrapv and -O2 -fwrapv -fno-tree-pre exit 0)
```
Trunk: https://godbolt.org/z/vcxn493T8
- cgsnapshot aborts; GCC 16.2 and older are OK.
- Reproduced with unpatched upstream trunk d1dbc89caa5 of 2026-11-26.
- `-fno-strict-overflow` is the mode the Linux kernel is built with.