This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/14642] New: y<<n where n==32 does not yield zero on x86
- From: "nasix at raytheon dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Mar 2004 21:25:17 -0000
- Subject: [Bug c/14642] New: y<<n where n==32 does not yield zero on x86
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
One would expect y << n, where y is any int and n==sizeof(int)*8, would yield
zero, but for the x86 target, the result is y. This is due to the x86 shl
opcode taking the count modulo 32 rather than modulo 64 as with PPC or 68K. The
code generator ought to limit the shift count generally, and for the case of
n==sizeof(int)*8, simply return zero. This illustrates the problem:
#include <assert.h>
/* Demonstrates whether C compiler properly shifts
the operand by the # of bits an integer occupies.
x86 and MIPS shift count are modulo-32, so they will fail this test.
*/
typedef long INT_T;
/* use function to keep optimizer out of it */
static INT_T shift(const INT_T x,const unsigned count)
{
return x << count;
}
int main()
{
assert(shift(1,sizeof(INT_T)*8) == (INT_T)0);
return 0;
}
--
Summary: y<<n where n==32 does not yield zero on x86
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P1
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nasix at raytheon dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-cygwin
GCC host triplet: i686-pc-cygwin
GCC target triplet: i686-pc-cygwin
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14642