Hi,
I'm having fun with arrays in Ada ;) and wondering if anyone can tell me what's
right here.
Ada ACATS c64106a contains code with an array type whose indices run from -1 to
1. (That is, three elements.)
In GCC this gets represented as an ARRAY_TYPE, whose TYPE_DOMAIN is a 32-bit
signed integer type; the TYPE_MAX_VALUE of this is 1 (as a size_int), the
TYPE_MIN_VALUE of this is -1 as a size_int, i.e. 4294967295. I believe using
(unsigned 32-bit) size_int for min/max is correct (?) despite the domain being a
signed type.
An array of this type is then initialized with a CONSTRUCTOR. The CONSTRUCTOR
has three elements, with INTEGER_CST indices, being in order 2^32-1, 0, 1 (all
of sizetype).
I substitute the CONSTRUCTOR into an ARRAY_REF <blah>[4294967295]{lb: 4294967295
sz: 2}, i.e. that picks the element with index (sizetype)2^32-1.
fold() in fold-const.c then fails to fold, because it does binary search for
2^32-1 through the constructor elements, and first checks against the middle
CONSTRUCTOR_ELT, which has index 0.
So, where's the bug here? Should all these indices have sizetype? Should
fold-const.c's binary search respect the TYPE_DOMAIN of the type of the
CONSTRUCTOR being searched? (Lots of build_int_cst to reinterpret the
CONSTRUCTOR_ELT indices, and/or the index being searched for, in said TYPE_DOMAIN ?)
Advice appreciated!
Thanks, Alan