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

            Bug ID: 125588
           Summary: Segmentation Fault on global integer initialised with
                    complex arithmetic
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lu.maltsis at postgrad dot manchester.ac.uk
  Target Milestone: ---

```sh
$ cat /tmp/bug.c
#include <stdint.h>
uint16_t a = 8 <= 0 % 0 ^
            7 >> ((6 >> 48 <= 10 / 2) % 48 % 48 ^ 10 / 2) % 64 % 10 ^
            6 >> 8 <= 0 &
                7 >> ((6 >> 48 <= 10 / 2) % 48 % 48 ^ 10 / 2) % 64 % 10;
```
This crashes with 
```sh
/tmp/bug.c:2:21: warning: division by zero [-Wdiv-by-zero]
    2 | uint16_t a = 8 <= 0 % 0 ^
      |                     ^
/tmp/bug.c:3:22: warning: right shift count >= width of type
[-Wshift-count-overflow]
    3 |             7 >> ((6 >> 48 <= 10 / 2) % 48 % 48 ^ 10 / 2) % 64 % 10 ^
      |                      ^~
/tmp/bug.c:5:26: warning: right shift count >= width of type
[-Wshift-count-overflow]
    5 |                 7 >> ((6 >> 48 <= 10 / 2) % 48 % 48 ^ 10 / 2) % 64 %
10;
      |                          ^~
gcc: internal compiler error: Segmentation fault signal terminated program cc1
Segmentation fault (core dumped)
```

https://godbolt.org/z/sWE7jf3aM

On trunk: bee542c,
https://github.com/gcc-mirror/gcc/commit/bee542c6b13fb08607dc03aadf5cd5eef5fe6642

Notably, changing the datatype to uint32_t or int:
```c
int a = 8 <= 0 % 0 ^
            7 >> ((6 >> 48 <= 10 / 2) % 48 % 48 ^ 10 / 2) % 64 % 10 ^
            6 >> 8 <= 0 &
                7 >> ((6 >> 48 <= 10 / 2) % 48 % 48 ^ 10 / 2) % 64 % 10;
```
Instead reports 
```sh
error: initializer element is not constant
```

This bug seems to be very brittle, the given reproduction scripts have been
creduced and I've made manual attempts to make them smaller.

Reply via email to