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,
>
> > > > If you prefer removing the type argument that would be fine, too.
> > >
> > > this might be a good idea, yes.
> >
> > Actually, in
> >
> > 	  step = array_ref_element_size (ref);
> >
> > 	  if (TREE_CODE (step) != INTEGER_CST)
> > 	    continue;
> >
> > 	  itype = TREE_TYPE (step);
> >
> > 	  /* If the type sizes do not match, we might run into problems
> > 	     when one of them would overflow.  */
> > 	  if (TYPE_PRECISION (itype) != TYPE_PRECISION (type))
> > 	    continue;
> >
> > 	  if (!operand_equal_p (step, fold_convert (itype, s), 0))
> > 	    continue;
> >
> > do you really mean to compare TYPE_PRECISION (itype) and TYPE_PRECISION
> > (type)?  I think type should refer to TREE_TYPE (s) here, not to
> > TREE_TYPE (addr), no?
>
> they have the same size.

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?
It seems at least the frontend is promoting the unsigned short to int
for the array index.

Note that the type returned by array_ref_element_size() seems to
be unsigned int always.

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]