Skip to content

Commit 082c119

Browse files
committed
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
1 parent 016bc61 commit 082c119

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

tests/ui/float/conv-bits-runtime-const.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,33 @@
55

66
#![feature(f16)]
77
#![feature(f128)]
8+
#![feature(cfg_target_has_reliable_f16_f128)]
89
#![allow(unused_macro_rules)]
10+
// expect the unexpected (`target_has_reliable_*` are not "known" configs since they are unstable)
11+
#![expect(unexpected_cfgs)]
912

1013
use std::hint::black_box;
1114

1215
macro_rules! both_assert {
13-
($a:expr) => {
14-
{
15-
const _: () = assert!($a);
16-
// `black_box` prevents promotion, and MIR opts are disabled above, so this is truly
17-
// going through LLVM.
18-
assert!(black_box($a));
19-
}
20-
};
21-
($a:expr, $b:expr) => {
22-
{
23-
const _: () = assert!($a == $b);
24-
assert_eq!(black_box($a), black_box($b));
25-
}
26-
};
16+
($a:expr) => {{
17+
const _: () = assert!($a);
18+
// `black_box` prevents promotion, and MIR opts are disabled above, so this is truly
19+
// going through LLVM.
20+
assert!(black_box($a));
21+
}};
22+
($a:expr, $b:expr) => {{
23+
const _: () = assert!($a == $b);
24+
assert_eq!(black_box($a), black_box($b));
25+
}};
2726
}
2827

2928
fn has_broken_floats() -> bool {
3029
// i586 targets are broken due to <https://github.com/rust-lang/rust/issues/114479>.
3130
cfg!(all(target_arch = "x86", not(target_feature = "sse2")))
3231
}
3332

34-
#[cfg(target_arch = "x86_64")]
35-
fn f16(){
33+
#[cfg(target_has_reliable_f16)]
34+
fn f16() {
3635
both_assert!((1f16).to_bits(), 0x3c00);
3736
both_assert!(u16::from_be_bytes(1f16.to_be_bytes()), 0x3c00);
3837
both_assert!((12.5f16).to_bits(), 0x4a40);
@@ -122,7 +121,7 @@ fn f64() {
122121
}
123122
}
124123

125-
#[cfg(target_arch = "x86_64")]
124+
#[cfg(target_has_reliable_f128)]
126125
fn f128() {
127126
both_assert!((1f128).to_bits(), 0x3fff0000000000000000000000000000);
128127
both_assert!(u128::from_be_bytes(1f128.to_be_bytes()), 0x3fff0000000000000000000000000000);
@@ -154,12 +153,10 @@ fn f128() {
154153
}
155154

156155
fn main() {
156+
#[cfg(target_has_reliable_f16)]
157+
f16();
157158
f32();
158159
f64();
159-
160-
#[cfg(target_arch = "x86_64")]
161-
{
162-
f16();
163-
f128();
164-
}
160+
#[cfg(target_has_reliable_f128)]
161+
f128();
165162
}

0 commit comments

Comments
 (0)