This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix ICE on out-of-range array index
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 04 Mar 2009 03:39:59 -0300
- Subject: Re: Fix ICE on out-of-range array index
- References: <Pine.LNX.4.64.0903031409360.27439@digraph.polyomino.org.uk>
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