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,
>
> > I get an ICE with the following C++ testcase:
> >
> > void bar(unsigned int i)
> > {
> >         int a[4];
> >         char *p = (char*)&a[1] + 4*i;
> > }
> >

> however the cast should be done using fold_convert:
>
>  tem = try_move_mult_to_index (TREE_TYPE (arg0), PLUS_EXPR, arg0, arg1);
>  if (tem)
>    return fold (fold_convert (type, tem));

Ok, I prefer changing try_move_mult_to_index, though, as it touches
less places.  I'm currently boostrapping and testing the following patch:


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.502
diff -c -3 -p -r1.502 fold-const.c
*** fold-const.c	3 Feb 2005 06:44:34 -0000	1.502
--- fold-const.c	9 Feb 2005 13:10:10 -0000
*************** try_move_mult_to_index (tree type, enum
*** 6246,6252 ****
  					TREE_OPERAND (pos, 1),
  					delta));

!   return build1 (ADDR_EXPR, type, ret);
  }


--- 6246,6252 ----
  					TREE_OPERAND (pos, 1),
  					delta));

!   return fold_convert (type, build1 (ADDR_EXPR, TREE_TYPE (addr), ret));
  }




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