This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Tree CONSTRUCTORs and Ada array indices
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Alan Lawrence <alan dot lawrence at arm dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Wed, 14 Oct 2015 16:11:24 +0200
- Subject: Re: Tree CONSTRUCTORs and Ada array indices
- Authentication-results: sourceware.org; auth=none
- References: <561E5069 dot 6020901 at arm dot com>
On Wed, Oct 14, 2015 at 2:54 PM, Alan Lawrence <alan.lawrence@arm.com> 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
> TYPE_DOMAIN ?)
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.
Try
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.
Richard.
> Advice appreciated!
>
> Thanks, Alan
>