[Bug target/43249] New: unsigned int arg with no prototype gets full 64-bit reg
janis at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Wed Mar 3 19:11:00 GMT 2010
For a function with no prototype that defines an argument as unsigned
int, GCC for powerpc64-linux with -m64 and optimization uses the
entire 64-bit argument register rather than masking off the lower
32 bits. This problem was discoverd with 176.gcc using options
"-m64 -O2 -ftree-vectorize -maltivec -fdata-sections", which changed
the order of 32-element arrays so that accessing element 63 instead of
element 31 started getting garbage that no longer happened to work.
Here's a simple testcase that works with -O0 and fails with -O1.
It's useful to compare this with a a version whose argument is
unsigned short. For the GCC testsuite, just remove references to
printf.
-------------------------------------------------------------------
extern int printf (const char *, ...);
int
__attribute__((noinline))
floor_log2_wide (x)
unsigned int x;
{
int log = -1;
while (x != 0)
log++,
x >>= 1;
return log;
}
int
main ()
{
int m;
unsigned int n = 4294967259U;
m = floor_log2_wide ((int)n);
printf ("n = %u, m = %d\n", n, m);
if (m != 31)
__builtin_abort ();
return 0;
}
-------------------------------------------------------------------
elm3c105% /home/janis/tools/gcc-trunk-anonsvn/bin/gcc -m64 -O0 bug.c && ./a.out
n = 4294967259, m = 31
elm3c105% /home/janis/tools/gcc-trunk-anonsvn/bin/gcc -m64 -O1 bug.c && ./a.out
n = 4294967259, m = 63
Aborted
I've tried compilers back to GCC 4.1 and they all have the same problem;
it's probably not a regression.
--
Summary: unsigned int arg with no prototype gets full 64-bit reg
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: janis at gcc dot gnu dot org
GCC target triplet: powerpc64-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43249
More information about the Gcc-bugs
mailing list