rust-lang / rust-lang/rustc_codegen_cranelift
msvc: small float aggregates are returned incorrectly with `extern "Rust"`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 157
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 3
Description
Consider
https://godbolt.org/z/4dYTvseGK
// --target=x86_64-pc-windows-msvc -Copt-level=3
#[repr(C)]
#[derive(Clone, Copy)]
struct Foo {
a: f32,
b: f32,
}
#[unsafe(no_mangle)]
fn foo(foo: &Foo) -> Foo {
*foo
}
The LLVM backend emits
foo:
movss xmm0, dword ptr [rcx]
movss xmm1, dword ptr [rcx + 4]
ret
while cg_clif emits
foo:
push rbp
mov rbp, rsp
sub rsp, 0x30
movdqu xmmword ptr [rsp + 0x10], xmm6
movdqu xmmword ptr [rsp + 0x20], xmm7
movss xmm7, dword ptr [rdx]
movss xmm6, dword ptr [rdx + 0x4]
movss dword ptr [rsp], xmm7
movss dword ptr [rsp + 0x4], xmm6
movss xmm0, dword ptr [rsp]
movss dword ptr [rcx], xmm6
movdqu xmm6, xmmword ptr [rsp + 0x10]
movdqu xmm7, xmmword ptr [rsp + 0x20]
add rsp, 0x30
mov rsp, rbp
pop rbp
ret
A bit of a mess, but note that xmm1 is not written to, and it looks like there is an outpointer which the LLVM also does not have.
This issue showed up in https://github.com/rust-lang/rust/pull/162832
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Godbolt reproducer for x86_64-pc-windows-msvc and compare the LLVM backend assembly with the cg_clif output. Trace how cg_clif handles this small float aggregate's return ABI; done means the generated code returns both fields consistently with LLVM, without the incorrect outpointer behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100