<html>
<head>
<base href="https://bugs.llvm.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 - Optimized 128-bit atomic compare-and-swap can generate incorrect code on msvc target"
href="https://bugs.llvm.org/show_bug.cgi?id=42064">42064</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Optimized 128-bit atomic compare-and-swap can generate incorrect code on msvc target
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>cerickson@curedev.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=22047" name="attach_22047" title="Example source code">attachment 22047</a> <a href="attachment.cgi?id=22047&action=edit" title="Example source code">[details]</a></span>
Example source code
When compiling the attached source with:
clang --target=x86_64-pc-windows-msvc -march=sandybridge -O2
it appears that the generated code tries to use rbx as both an input for
cmpxchg16b and as a stack pointer:
mov rbx, rsp
...
movabs rax, 1393743441367457520
mov rdx, rax
mov rcx, rax
mov rbx, rax
lock cmpxchg16b xmmword ptr [r8]
vxorps xmm0, xmm0, xmm0
vmovaps xmmword ptr [rbx + 128], xmm0 // rbx is garbage at this point
The example C++ code is a bit silly because it is as reduced as I could get it
and still have the problem occur. The same issue occurs whether using
_InterlockedCompareExchange128() or __sync_val_compare_and_swap().
For convenience, here is the example on godbolt: <a href="https://godbolt.org/z/C64_VH">https://godbolt.org/z/C64_VH</a>
I ran into this issue in clang 7.0.0 but it seems to still be there in trunk
(according to godbolt).</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>