Skip to content

f16 generates code that uses the incorrect ABI for compiler-rt #123885

Closed
@tgross35

Description

@tgross35

On the playground and godbolt, the following is non-deterministic:

#![feature(f16,f128)]
use std::mem::transmute;

#[inline(never)]
pub fn add(a: f16) -> f16 {
    10.0f16 + a
}

fn main() {
    let a = add(10.0);
    println!("{:#06x}", unsafe { transmute::<_, u16>(a) });
}

Running different times gives me different values like 0x9200, 0x06e0, 0xc000. The generated assembly is always the same:

example::add::hb3d3e297b1262388:
        push    rax
        mov     rax, qword ptr [rip + __extendhfsf2@GOTPCREL]
        call    rax
        movss   xmm1, dword ptr [rip + .LCPI1_0]
        addss   xmm0, xmm1
        mov     rax, qword ptr [rip + __truncsfhf2@GOTPCREL]
        call    rax
        pop     rax
        ret

Not really sure what would be going on here, seems unlikely to be a bug in extend/trunc.

This shows up on both the playground (nightly 2024-04-12 7942405) and godbolt (2024-04-11), but I cannot reproduce locally (nightly 2024-04-12, aarch64-darwin).

Links: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=b261d218028b8bddfe769658c195f529, https://rust.godbolt.org/z/fT1xcMMWz

@rustbot label +F-f16_and_f128

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ABIArea: Concerning the application binary interface (ABI)A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.F-f16_and_f128`#![feature(f16)]`, `#![feature(f128)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions