https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129296
Bug ID: 129296
Summary: [16/17 Regression] wrong code at -O2: ranger looks
through VIEW_CONVERT_EXPR of a speculated bool load
(PR121279 rewrite) and gives it the range [0, 1]
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
#include <stdbool.h>
struct V { int type; union { bool b; long long t; }; };
struct V s;
__attribute__((noipa)) int
f (int *a, int k)
{
int r = 0;
for (int i = 0; i < k; i++)
{
int x = 1;
if (a[i] == 3)
x = s.b;
r += x;
}
return r;
}
int
main (void)
{
s.t = -1;
int a[5] = { 0, 1, 2, 4, 5 };
if (f (a, 5) != 5)
__builtin_abort ();
return 0;
}
```
`a[i]` is never 3, so `s.b` is never read; the union holds `s.t == -1`.
Resulted in this output:
```
$ gcc -O2 repro.c && ./a.out
Aborted (core dumped)
(-O0 / -O1 / -Os exit 0; -O3 aborts; -fno-tree-loop-im, -fno-ssa-phiopt also
exit 0)
```
Trunk: https://godbolt.org/z/r4sv3cPz8.
- Also fails on GCC 16.1/16.2 (cg161, cg162) and GCC 14/15.
- On 14/15 it fails through the original, unfixed PR121279 path; GCC 13.2 and
11.4 are OK.
- Reproduced with unpatched upstream trunk d1dbc89caa5 of 2026-11-26.