This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Correctness question
On Tue, 8 Feb 2005 15:40:10 -0000, Dave Korn <dave.korn@artimi.com> wrote:
> > -----Original Message-----
> > From: gcc-owner On Behalf Of Richard Guenther
> > Sent: 08 February 2005 14:34
>
> > On Tue, 8 Feb 2005, Florian Weimer wrote:
> >
> > > * Richard Guenther:
> > >
> > > > Is it correct for the middle-end to transform
> > > >
> > > > void foo(int i)
> > > > {
> > > > int a[4];
> > > > if (&a[i] == &a[2147483648U])
> > > > abort();
> > > > if (i == 2147483648U)
> > > > abort();
> > > > }
> > >
> > > Is this valid C? I doubt that even a + 5 is a valid
> > expression (a + 4 is okay, though).
> >
> > Do you mean (char *)&a + 5?
>
> No, he's referring to the fact that it is illegal to index more than one
> element past the end of an array. You can take &a[4], but not dereference it
> legally, but you aren't even allowed to calculate &a[5] or greater.
Ah yes, I remember that. It probably makes it undefined or
implementation defined.
But I guess the question for the middle-end is wether
ADDR_EXPR(ARRAY_REF(base, offset))
is equivalent to ADDR_EXPR(base) + offset. So I guess the middle-end
doesn't care
about wether offset is greater than the size of the array.
Richard.