<div dir="ltr">Ah, okay. Locally, I only tested Clang versions up to 3.9.<div><br></div><div>Should we close the bug report? Having slightly different conventions than GCC here is probably not an issue.</div><div><br></div><div>- Manuel</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-13 17:46 GMT+02:00 Nirav Davé <span dir="ltr"><<a href="mailto:niravd@google.com" target="_blank">niravd@google.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It looks like godbolt's comment filtering is removing the line if it gets placed on a separate line. The comments do appear for 4.0 and later. <span class="HOEnZb"><font color="#888888"><div><br></div><div>-Nirav</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 13, 2017 at 10:59 AM, Manuel Rigger <span dir="ltr"><<a href="mailto:rigger.manuel@gmail.com" target="_blank">rigger.manuel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I filed a bug (see <a href="https://bugs.llvm.org/show_bug.cgi?id=33770" target="_blank">https://bugs.llvm.org/sho<wbr>w_bug.cgi?id=33770</a>).<div><br></div><div>It seems the comment is swallowed (i.e., it is also not on the next line). I verified this locally and using Compiler Explorer (see <a href="https://godbolt.org/" target="_blank">https://godbolt.org/</a>). Removing the trailing semicolon lets the comment appear when using Clang 4.0, but not on versions below it.</div><span class="m_-2900867306605624386HOEnZb"><font color="#888888"><div><br></div><div>- Manuel</div></font></span></div><div class="m_-2900867306605624386HOEnZb"><div class="m_-2900867306605624386h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-07-13 16:36 GMT+02:00 Nirav Davé <span dir="ltr"><<a href="mailto:niravd@google.com" target="_blank">niravd@google.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>AFAIK we retain all assembly comments by default. I just tried this locally and it seems to work as expected with inline assembly comments should be preserved by default.</div><div><br></div><div>I suspect the comment does exist, but is on the next line. Currently, the trailing semicolon at the end of your instruction is interpreted as an EOL so the following comment is interpreted as a full line comment (We may want to change that). If you remove the semicolon you should find it on the same line. </div><span class="m_-2900867306605624386m_2040660885377883258HOEnZb"><font color="#888888"><div><br></div><div>-Nirav<br></div><div><br></div></font></span></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-2900867306605624386m_2040660885377883258h5">On Thu, Jul 13, 2017 at 7:51 AM, Manuel Rigger via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-2900867306605624386m_2040660885377883258h5"><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="m_-2900867306605624386m_2040660885377883258m_-5496036288163464201m_5039568634391883126gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>%1,%0; # atomic_swap_long"</div></div><div><div><span class="m_-2900867306605624386m_2040660885377883258m_-5496036288163464201m_5039568634391883126gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>: "+r" (v), /* 0 */</div></div><div><div><span class="m_-2900867306605624386m_2040660885377883258m_-5496036288163464201m_5039568634391883126gmail-Apple-tab-span" style="white-space:pre-wrap"> </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="m_-2900867306605624386m_2040660885377883258m_-5496036288163464201m_5039568634391883126gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>xchgq<span class="m_-2900867306605624386m_2040660885377883258m_-5496036288163464201m_5039568634391883126gmail-Apple-tab-span" style="white-space:pre-wrap"> </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="m_-2900867306605624386m_2040660885377883258m_-5496036288163464201m_5039568634391883126gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>%rsi, (%rdi)</div></div><div><div>#NO_APP</div></div></blockquote><div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">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-wrap"><br></span></div><div><span style="white-space:pre-wrap">The comment is retained on the LLVM IR level:</span></div><div><span style="white-space:pre-wrap"><br></span></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><span style="white-space:pre-wrap">%5 = call i64 asm sideeffect "xchgq\09$1,$0; # atomic_swap_long", "=r,=*m,0,*m,~{dirflag},~{fpsr<wbr>},~{flags}"(i64* %4, i64 %3, i64* %4)</span></div></blockquote><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">Is this intended? Should I open a bug report?</span></div><span class="m_-2900867306605624386m_2040660885377883258m_-5496036288163464201HOEnZb"><font color="#888888"><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">- Manuel</span></div></font></span></div>
<br></div></div><span>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>