From c4d9c0f248f05542024ad55a52774ea84406db81 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 5 Jul 2025 01:46:49 -0500 Subject: [PATCH] tests: Use `cfg_target_has_reliable_f16_f128` `conv-bits-runtime-const` gates `f16` and `f128` tests behind `x86_64`, but this isn't always accurate. In particular, x86 `MinGW` has an ABI bug [1] which means things work when linked to our Rust math libraries but don't work with host libraries. RUST-143405 slightly adjusts which targets we provide `f16` and `f128` symbols for and effectively removes MinGW from that list, meaning host libraries start getting linked, meaning `f16` and `f128` tests start to fail. Account for this by changing the gates in one such test to `cfg(target_has_reliable_{f16,f128})` which is the way we should be gating all behavior related to the types going forward. `rustfmt` also seems to have formatted the macros which is fine. [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054 --- tests/ui/float/conv-bits-runtime-const.rs | 43 +++++++++++------------ 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/tests/ui/float/conv-bits-runtime-const.rs b/tests/ui/float/conv-bits-runtime-const.rs index 3046728fe66ff..1373001b74dab 100644 --- a/tests/ui/float/conv-bits-runtime-const.rs +++ b/tests/ui/float/conv-bits-runtime-const.rs @@ -5,25 +5,24 @@ #![feature(f16)] #![feature(f128)] +#![feature(cfg_target_has_reliable_f16_f128)] #![allow(unused_macro_rules)] +// expect the unexpected (`target_has_reliable_*` are not "known" configs since they are unstable) +#![expect(unexpected_cfgs)] use std::hint::black_box; macro_rules! both_assert { - ($a:expr) => { - { - const _: () = assert!($a); - // `black_box` prevents promotion, and MIR opts are disabled above, so this is truly - // going through LLVM. - assert!(black_box($a)); - } - }; - ($a:expr, $b:expr) => { - { - const _: () = assert!($a == $b); - assert_eq!(black_box($a), black_box($b)); - } - }; + ($a:expr) => {{ + const _: () = assert!($a); + // `black_box` prevents promotion, and MIR opts are disabled above, so this is truly + // going through LLVM. + assert!(black_box($a)); + }}; + ($a:expr, $b:expr) => {{ + const _: () = assert!($a == $b); + assert_eq!(black_box($a), black_box($b)); + }}; } fn has_broken_floats() -> bool { @@ -31,8 +30,8 @@ fn has_broken_floats() -> bool { cfg!(all(target_arch = "x86", not(target_feature = "sse2"))) } -#[cfg(target_arch = "x86_64")] -fn f16(){ +#[cfg(target_has_reliable_f16)] +fn f16() { both_assert!((1f16).to_bits(), 0x3c00); both_assert!(u16::from_be_bytes(1f16.to_be_bytes()), 0x3c00); both_assert!((12.5f16).to_bits(), 0x4a40); @@ -122,7 +121,7 @@ fn f64() { } } -#[cfg(target_arch = "x86_64")] +#[cfg(target_has_reliable_f128)] fn f128() { both_assert!((1f128).to_bits(), 0x3fff0000000000000000000000000000); both_assert!(u128::from_be_bytes(1f128.to_be_bytes()), 0x3fff0000000000000000000000000000); @@ -154,12 +153,10 @@ fn f128() { } fn main() { + #[cfg(target_has_reliable_f16)] + f16(); f32(); f64(); - - #[cfg(target_arch = "x86_64")] - { - f16(); - f128(); - } + #[cfg(target_has_reliable_f128)] + f128(); }