<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 - Wrong code generated for x86 inline assembly"
href="https://bugs.llvm.org/show_bug.cgi?id=51340">51340</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Wrong code generated for x86 inline assembly
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>12.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>C
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>pgofman@codeweavers.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=25105" name="attach_25105" title="Isolated test case">attachment 25105</a> <a href="attachment.cgi?id=25105&action=edit" title="Isolated test case">[details]</a></span>
Isolated test case
The bug affects wine-mono project (compiling WPF code with clang).
I am attaching an isolated test case which reproduces the issue which isolates
the miscompiled code.
When compiled with 'clang -fms-extensions -m32 ./clang_bug.c' wrongly
translates 'movss fi.f,xmm1;' instruction. Instead of referencing the
address on stack it uses eax as destination address where the compiler has
stored the stack address before the asm block. The eax has been overwritten by
prior instructions in the assembly. 'movss fi.f,xmm1;' is also translated
wrong using 'ecx' where the compiler has also stored the same stack address of
'fi' variable.
The issue is not reproducible if not using union here (e. g., just defining
'fi' as float or int). It is also not reproducible when adding '-O2' to
compiler flags.
Here is the relevant asm compilation result for the wrong case:
round_func: # @round_func
.cfi_startproc
# %bb.0:
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset %ebp, -8
movl %esp, %ebp
.cfi_def_cfa_register %ebp
subl $8, %esp
movss 8(%ebp), %xmm0 # xmm0 = mem[0],zero,zero,zero
leal -8(%ebp), %eax
leal -8(%ebp), %ecx
#APP
movss 8(%ebp), %xmm0 # xmm0 = mem[0],zero,zero,zero
cvtss2si %xmm0, %eax
cvtsi2ss %eax, %xmm1
subss %xmm0, %xmm1
movss round_func.negHalf, %xmm0 # xmm0 = mem[0],zero,zero,zero
cmpless %xmm0, %xmm1
movss %xmm1, (%eax)
subl (%ecx), %eax
#NO_APP
addl $8, %esp
popl %ebp
.cfi_def_cfa %esp, 4
retl
.Lfunc_end0:
.size round_func, .Lfunc_end0-round_func
.cfi_endproc</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>