[llvm-bugs] [Bug 38828] New: Incorrect assembly emitted for cmpxchg IR instruction on thumbv7m-none-eabi target

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 4 11:17:20 PDT 2018


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

            Bug ID: 38828
           Summary: Incorrect assembly emitted for cmpxchg IR instruction
                    on thumbv7m-none-eabi target
           Product: new-bugs
           Version: trunk
          Hardware: Other
                OS: other
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: mvirkkunen at gmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 20841
  --> https://bugs.llvm.org/attachment.cgi?id=20841&action=edit
C program that reproduces the problem

When compiled with:

clang -c -target thumbv7m-none-eabi -O1 compare_exchange.c

The attached C program produces invalid assembly code that attempts to load a
value from outside the function's stack frame in the first "ldrex" instruction
of the compare exchange operation. The rest of the stack access generated by
the cmpxchg seem to be correct. More weird results can be obtained by
adding/removing "int"s before the atomic one. I've also attached the generated
assembly and IR code from my machine.

The problem seems to be on the assembly generation level and not in clang
itself (I ran into this while using Rust). The example program uses intrinsics
instead of standard C to make sure it's not a header issue, but the same
problem happens with stdatomic.h.

Compiling with "-target thumbv7-none-eabi" instead seems to produce correct
code, as well as compiling with -O0.

LLVM version: Tip of trunk from SVN, as well as 6.0.0-1ubuntu2 (my machine,
from the official Ubuntu repositories)

Godbolt link for quick verification:
https://godbolt.org/z/Ozr2xa

-- 
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/20180904/ca256777/attachment.html>


More information about the llvm-bugs mailing list