Skip to content

Missoptimization of functions with C calling convention #33868

Closed
@Florob

Description

@Florob

When trying to look at how aggregates are passed to functions I came across the following:
The code presented below erroneously outputs 488447261 instead of 20.
This is using the 1.9.0 preview release (or anything newer) and seems to be a regression from 1.8.0.
The behaviour only occurs when using the C calling conventions and optimizations, eliminating either factor gives the correct result.

#[repr(C)]
struct S {
    a: u32,
    b: f32,
    c: u32
}

extern "C" fn test(s: S) -> u32 {
    s.a + s.b as u32 + s.c
}

fn main() {
    println!("{}", test(S { a: 12, b: 3.4, c: 5 }));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)P-highHigh priorityregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions