[llvm-bugs] [Bug 33770] New: Inline Assembler Comments

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 13 07:51:12 PDT 2017


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

            Bug ID: 33770
           Summary: Inline Assembler Comments
           Product: new-bugs
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: rigger.manuel at gmail.com
                CC: llvm-bugs at lists.llvm.org

I'm investigating how inline assembly is used in C projects. While doing so, I
found that a number of projects include comments as part of their inline
assembly snippets. The code snippet below is an example:

#include <stdint.h>

uint64_t atomic_swap_long(volatile uint64_t *p, uint64_t v) {
  __asm __volatile(
    "xchgq      %1,%0; # atomic_swap_long"
        : "+r" (v),   /* 0 */
          "+m" (*p)); /* 1 */
  return v;
}

When compiling with GCC (gcc -O1 -S) the following code is produced for the
inline assembly snippet on my system:

 #APP
# 4 "inline-assembly-comment.c" 1
        xchgq   (%rdi),%rax; # atomic_swap_long
# 0 "" 2
#NO_APP

With Clang 3.8 and below, an empty line is inserted instead of the comment:

#APP
xchgq   %rsi, (%rdi)
#NO_APP

With Clang 3.9 and 4.0, the newline disappeared but the comment is still not
part of the assembly code.

The comment is retained on the LLVM IR level:

%5 = call i64 asm sideeffect "xchgq\09$1,$0; # atomic_swap_long",
"=r,=*m,0,*m,~{dirflag},~{fpsr},~{flags}"(i64* %4, i64 %3, i64* %4)

On the mailing list (see
http://lists.llvm.org/pipermail/cfe-dev/2017-July/054657.html), I got the
advice to delete the trailing semicolon. This works for Clang 4.0.

-- 
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/20170713/72f939bb/attachment.html>


More information about the llvm-bugs mailing list