This is the mail archive of the gcc@gcc.gnu.org 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: fold: &a[i1] + c * i2 -> &a[i1 + i2] messing up types


On Wed, 9 Feb 2005, Zdenek Dvorak wrote:

> Hello,
>
> > Consider (C++)
> >
> > int a[1024];
> >
> > int *foo(unsigned short i, long long int j)
> > {
> >         return &a[i]+j;
> > }
> >
> > transformed to
> >
> > int* foo(short unsigned int, long long int) (i, j)
> > {
> >   int * D.1567;
> >   int D.1568;
> >   unsigned int D.1569;
> >   unsigned int D.1570;
> >
> >   D.1568 = (int) i;
> >   D.1569 = (unsigned int) j;
> >   D.1570 = D.1568 + D.1569;
> >   D.1567 = &a[D.1570];
> >   return D.1567;
> > }
> >
> > is the cast of j to (unsigned int) working by pure luck - what about
> > j == -1?
>
> then j will be casted to unsigned int.  That's perfectly ok.

Indeed.  I missed that pointers are unsigned.

Richard.

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


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