The attached test case is supposed to print '31337' when run. Correct output:
[EMAIL PROTECTED] factor]$ gcc -O1 testcase.c [EMAIL PROTECTED] factor]$ ./a.out 31337 Correct output: [EMAIL PROTECTED] factor]$ gcc -O2 -fno-forward-propagate testcase.c [EMAIL PROTECTED] factor]$ ./a.out 31337 *Incorrect* output: [EMAIL PROTECTED] factor]$ gcc -O2 testcase.c [EMAIL PROTECTED] 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