Closed
Description
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
Labels
Area: Concerning the application binary interface (ABI)Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: This is a bug.`#![feature(f16)]`, `#![feature(f128)]`Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessRelevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.