public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/43249] New: unsigned int arg with no prototype gets full 64-bit reg
@ 2010-03-03 19:11 janis at gcc dot gnu dot org
2010-03-10 18:35 ` [Bug target/43249] " janis at gcc dot gnu dot org
2010-05-26 13:23 ` amodra at gmail dot com
0 siblings, 2 replies; 4+ messages in thread
From: janis at gcc dot gnu dot org @ 2010-03-03 19:11 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <bug-43249-4@http.gcc.gnu.org/bugzilla/>]
end of thread, other threads:[~2012-04-20 14:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-03 19:11 [Bug target/43249] New: unsigned int arg with no prototype gets full 64-bit reg janis at gcc dot gnu dot org
2010-03-10 18:35 ` [Bug target/43249] " janis at gcc dot gnu dot org
2010-05-26 13:23 ` amodra at gmail dot com
[not found] <bug-43249-4@http.gcc.gnu.org/bugzilla/>
2012-04-20 14:46 ` wschmidt at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).