This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/36753] New: Forward propagation interacts badly with global register variable


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]