<html>
<head>
<base href="http://bugzilla.gdcproject.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 - Compiler emits invalid assembly when compiled with -O2"
href="http://bugzilla.gdcproject.org/show_bug.cgi?id=154">154</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Compiler emits invalid assembly when compiled with -O2
</td>
</tr>
<tr>
<th>Product</th>
<td>GDC
</td>
</tr>
<tr>
<th>Version</th>
<td>4.9.x
</td>
</tr>
<tr>
<th>Hardware</th>
<td>x86_64
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>major
</td>
</tr>
<tr>
<th>Priority</th>
<td>Normal
</td>
</tr>
<tr>
<th>Component</th>
<td>gdc
</td>
</tr>
<tr>
<th>Assignee</th>
<td>ibuclaw@gdcproject.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>maor@weka.io
</td>
</tr></table>
<p>
<div>
<pre>Using either the (almost) latest dev GDC (commit
5434139180a410f9fc79cabe0871b3601cee167f) or gdc-4.9 on Ubuntu Linux and X86_64
I get the following problem compiling the below code:
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;
}
int main() {
ulong a = 10;
ulong b = exchangeAndAdd(&a, 2);
assert(a==12);
assert(b==10);
return 0;
}
when compiling with no optimizations or with -O1 all is well, the
exchangeAndAdd assembly looks like:
4065d9: 48 89 f0 mov %rsi,%rax
4065dc: f0 48 0f c1 07 lock xadd %rax,(%rdi)
4065e1: c3 retq
it's called from main and everybody is happy.
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are watching all bug changes.</li>
</ul>
</body>
</html>