<html>
<head>
<base href="http://bugzilla.gdcproject.org/" />
</head>
<body><span class="vcard"><a class="email" href="mailto:art.08.09@gmail.com" title="art.08.09@gmail.com">art.08.09@gmail.com</a>
</span> changed
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Compiler emits invalid assembly when compiled with -O2"
href="http://bugzilla.gdcproject.org/show_bug.cgi?id=154">bug 154</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>NEW
</td>
<td>RESOLVED
</td>
</tr>
<tr>
<td style="text-align:right;">CC</td>
<td>
</td>
<td>art.08.09@gmail.com
</td>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>---
</td>
<td>INVALID
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Compiler emits invalid assembly when compiled with -O2"
href="http://bugzilla.gdcproject.org/show_bug.cgi?id=154#c1">Comment # 1</a>
on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Compiler emits invalid assembly when compiled with -O2"
href="http://bugzilla.gdcproject.org/show_bug.cgi?id=154">bug 154</a>
from <span class="vcard"><a class="email" href="mailto:art.08.09@gmail.com" title="art.08.09@gmail.com">art.08.09@gmail.com</a>
</span></b>
<pre><span class="quote">> asm {"
> mov %2, %0;
> lock;
> xadd %0, (%1);
>
> "
> : "=r"(retVal)
> : "r"(counter), "r"(addition)
> : "memory"; }</span >
<span class="quote">> when compiling with -O2 the exchangeAndAdd function assembly is the same but
> it is also inlined into main like so (invalid assembly):
>
> 406614: ba 02 00 00 00 mov $0x2,%edx
> 406619: 48 c7 44 24 08 0a 00 movq $0xa,0x8(%rsp)
> 406620: 00 00
> 406622: 48 8d 44 24 08 lea 0x8(%rsp),%rax
> 406627: 48 89 d0 mov %rdx,%rax
> 40662a: f0 48 0f c1 00 lock xadd %rax,(%rax)
>
> This obviously segfaults as rax is garbaged.</span >
That happens because you're modifying the output before using the inputs.
Not a bug; you need to mark the output as an earlyclobber:
ulong /*RAX*/ exchangeAndAdd(ulong * counter /*RSI*/, ulong addition /*RDI*/)
{
ulong retVal = void;
asm {"
mov %2, %0;
lock;
xadd %0, (%1);
"
: "=&r"(retVal)
: "r"(counter), "r"(addition)
: "memory"; }
return retVal;
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are watching all bug changes.</li>
</ul>
</body>
</html>