https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129298

            Bug ID: 129298
           Summary: [16/17 Regression] wrong code (ud2) at -O1: inline
                    predicate for __builtin_constant_p ((uintptr_t) param
                    + 8) ignores the ops between the parameter and the
                    argument
           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 <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 + 8;
  if (__builtin_constant_p (p) && (p & 7) == 0)
    exit (0);
  else if (__builtin_constant_p (length))
    exit (0);
  else
    exit (0);
}

int main () { foo (&d, sizeof (d)); return 0; }
```

Resulted in this output:
```
$ gcc -O1 repro.c && ./a.out
Illegal instruction (core dumped)
(also -Og and -O2/-O3 -fno-tree-vrp; every path calls exit (0), but main is a
single ud2; -O2, -O3 and -Os exit 0)
```

Trunk: https://godbolt.org/z/W1cs78zcr
- Trunk, GCC 16.2 and 16.1 give SIGILL; GCC 15.3, 15.2, 14.4, 13.4, 12.2 and
11.4 exit 0.

Reply via email to