This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
-O2 bug in gcc 3.2, 3.3 and 3.4 with 64 bit integers on x86
- From: Anders Torger <torger at ludd dot luth dot se>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 9 Nov 2004 16:42:01 +0100
- Subject: -O2 bug in gcc 3.2, 3.3 and 3.4 with 64 bit integers on x86
/*
C program below. This mail can be extracted into test.c
on x86, sizeof(long long) == 8, sizeof(long) == 4
gcc -O2 -S test.c
hash:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl -4(%ebp), %eax
xorl -8(%ebp), %eax
leave
ret
Where did the ull = *(unsigned long long *)key; assignment go?
The compiler allocates stack space, and uses it, but without
putting anything into it first. The asm generated without
optimisation (without -O2) is correct.
Debian Linux Pentium 4 system, gcc installed from package system
from unstable as of 9 Nov 2004.
gcc -O2 -S test.c
no messages are generated at compilation.
gcc 2.95 generates correct code.
gcc 3.2.3 fails
gcc 3.3.5 fails
gcc 3.4.2 fails
/Anders Torger
*/
#include <stdio.h>
unsigned long
hash(void *key)
{
unsigned long long ull;
ull = *(unsigned long long *)key;
return ((unsigned long *)&ull)[0] ^ ((unsigned long *)&ull)[1];
}
int
main(void)
{
unsigned long long ull;
ull = ~0;
fprintf(stderr, "%u\n", hash(&ull));
return 0;
}