Right-shift bug in egcs-2.91.66
Timur Tabi
ttabi@interactivesi.com
Fri May 11 10:06:00 GMT 2001
An update: The problem goes away if I make test a volatile:
volatile u32 test = 0x12345678;
printk("0x%08lx%08lx\n", (u32)(test >> 32), (u32)test );
Obviously, this is a problem with the optimizer.
Now, I received a reply that says that "test >> 32" is undefined:
Per "The C Programming Language 2nd edition" appendix A7.8
Shift operators
"The result is undefined if the right operand is negative, or greater
than or equal to the number of bits in the left expression's type."
Well, this is stupid. Dividing by zero is undefined because mathematically
there are an infinite number of answers. But the above can easily be defined.
Shifting by equal or more than the number of bits in the operand results in zero.
It's very simple.
(IMHO, shifting by a negative number is equal to shifting in the opposite
direction by the positive, but I can understand why this might not be
implemented).
--
Timur Tabi - ttabi@interactivesi.com
Interactive Silicon - http://www.interactivesi.com
More information about the Gcc-bugs
mailing list