Skip to content

msvc: small float aggregates are returned incorrectly with extern "Rust" #1703

Description

@folkertdev

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 rust-lang/rust#162832

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-abiArea: ABI handlingO-windowsOperating system: WindowsO-x86_64Target: x64 processors

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions