<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Inline Assembler Comments"
   href="https://bugs.llvm.org/show_bug.cgi?id=33770">33770</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inline Assembler Comments
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rigger.manuel@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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
<a href="http://lists.llvm.org/pipermail/cfe-dev/2017-July/054657.html">http://lists.llvm.org/pipermail/cfe-dev/2017-July/054657.html</a>), I got the
advice to delete the trailing semicolon. This works for Clang 4.0.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>