]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fix assertion failure on small array constructor
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 6 Jun 2025 09:32:51 +0000 (11:32 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Fri, 6 Jun 2025 09:39:40 +0000 (11:39 +0200)
commit61b014f614be523174f6a9df6e1fbac11de11abd
tree299dc7d40bb49896187fbb55804035952cdf655e
parent572dd0dd8db4bec69883c0b3e53013a7842e886e
Fix assertion failure on small array constructor

The Ada testcase triggers an assertion failure in size_binop_loc:

+===========================GNAT BUG DETECTED==============================+
| 16.0.0 20250605 (experimental) (x86_64-suse-linux) GCC error:            |
| in size_binop_loc, at fold-const.cc:2091                                 |
| Error detected around aggr7.ads:9:36

  gcc_assert (int_binop_types_match_p (code, TREE_TYPE (arg0),
                                       TREE_TYPE (arg1)));

because the very old code for ARRAY_TYPE in store_constructor is confused in
the case where it cannot perform static host-based arithmetics on offsets.

But the root cause is that it performs all the calculations in signed
sizetype while TYPE_DOMAIN is supposed to be a subtype of (unsigned)
sizetype, even for signed index types in Ada like in the testcase,
so the code takes the dynamic path instead of the static one for
negative indices.

gcc/
* expr.cc (store_constructor) <ARRAY_TYPE>: Perform the arithmetics
on offsets in (unsigned) sizetype.

gcc/testsuite/
* gnat.dg/specs/aggr7.ads: New test.
gcc/expr.cc
gcc/testsuite/gnat.dg/specs/aggr7.ads [new file with mode: 0644]