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.