This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/36753] New: Forward propagation interacts badly with global register variable
- From: "slava at factorcode dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Jul 2008 19:22:55 -0000
- Subject: [Bug c/36753] New: Forward propagation interacts badly with global register variable
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The attached test case is supposed to print '31337' when run.
Correct output:
[slava@imac factor]$ gcc -O1 testcase.c
[slava@imac factor]$ ./a.out
31337
Correct output:
[slava@imac factor]$ gcc -O2 -fno-forward-propagate testcase.c
[slava@imac factor]$ ./a.out
31337
*Incorrect* output:
[slava@imac factor]$ gcc -O2 testcase.c
[slava@imac factor]$ ./a.out
0
We can plainly see the problem in the disassemble for the broken() function.
With -O2 -fno-forward-propagate,
broken:
leaq 8(%r14), %rax
movq %rax, %r14
movq $31337, (%rax)
ret
With -O2:
broken:
addq $8, %r14
movq $31337, 8(%r14)
ret
===========================================
#include <stdbool.h>
#include <stdio.h>
register unsigned long *ds asm("r14");
__attribute__((noinline)) void broken(bool value)
{
*++ds = 31337;
}
int main()
{
unsigned long stack[2];
stack[0] = 0;
stack[1] = 0;
ds = stack;
broken(true);
printf("%ld\n",*ds);
}
===========================================
--
Summary: Forward propagation interacts badly with global register
variable
Product: gcc
Version: 4.3.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: slava at factorcode dot org
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36753