------- Comment #7 from rakdver at gcc dot gnu dot org 2010-07-26 14:47 -------
By the time the code reaches ivopts, it looks (modulo SSA form) this way:
signed char x = -128, tmp;
for (;;)
{
tmp = -x;
foo ((int) x, (int) tmp, x==-128);
...
if (x == 127)
break;
x++;
}
Note that all the careful handling of -x in case that x=-128 disappeared.
Then, ivopts trust that signed arithmetics does not overflow, and misscompile
the program. In fact, it seems that the error is already there at the very
beginning: the .original dump shows
fixnum_neg
{
ux = (unsigned char) x;
uy = (unsigned char) -(signed char) ux;
...
}
That is, the negation of unsigned char value is implemented by casting it to
signed char, which introduces signed overflow if the value of x is -128. As
far as I understand the C standard, this seems incorrect.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45034