This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Tree CONSTRUCTORs and Ada array indices

On Wed, Oct 14, 2015 at 2:54 PM, Alan Lawrence <> wrote:
> 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.

I _think_ I fixed all (most?) of the assumptions about TYPE_DOMAIN
being unsigned
(and its min/max value).  So using a signed min/max should be ok (and
desired) here.

> 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

Which fold-const.c code?  fold_array_ctor_reference?  I believe that nothing
guarantees that CONSTRUCTOR elements are ordered, thus binary search
wouldn't work anyway.


  int a[] = { [5] = 1, [1] = 7, [7] = 3 };

for example.

Ah, the code in fold() itself?  I think you should just remove it / integrate it
with fold_array_ctor_reference.


> Advice appreciated!
> Thanks, Alan

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]