This is the mail archive of the gcc-patches@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: Fix ICE on out-of-range array index


On Mar  3, 2009, "Joseph S. Myers" <joseph@codesourcery.com> wrote:

> +      offset = (((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) offset << shift))
> +		>> shift);

Right-shift of negative values is implementation-defined, better not
rely on it for sign extension.

> +      offset = (((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) offset << shift))
> +		>> shift);
  
It's more portable to use the ^/- idiom:

if (width < widthof HOST_WIDE_INT) {
  unsigned HOST_WIDE_INT sign_bit = 1;
  sign_bit <<= (width - 1);
  offset = (((unsigned HOST_WIDE_INT)offset ^ sign_bit) - sign_bit);
}

-- 
Alexandre Oliva           http://www.lsd.ic.unicamp.br/~oliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer


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