<div dir="ltr">Hi,<div><br></div><div>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:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>#include <stdint.h></div></div><div><div><br></div></div><div><div>uint64_t atomic_swap_long(volatile uint64_t *p, uint64_t v) {</div></div><div><div>  __asm __volatile(</div></div><div><div>    "xchgq<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>%1,%0; # atomic_swap_long"</div></div><div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>: "+r" (v),   /* 0 */</div></div><div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>  "+m" (*p)); /* 1 */</div></div><div><div>  return v;</div></div><div><div>}</div></div></blockquote><div><br></div><div>When compiling with GCC (gcc -O1 -S) the following code is produced for the inline assembly snippet on my system:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div> #APP</div><div># 4 "inline-assembly-comment.c" 1</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>xchgq<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>(%rdi),%rax; # atomic_swap_long</div><div># 0 "" 2</div><div>#NO_APP</div></blockquote><div><br></div><div>With Clang 3.8 and below, an empty line is inserted instead of the comment:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>#APP</div></div><div><div>xchgq<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>%rsi, (%rdi)</div></div><div><div>#NO_APP</div></div></blockquote><div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">With Clang 3.9 and 4.0, the newline disappeared but the comment is still not part of the assembly code.</span><br></div></div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">The comment is retained on the LLVM IR level:</span></div><div><span style="white-space:pre"><br></span></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><span style="white-space:pre">%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)</span></div></blockquote><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">Is this intended? Should I open a bug report?</span></div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">- Manuel</span></div></div>