https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129301
Bug ID: 129301
Summary: wrong code (ud2) at -O1 -fno-tree-forwprop: inline
predicates assume __builtin_constant_p ((uintptr_t)
&d) folds to 1, but without forwprop it folds to 0
(PR111036 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 (gcc.dg/torture/pr111036.c with a printf on each path):
```c
#include <stdio.h>
#include <stdlib.h>
__attribute__((aligned(32))) static struct
{
unsigned long long a[2];
} d;
static inline void __attribute__((always_inline))
foo (void *base, size_t length)
{
__UINTPTR_TYPE__ p = (__UINTPTR_TYPE__) base;
if (__builtin_constant_p (p) && (p & 31) == 0)
{ printf ("path 1\n"); exit (0); }
else if (__builtin_constant_p (length))
{ printf ("path 2\n"); exit (0); }
else
{ printf ("path 3\n"); exit (0); }
}
int main ()
{
foo (&d, sizeof (d));
return 0;
}
```
Resulted in this output:
```
$ gcc -O0 repro.c && ./a.out
path 3
$ gcc -O2 -fno-tree-forwprop repro.c && ./a.out
Illegal instruction (core dumped)
(also -O1/-O3/-Os -fno-tree-forwprop and -O2 -fdisable-tree-forwprop1; every
path calls exit (0), but main is compiled to a single ud2; plain -O2 exits 0)
```
Trunk: https://godbolt.org/z/e56fx7dT7
- Trunk gives SIGILL; GCC 15.1 and 14.2 exit 0; GCC 13.2 and 11.4 crash with
the original PR111036 symptom.