[LLVMbugs] [Bug 15139] New: Miscompilation (with -O0) of forced register variable.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Feb 1 09:49:13 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=15139

             Bug #: 15139
           Summary: Miscompilation (with -O0) of forced register variable.
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: peter.goodman at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 9957
  --> http://llvm.org/bugs/attachment.cgi?id=9957
Minimal test case (C file).

clang version 3.3 (trunk 172567) (llvm/trunk 172566)
Target: x86_64-unknown-linux-gnu
Thread model: posix


Code:

    #include <stdint.h>

    int foo(void) {
        register int bar asm("rcx") = 0;
        return bar;
    }

Disassembly:

    0:    c7 44 24 fc 00 00 00 00     movl $0, -4(%rsp)
    8:    8b 44 24 fc                 movl -4(%rsp), %eax
    c:    c3                          ret


Why it's wrong:
    Aside from not using %rcx, the generated code does not change %rsp before
    the first movl instruction (thus overflowing the stack). Thus, the second
    movl has undefined behaviour.

Notes:
    I experiences this error in other forms as well, e.g. without `asm("rcx")`,
    defining a register variable, and using it as a clobbered output variable
    in inline assembly (e.g. `"=r"(bar)`), etc. This was tested on -O0 and -O3.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list