Skip to content

Incorrect code generated for fastcall functions on i686-pc-windows-gnu #91167

Open
@ricobbe

Description

@ricobbe

I tried this code:

#[repr(C)]
#[derive(Clone)]
struct S {
    x: u8,
    y: i32,
}

#[link(name = "extern", kind = "dylib")]
extern "fastcall" {
    fn fastcall_fn(a: S, b: i32);
}

fn main() {
    unsafe {
        fastcall_fn(S { x: 1, y: 2 }, 16);
    }
}

linked against the following C code (compiled to extern.dll):

#include <stdio.h>
#include <stdint.h>

struct S {
    uint8_t x;
    int32_t y;
};

__declspec(dllexport) void __fastcall fastcall_fn(struct S s, int i) {
    printf("fastcall_fn(S { x: %d, y: %d }, %d)\n", s.x, s.y, i);
    fflush(stdout);
}

I expected to see this output:

fastcall_fn(S { x: 1, y: 2 }, 16)

Instead, I got this output:

fastcall_fn(S { x: 1, y: 2 }, 18873345)
fastcall_fn(S { x: 1, y: 2 }, 29491201)

Meta

rustc --version --verbose:

rustc 1.58.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: i686-pc-windows-gnu
release: 1.58.0-dev
LLVM version: 13.0.0

Reproed against commit 7b3cd07 of master.

To reproduce, check out the fastcall-bug branch on my fork of rustc; the reproduction case is in src/test/run-make/fastcall-bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-external-bugCategory: issue that is caused by bugs in software beyond our controlO-x86_32Target: x86 processors, 32 bit (like i686-*) (IA-32)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions