[llvm-bugs] [Bug 28544] New: incorrect code generated when adding 64-bit constant to 64-bit variable

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 13 13:17:41 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28544

            Bug ID: 28544
           Summary: incorrect code generated when adding 64-bit constant
                    to 64-bit variable
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: markv at sassafras.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 16738
  --> https://llvm.org/bugs/attachment.cgi?id=16738&action=edit
C source demonstrating the bug

Adding a 64-bit constant value to a 64-bit referenced value generates incorrect
code when clang runs with -O1 or higher.  The test case is very simple:

    void
    f1 (unsigned long long *foo)
    {
        *foo += 0x0000000800000000LL;
    }

I compile thing with a command like the following:

    clang -S -O1 test.c

Generated code looks like this (abridged):

    pushq    %rbp
    movq    %rsp, %rbp
    subq    $-2147483648, (%rdi)    ## imm = 0xFFFFFFFF80000000
    popq    %rbp
    retq

For reference, similar code is compiled correctly:

    unsigned long long
    f2 (unsigned long long foo)
    {
        return(foo + 0x0000000800000000LL);
    }

Results in:

    pushq    %rbp
    movq    %rsp, %rbp
    movabsq    $34359738368, %rax      ## imm = 0x800000000
    addq    %rdi, %rax
    popq    %rbp
    retq

Attached file .c has these two routines.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160713/bf056b0b/attachment.html>


More information about the llvm-bugs mailing list