<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 - bad codegen for regcall when passing large argument on stack for function with different calling convention on i686-w64-mingw32"
href="https://bugs.llvm.org/show_bug.cgi?id=48595">48595</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>bad codegen for regcall when passing large argument on stack for function with different calling convention on i686-w64-mingw32
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mizvekov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Compiling the following program with `clang -target i686-w64-mingw32 -g -O2
test.cc` will produce binary with bad code, which will cause program to
segfault when run:
```
struct baz { char buf[sizeof(long long) + 1]{}; };
struct bar {
baz a;
[[gnu::noinline]] bar(baz a) : a{a} {}
};
[[gnu::regcall, gnu::noinline]] static void foo() { bar c{baz{}}; }
int main() {
const volatile char a = 1;
foo();
return a;
}
```
This is generated assembly for `foo`:
```
004015f0 <__regcall3__foo()>:
4015f0: 55 push %ebp
4015f1: 89 e5 mov %esp,%ebp
4015f3: 54 push %esp
4015f4: 83 e4 f0 and $0xfffffff0,%esp
4015f7: 81 ec 80 00 00 00 sub $0x80,%esp
4015fd: 0f 29 7d e8 movaps %xmm7,-0x18(%ebp)
401601: 0f 29 75 d8 movaps %xmm6,-0x28(%ebp)
401605: 0f 29 6d c8 movaps %xmm5,-0x38(%ebp)
401609: 0f 29 65 b8 movaps %xmm4,-0x48(%ebp)
40160d: c7 44 24 1c 00 00 00 00 movl $0x0,0x1c(%esp)
401615: c7 44 24 18 00 00 00 00 movl $0x0,0x18(%esp)
40161d: c6 44 24 20 00 movb $0x0,0x20(%esp)
401622: 8d 4c 24 24 lea 0x24(%esp),%ecx
401626: 8a 44 24 20 mov 0x20(%esp),%al
40162a: 88 44 24 08 mov %al,0x8(%esp)
40162e: f2 0f 10 44 24 18 movsd 0x18(%esp),%xmm0
401634: f2 0f 11 04 24 movsd %xmm0,(%esp)
401639: e8 52 10 00 00 call 402690 <bar::bar(baz)>
40163e: 83 ec 0c sub $0xc,%esp
401641: 0f 28 65 b8 movaps -0x48(%ebp),%xmm4
401645: 0f 28 6d c8 movaps -0x38(%ebp),%xmm5
401649: 0f 28 75 d8 movaps -0x28(%ebp),%xmm6
40164d: 0f 28 7d e8 movaps -0x18(%ebp),%xmm7
401651: 8d 65 fc lea -0x4(%ebp),%esp
401654: 5c pop %esp
401655: 5d pop %ebp
401656: c3 ret
401657: 66 90 xchg %ax,%ax
401659: 66 90 xchg %ax,%ax
40165b: 66 90 xchg %ax,%ax
40165d: 66 90 xchg %ax,%ax
40165f: 90 nop
```
The execution will segfault at the first movaps, because the memory address
does not satisfy alignment for this instruction (movups should be used
instead). Windows x86 ABI does not require stack to be 16 byte aligned unlike
Linux for example.</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>