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

            Bug ID: 128606
           Summary: ICE in c_parser_gimple_postfix_expression caused by
                    _Literal of scalable vector type
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Chris.Bazley at arm dot com
  Target Milestone: ---

GCC encounters an internal compiler error when parsing a nonuniform scalable
vector constant in a `__GIMPLE` function.

The failure occurs in `c_parser_gimple_postfix_expression`, where
`TYPE_VECTOR_SUBPARTS (type).to_constant()` is used to determine the initial
allocation size of a vector constructor.

For scalable vector types, `TYPE_VECTOR_SUBPARTS` is polynomial, so
`to_constant()` fails.

**Reproducer:**

```c
#include <arm_sve.h>

svuint8_t __GIMPLE (startwith ("expand"))
foo (void)
{
  svuint8_t v;

  v = _Literal (svuint8_t) {
    1, 2, 1, 2, 1, 2, 1, 0,
    0, 0, 0, 0, 0, 0, 0, 0
  };

  return v;
}
```

**Compilation options:**

```
-O2 -fgimple -march=armv8.2-a+sve -msve-vector-bits=scalable
```

**Observed result:**

```
internal compiler error: in to_constant, at poly-int.h:592
```

**Expected result:**

The compiler should accept the scalable vector constant or issue a diagnostic
if the constructor is unsupported, rather than terminate with an internal
compiler error.

**Possible fix:**

Replacing `TYPE_VECTOR_SUBPARTS (type).to_constant()` with
`constant_lower_bound (TYPE_VECTOR_SUBPARTS (type)` avoids the ICE and allows
the reproducer to compile successfully and produce the following expected
output:
```
svuint8_t foo ()
{
  svuint8_t v;

  v = { 1, 2, 1, 2, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, ... };
  return v;
}
```

Further testing is needed to establish whether this is sufficient for all
scalable vector constructors.

Reply via email to