[Bug c/55967] New: rightshift an unsigned value (X) by it's number of bits does not always yield 0, when X is an unsigned that's leftshifted by it's number of bits and offset
b1262178 at rmqkr dot net
gcc-bugzilla@gcc.gnu.org
Mon Jan 14 12:44:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55967
Bug #: 55967
Summary: rightshift an unsigned value (X) by it's number of
bits does not always yield 0, when X is an unsigned
that's leftshifted by it's number of bits and offset
Classification: Unclassified
Product: gcc
Version: 4.6.2
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: b1262178@rmqkr.net
Hi,
I'm curring gcc via MinGW on a 32 bit PC:
The output of the following
/********************************************/
#include <stdio.h>
int main(void)
{
printf("%lu\n", ((1U<<(32))));
printf("%lu\n", ((1U<<(32))) + 0x80000000U);
printf("%lu\n", (((1U<<(32))) + 0x80000000U) >> 32U); /* expecting 0 but get
0x80000000U instead. BUG???? */
printf("%lu\n", ( 0x80000000U) >> 32U); /* compare: here
correctly get 0! */
printf("%lu\n", (((1U<<(32))) ) >> 32U); /* compare: here
correctly get 0! */
return 0;
return 0;
}
/********************************************/
is:
0
2147483648
2147483648 // Bug!
0
0
THE 3rd output line IS A BUG, right? I expect to get 0.
And why do I expect 0. Because I've got a 32-bit number and rightshift it by
32.
Ouput lines 4 and 5 do that correctly: they yield 0.
So what's going on in line 3 ?
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure
--enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions
--with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry
--enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32
--prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)
Thanks.
More information about the Gcc-bugs
mailing list