On Wed, 16 Feb 2005, Paul Schlie wrote:

> > Richard Guenther wrote:
> > While trying to implement folding of &a +- cst to &a[c] I came
> > along the C frontend, which for
> >
> >   int a[4];
> >   int *p = &a[-1];
> >
> > produces
> >
> >   p = &a + (int *)-4;
>
> Would guess it should be:
>
>    p = &a - (int *)4;
>
> or even:
>
>    p = &a + - (int *)4;

Yes, of course, but it is the C frontent that is producing
&a + (int *)-4, not me.  I'm just trying to work around this...

In fact, it is c-common.c:2289 that does -4  ->  (int *)-4
conversion, but pointer_int_sum is already called with PLUS_EXPR.
build_unary_op unconditionally expands &x[y] to x+y, regardless
of the sign of y.  Of course the standard says that they are equal.
But is &x[-1] == x + (int *)4*(int *)-1 ?  From this follows that
we have no way to convert this back to &x[-1], as we loose the
sign information by the (int *) cast.

How do the loop optimizers handle this - negative offsets by relying
on unsigned pointer wrap-around?

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/

Reply via email to