<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p><br>
</p>
<div class="moz-cite-prefix">On 07/13/2017 06:51 AM, Manuel Rigger
via cfe-dev wrote:<br>
</div>
<blockquote
cite="mid:CA+u7OA4i0Ef5V3v9YUrtCGuzsGf_8QH3AZszcUGS-znsTqCXHA@mail.gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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">
</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">
</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">
</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">
</span></div>
<div><span style="white-space:pre">Is this intended? Should I open a bug report?</span></div>
</div>
</blockquote>
<br>
Please feel free to file a bug report. Retaining the comments seems
like a useful thing to do.<br>
<br>
-Hal<br>
<br>
<blockquote
cite="mid:CA+u7OA4i0Ef5V3v9YUrtCGuzsGf_8QH3AZszcUGS-znsTqCXHA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><span style="white-space:pre">
</span></div>
<div><span style="white-space:pre">- Manuel</span></div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</body>
</html>