Invalid right shift in genautomata.c
Vladimir Makarov
vmakarov@redhat.com
Thu May 23 15:00:00 GMT 2002
Vladimir Makarov wrote:
>
> Neil Booth wrote:
> >
> > Vladimir Makarov wrote:-
> >
> > > Actually this is not a bug, Neil. The shift is not used when compiler
> > > generates the message (it is even gone after dead code elimination).
> > >
> > > To speed up genautomata, all bit operations are executed on
> > > HOST_WIDE_INT. This type is used also to hash the bitstring. Htab uses
> > > unsigned as a hash key. So I need to convert HOST_WIDE_INT into
> > > unsigned. I could make it by `(unsigned) key'. But that would result
> > > in bad hash keys when the number units > sizeof (unsigned) * CHAR_BIT.
> > > Therefore I hash HOST_WIDE_INT using the shift. But it is made only
> > > when sizeof (unsigned) < sizeof (HOST_WIDE_INT).
> >
> > Ah, OK. It's a shame we still get the message.
> >
>
> Ok, I'll try fix it in another way.
Here is the patch fixing the warning. I think it generates the better
hash too. I've committed it into the mainline.
Vlad
2002-05-23 Vladimir Makarov <vmakarov@redhat.com>
* genautomata.c (reserv_sets_hash_value): Use shift equal to 3/4
of size of unsigned.
Index: genautomata.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/genautomata.c,v
retrieving revision 1.13
diff -c -p -r1.13 genautomata.c
*** genautomata.c 21 May 2002 23:27:04 -0000 1.13
--- genautomata.c 23 May 2002 21:53:38 -0000
*************** reserv_sets_hash_value (reservs)
*** 3413,3422 ****
if (sizeof (set_el_t) <= sizeof (unsigned))
return hash_value;
result = 0;
! for (i = sizeof (set_el_t); i > 0; i -= sizeof (unsigned))
{
result += (unsigned) hash_value;
! hash_value >>= sizeof (unsigned) * CHAR_BIT;
}
return result;
}
--- 3413,3422 ----
if (sizeof (set_el_t) <= sizeof (unsigned))
return hash_value;
result = 0;
! for (i = sizeof (set_el_t); i > 0; i -= sizeof (unsigned) - 1)
{
result += (unsigned) hash_value;
! hash_value >>= (sizeof (unsigned) - 1) * CHAR_BIT;
}
return result;
}
More information about the Gcc-bugs
mailing list