<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 - [Windows][AArch64] Arguments not passed in the correct register"
href="https://bugs.llvm.org/show_bug.cgi?id=47465">47465</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[Windows][AArch64] Arguments not passed in the correct register
</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>Richard.Townsend@arm.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=23938" name="attach_23938" title="Reproducer">attachment 23938</a> <a href="attachment.cgi?id=23938&action=edit" title="Reproducer">[details]</a></span>
Reproducer
When compiling the attached file (constructed from a failing Chromium test),
Clang allocates space for the return value in X8 when calling the
RetValShouldNotBePassedInX8 instance member function (compiled with clang
--target=aarch64-windows-msvc -Os, reproducer at <a href="https://godbolt.org/z/rG5vqj">https://godbolt.org/z/rG5vqj</a>).
main: ; @main
sub sp, sp, #80 ; =80
str x30, [sp, #64] ; 8-byte Folded Spill
adrp x8, "??_7B@@6B@"
add x8, x8, "??_7B@@6B@"
str x8, [sp, #72]
add x0, sp, #72 ; =72 (x0 contains $this)
add x8, sp, #8 ; =8 (Return space allocated in
x8)
bl "?RetValShouldNotBePassedInX8@B@@UEAA?AUBAR_STRUCT@@XZ"
ldr w0, [sp, #8]
ldr x30, [sp, #64] ; 8-byte Folded Reload
add sp, sp, #80 ; =80
ret
MSVC's output (<a href="https://godbolt.org/z/x9aPjG">https://godbolt.org/z/x9aPjG</a>):
|main| PROC
|$LN8|
str lr,[sp,#-0x10]!
sub sp,sp,#0x40
add x1,sp,#8 (Return space allocated in x1)
mov x0,sp (x0 contains $this)
bl |virtual BAR_STRUCT B::RetValShouldNotBePassedInX8(void)
__ptr64|
ldr w0,[sp,#8]
add sp,sp,#0x40
ldr lr,[sp],#0x10
ret
I reached out to Microsoft and they've confirmed that non-static member
functions always pass the return address in x1, and not x8[1]. They've updated
the official ABI documentation[2] to reflect this. This issue doesn't appear to
crop up very much in production because normally the value that's returned is
not aggregate by their definition (in which case, the return value address is
passed in x1 and everything's fine), but some Chromium/Edge components (in
particular the dawn_end2end_tests test suite) are affected and crash because of
this.
[1]
<a href="https://developercommunity.visualstudio.com/content/problem/1152955/arm64-abi-inconsistent-handling-of-abi-structs.html">https://developercommunity.visualstudio.com/content/problem/1152955/arm64-abi-inconsistent-handling-of-abi-structs.html</a>
[2]
<a href="https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=vs-2019#return-values">https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=vs-2019#return-values</a></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>