Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d28df61

Browse files
authoredApr 29, 2025··
Unrolled build for rust-lang#140323
Rollup merge of rust-lang#140323 - tgross35:cfg-unstable-float, r=Urgau Implement the internal feature `cfg_target_has_reliable_f16_f128` Support for `f16` and `f128` is varied across targets, backends, and backend versions. Eventually we would like to reach a point where all backends support these approximately equally, but until then we have to work around some of these nuances of support being observable. Introduce the `cfg_target_has_reliable_f16_f128` internal feature, which provides the following new configuration gates: * `cfg(target_has_reliable_f16)` * `cfg(target_has_reliable_f16_math)` * `cfg(target_has_reliable_f128)` * `cfg(target_has_reliable_f128_math)` `reliable_f16` and `reliable_f128` indicate that basic arithmetic for the type works correctly. The `_math` versions indicate that anything relying on `libm` works correctly, since sometimes this hits a separate class of codegen bugs. These options match configuration set by the build script at [1]. The logic for LLVM support is duplicated as-is from the same script. There are a few possible updates that will come as a follow up. The config introduced here is not planned to ever become stable, it is only intended to replace the build scripts for `std` tests and `compiler-builtins` that don't have any way to configure based on the codegen backend. MCP: rust-lang/compiler-team#866 Closes: rust-lang/compiler-team#866 [1]: https://github.com/rust-lang/rust/blob/555e1d0386f024a8359645c3217f4b3eae9be042/library/std/build.rs#L84-L186 --- The second commit makes use of this config to replace `cfg_{f16,f128}{,_math}` in `library/`. I omitted providing a `cfg(bootstrap)` configuration to keep things simpler since the next beta branch is in two weeks. try-job: aarch64-gnu try-job: i686-msvc-1 try-job: test-various try-job: x86_64-gnu try-job: x86_64-msvc-ext2
2 parents 25cdf1f + dfa972e commit d28df61

File tree

27 files changed

+959
-289
lines changed

27 files changed

+959
-289
lines changed
 

‎compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ use std::sync::Arc;
4141

4242
use cranelift_codegen::isa::TargetIsa;
4343
use cranelift_codegen::settings::{self, Configurable};
44-
use rustc_codegen_ssa::CodegenResults;
4544
use rustc_codegen_ssa::traits::CodegenBackend;
45+
use rustc_codegen_ssa::{CodegenResults, TargetConfig};
4646
use rustc_metadata::EncodedMetadata;
4747
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4848
use rustc_session::Session;
@@ -178,7 +178,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
178178
}
179179
}
180180

181-
fn target_features_cfg(&self, sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
181+
fn target_config(&self, sess: &Session) -> TargetConfig {
182182
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
183183
let target_features = if sess.target.arch == "x86_64" && sess.target.os != "none" {
184184
// x86_64 mandates SSE2 support and rustc requires the x87 feature to be enabled
@@ -197,7 +197,16 @@ impl CodegenBackend for CraneliftCodegenBackend {
197197
};
198198
// FIXME do `unstable_target_features` properly
199199
let unstable_target_features = target_features.clone();
200-
(target_features, unstable_target_features)
200+
201+
TargetConfig {
202+
target_features,
203+
unstable_target_features,
204+
// Cranelift does not yet support f16 or f128
205+
has_reliable_f16: false,
206+
has_reliable_f16_math: false,
207+
has_reliable_f128: false,
208+
has_reliable_f128_math: false,
209+
}
201210
}
202211

203212
fn print_version(&self) {

‎compiler/rustc_codegen_gcc/src/gcc_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
5555
)
5656
} else if let Some(feature) = feature.strip_prefix('-') {
5757
// FIXME: Why do we not remove implied features on "-" here?
58-
// We do the equivalent above in `target_features_cfg`.
58+
// We do the equivalent above in `target_config`.
5959
// See <https://github.com/rust-lang/rust/issues/134792>.
6060
all_rust_features.push((false, feature));
6161
} else if !feature.is_empty() && diagnostics {

‎compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ use rustc_codegen_ssa::back::write::{
102102
};
103103
use rustc_codegen_ssa::base::codegen_crate;
104104
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, WriteBackendMethods};
105-
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
105+
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, TargetConfig};
106106
use rustc_data_structures::fx::FxIndexMap;
107107
use rustc_data_structures::sync::IntoDynSyncSend;
108108
use rustc_errors::DiagCtxtHandle;
@@ -260,8 +260,8 @@ impl CodegenBackend for GccCodegenBackend {
260260
.join(sess)
261261
}
262262

263-
fn target_features_cfg(&self, sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
264-
target_features_cfg(sess, &self.target_info)
263+
fn target_config(&self, sess: &Session) -> TargetConfig {
264+
target_config(sess, &self.target_info)
265265
}
266266
}
267267

@@ -485,10 +485,7 @@ fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
485485
}
486486

487487
/// Returns the features that should be set in `cfg(target_feature)`.
488-
fn target_features_cfg(
489-
sess: &Session,
490-
target_info: &LockedTargetInfo,
491-
) -> (Vec<Symbol>, Vec<Symbol>) {
488+
fn target_config(sess: &Session, target_info: &LockedTargetInfo) -> TargetConfig {
492489
// TODO(antoyo): use global_gcc_features.
493490
let f = |allow_unstable| {
494491
sess.target
@@ -523,5 +520,14 @@ fn target_features_cfg(
523520

524521
let target_features = f(false);
525522
let unstable_target_features = f(true);
526-
(target_features, unstable_target_features)
523+
524+
TargetConfig {
525+
target_features,
526+
unstable_target_features,
527+
// There are no known bugs with GCC support for f16 or f128
528+
has_reliable_f16: true,
529+
has_reliable_f16_math: true,
530+
has_reliable_f128: true,
531+
has_reliable_f128_math: true,
532+
}
527533
}

‎compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ use back::owned_target_machine::OwnedTargetMachine;
2929
use back::write::{create_informational_target_machine, create_target_machine};
3030
use context::SimpleCx;
3131
use errors::{AutoDiffWithoutLTO, ParseTargetMachineConfig};
32-
use llvm_util::target_features_cfg;
32+
use llvm_util::target_config;
3333
use rustc_ast::expand::allocator::AllocatorKind;
3434
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
3535
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
3636
use rustc_codegen_ssa::back::write::{
3737
CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryConfig, TargetMachineFactoryFn,
3838
};
3939
use rustc_codegen_ssa::traits::*;
40-
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
40+
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, TargetConfig};
4141
use rustc_data_structures::fx::FxIndexMap;
4242
use rustc_errors::{DiagCtxtHandle, FatalError};
4343
use rustc_metadata::EncodedMetadata;
@@ -338,8 +338,8 @@ impl CodegenBackend for LlvmCodegenBackend {
338338
llvm_util::print_version();
339339
}
340340

341-
fn target_features_cfg(&self, sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
342-
target_features_cfg(sess)
341+
fn target_config(&self, sess: &Session) -> TargetConfig {
342+
target_config(sess)
343343
}
344344

345345
fn codegen_crate<'tcx>(

‎compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::sync::Once;
66
use std::{ptr, slice, str};
77

88
use libc::c_int;
9+
use rustc_codegen_ssa::TargetConfig;
910
use rustc_codegen_ssa::base::wants_wasm_eh;
1011
use rustc_codegen_ssa::codegen_attrs::check_tied_features;
1112
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -302,7 +303,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
302303
/// Must express features in the way Rust understands them.
303304
///
304305
/// We do not have to worry about RUSTC_SPECIFIC_FEATURES here, those are handled outside codegen.
305-
pub(crate) fn target_features_cfg(sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
306+
pub(crate) fn target_config(sess: &Session) -> TargetConfig {
306307
// Add base features for the target.
307308
// We do *not* add the -Ctarget-features there, and instead duplicate the logic for that below.
308309
// The reason is that if LLVM considers a feature implied but we do not, we don't want that to
@@ -402,7 +403,89 @@ pub(crate) fn target_features_cfg(sess: &Session) -> (Vec<Symbol>, Vec<Symbol>)
402403

403404
let target_features = f(false);
404405
let unstable_target_features = f(true);
405-
(target_features, unstable_target_features)
406+
let mut cfg = TargetConfig {
407+
target_features,
408+
unstable_target_features,
409+
has_reliable_f16: true,
410+
has_reliable_f16_math: true,
411+
has_reliable_f128: true,
412+
has_reliable_f128_math: true,
413+
};
414+
415+
update_target_reliable_float_cfg(sess, &mut cfg);
416+
cfg
417+
}
418+
419+
/// Determine whether or not experimental float types are reliable based on known bugs.
420+
fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
421+
let target_arch = sess.target.arch.as_ref();
422+
let target_os = sess.target.options.os.as_ref();
423+
let target_env = sess.target.options.env.as_ref();
424+
let target_abi = sess.target.options.abi.as_ref();
425+
let target_pointer_width = sess.target.pointer_width;
426+
427+
cfg.has_reliable_f16 = match (target_arch, target_os) {
428+
// Selection failure <https://github.com/llvm/llvm-project/issues/50374>
429+
("s390x", _) => false,
430+
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
431+
("arm64ec", _) => false,
432+
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
433+
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
434+
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
435+
("csky", _) => false,
436+
("hexagon", _) => false,
437+
("powerpc" | "powerpc64", _) => false,
438+
("sparc" | "sparc64", _) => false,
439+
("wasm32" | "wasm64", _) => false,
440+
// `f16` support only requires that symbols converting to and from `f32` are available. We
441+
// provide these in `compiler-builtins`, so `f16` should be available on all platforms that
442+
// do not have other ABI issues or LLVM crashes.
443+
_ => true,
444+
};
445+
446+
cfg.has_reliable_f128 = match (target_arch, target_os) {
447+
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
448+
("arm64ec", _) => false,
449+
// Selection bug <https://github.com/llvm/llvm-project/issues/96432>
450+
("mips64" | "mips64r6", _) => false,
451+
// Selection bug <https://github.com/llvm/llvm-project/issues/95471>
452+
("nvptx64", _) => false,
453+
// ABI bugs <https://github.com/rust-lang/rust/issues/125109> et al. (full
454+
// list at <https://github.com/rust-lang/rust/issues/116909>)
455+
("powerpc" | "powerpc64", _) => false,
456+
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
457+
("sparc", _) => false,
458+
// Stack alignment bug <https://github.com/llvm/llvm-project/issues/77401>. NB: tests may
459+
// not fail if our compiler-builtins is linked.
460+
("x86", _) => false,
461+
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
462+
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
463+
// There are no known problems on other platforms, so the only requirement is that symbols
464+
// are available. `compiler-builtins` provides all symbols required for core `f128`
465+
// support, so this should work for everything else.
466+
_ => true,
467+
};
468+
469+
cfg.has_reliable_f16_math = match (target_arch, target_os) {
470+
// x86 has a crash for `powi`: <https://github.com/llvm/llvm-project/issues/105747>
471+
("x86" | "x86_64", _) => false,
472+
// Assume that working `f16` means working `f16` math for most platforms, since
473+
// operations just go through `f32`.
474+
_ => true,
475+
} && cfg.has_reliable_f16;
476+
477+
cfg.has_reliable_f128_math = match (target_arch, target_os) {
478+
// LLVM lowers `fp128` math to `long double` symbols even on platforms where
479+
// `long double` is not IEEE binary128. See
480+
// <https://github.com/llvm/llvm-project/issues/44744>.
481+
//
482+
// This rules out anything that doesn't have `long double` = `binary128`; <= 32 bits
483+
// (ld is `f64`), anything other than Linux (Windows and MacOS use `f64`), and `x86`
484+
// (ld is 80-bit extended precision).
485+
("x86_64", _) => false,
486+
(_, "linux") if target_pointer_width == 64 => true,
487+
_ => false,
488+
} && cfg.has_reliable_f128;
406489
}
407490

408491
pub(crate) fn print_version() {
@@ -686,7 +769,7 @@ pub(crate) fn global_llvm_features(
686769
)
687770
} else if let Some(feature) = feature.strip_prefix('-') {
688771
// FIXME: Why do we not remove implied features on "-" here?
689-
// We do the equivalent above in `target_features_cfg`.
772+
// We do the equivalent above in `target_config`.
690773
// See <https://github.com/rust-lang/rust/issues/134792>.
691774
all_rust_features.push((false, feature));
692775
} else if !feature.is_empty() {

‎compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ pub struct CrateInfo {
235235
pub lint_levels: CodegenLintLevels,
236236
}
237237

238+
/// Target-specific options that get set in `cfg(...)`.
239+
///
240+
/// RUSTC_SPECIFIC_FEATURES should be skipped here, those are handled outside codegen.
241+
pub struct TargetConfig {
242+
/// Options to be set in `cfg(target_features)`.
243+
pub target_features: Vec<Symbol>,
244+
/// Options to be set in `cfg(target_features)`, but including unstable features.
245+
pub unstable_target_features: Vec<Symbol>,
246+
/// Option for `cfg(target_has_reliable_f16)`, true if `f16` basic arithmetic works.
247+
pub has_reliable_f16: bool,
248+
/// Option for `cfg(target_has_reliable_f16_math)`, true if `f16` math calls work.
249+
pub has_reliable_f16_math: bool,
250+
/// Option for `cfg(target_has_reliable_f128)`, true if `f128` basic arithmetic works.
251+
pub has_reliable_f128: bool,
252+
/// Option for `cfg(target_has_reliable_f128_math)`, true if `f128` math calls work.
253+
pub has_reliable_f128_math: bool,
254+
}
255+
238256
#[derive(Encodable, Decodable)]
239257
pub struct CodegenResults {
240258
pub modules: Vec<CompiledModule>,

‎compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::write::WriteBackendMethods;
1818
use crate::back::archive::ArArchiveBuilderBuilder;
1919
use crate::back::link::link_binary;
2020
use crate::back::write::TargetMachineFactoryFn;
21-
use crate::{CodegenResults, ModuleCodegen};
21+
use crate::{CodegenResults, ModuleCodegen, TargetConfig};
2222

2323
pub trait BackendTypes {
2424
type Value: CodegenObject;
@@ -50,8 +50,15 @@ pub trait CodegenBackend {
5050
/// - The second is like the first, but also includes unstable features.
5151
///
5252
/// RUSTC_SPECIFIC_FEATURES should be skipped here, those are handled outside codegen.
53-
fn target_features_cfg(&self, _sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
54-
(vec![], vec![])
53+
fn target_config(&self, _sess: &Session) -> TargetConfig {
54+
TargetConfig {
55+
target_features: vec![],
56+
unstable_target_features: vec![],
57+
has_reliable_f16: true,
58+
has_reliable_f16_math: true,
59+
has_reliable_f128: true,
60+
has_reliable_f128_math: true,
61+
}
5562
}
5663

5764
fn print_passes(&self) {}

‎compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ const GATED_CFGS: &[GatedCfg] = &[
4040
// this is consistent with naming of the compiler flag it's for
4141
(sym::fmt_debug, sym::fmt_debug, Features::fmt_debug),
4242
(sym::emscripten_wasm_eh, sym::cfg_emscripten_wasm_eh, Features::cfg_emscripten_wasm_eh),
43+
(
44+
sym::target_has_reliable_f16,
45+
sym::cfg_target_has_reliable_f16_f128,
46+
Features::cfg_target_has_reliable_f16_f128,
47+
),
48+
(
49+
sym::target_has_reliable_f16_math,
50+
sym::cfg_target_has_reliable_f16_f128,
51+
Features::cfg_target_has_reliable_f16_f128,
52+
),
53+
(
54+
sym::target_has_reliable_f128,
55+
sym::cfg_target_has_reliable_f16_f128,
56+
Features::cfg_target_has_reliable_f16_f128,
57+
),
58+
(
59+
sym::target_has_reliable_f128_math,
60+
sym::cfg_target_has_reliable_f16_f128,
61+
Features::cfg_target_has_reliable_f16_f128,
62+
),
4363
];
4464

4565
/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.

‎compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ declare_features! (
205205
(unstable, anonymous_lifetime_in_impl_trait, "1.63.0", None),
206206
/// Allows access to the emscripten_wasm_eh config, used by panic_unwind and unwind
207207
(internal, cfg_emscripten_wasm_eh, "1.86.0", None),
208+
/// Allows checking whether or not the backend correctly supports unstable float types.
209+
(internal, cfg_target_has_reliable_f16_f128, "CURRENT_RUSTC_VERSION", None),
208210
/// Allows identifying the `compiler_builtins` crate.
209211
(internal, compiler_builtins, "1.13.0", None),
210212
/// Allows writing custom MIR

‎compiler/rustc_interface/src/util.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,25 @@ pub(crate) fn add_configuration(
3838
codegen_backend: &dyn CodegenBackend,
3939
) {
4040
let tf = sym::target_feature;
41+
let tf_cfg = codegen_backend.target_config(sess);
4142

42-
let (target_features, unstable_target_features) = codegen_backend.target_features_cfg(sess);
43+
sess.unstable_target_features.extend(tf_cfg.unstable_target_features.iter().copied());
44+
sess.target_features.extend(tf_cfg.target_features.iter().copied());
4345

44-
sess.unstable_target_features.extend(unstable_target_features.iter().copied());
46+
cfg.extend(tf_cfg.target_features.into_iter().map(|feat| (tf, Some(feat))));
4547

46-
sess.target_features.extend(target_features.iter().copied());
47-
48-
cfg.extend(target_features.into_iter().map(|feat| (tf, Some(feat))));
48+
if tf_cfg.has_reliable_f16 {
49+
cfg.insert((sym::target_has_reliable_f16, None));
50+
}
51+
if tf_cfg.has_reliable_f16_math {
52+
cfg.insert((sym::target_has_reliable_f16_math, None));
53+
}
54+
if tf_cfg.has_reliable_f128 {
55+
cfg.insert((sym::target_has_reliable_f128, None));
56+
}
57+
if tf_cfg.has_reliable_f128_math {
58+
cfg.insert((sym::target_has_reliable_f128_math, None));
59+
}
4960

5061
if sess.crt_static(None) {
5162
cfg.insert((tf, Some(sym::crt_dash_static)));

‎compiler/rustc_session/src/config/cfg.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ pub(crate) fn disallow_cfgs(sess: &Session, user_cfgs: &Cfg) {
142142
| (sym::target_has_atomic, Some(_))
143143
| (sym::target_has_atomic_equal_alignment, Some(_))
144144
| (sym::target_has_atomic_load_store, Some(_))
145+
| (sym::target_has_reliable_f16, None | Some(_))
146+
| (sym::target_has_reliable_f16_math, None | Some(_))
147+
| (sym::target_has_reliable_f128, None | Some(_))
148+
| (sym::target_has_reliable_f128_math, None | Some(_))
145149
| (sym::target_thread_local, None) => disallow(cfg, "--target"),
146150
(sym::fmt_debug, None | Some(_)) => disallow(cfg, "-Z fmt-debug"),
147151
(sym::emscripten_wasm_eh, None | Some(_)) => disallow(cfg, "-Z emscripten_wasm_eh"),

‎compiler/rustc_span/src/symbol.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ symbols! {
614614
cfg_target_feature,
615615
cfg_target_has_atomic,
616616
cfg_target_has_atomic_equal_alignment,
617+
cfg_target_has_reliable_f16_f128,
617618
cfg_target_thread_local,
618619
cfg_target_vendor,
619620
cfg_trace: "<cfg>", // must not be a valid identifier
@@ -2068,6 +2069,10 @@ symbols! {
20682069
target_has_atomic,
20692070
target_has_atomic_equal_alignment,
20702071
target_has_atomic_load_store,
2072+
target_has_reliable_f128,
2073+
target_has_reliable_f128_math,
2074+
target_has_reliable_f16,
2075+
target_has_reliable_f16_math,
20712076
target_os,
20722077
target_pointer_width,
20732078
target_thread_local,

‎library/std/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@ check-cfg = [
163163
# and to the `backtrace` crate which messes-up with Cargo list
164164
# of declared features, we therefor expect any feature cfg
165165
'cfg(feature, values(any()))',
166+
# Internal features aren't marked known config by default, we use these to
167+
# gate tests.
168+
'cfg(target_has_reliable_f16)',
169+
'cfg(target_has_reliable_f16_math)',
170+
'cfg(target_has_reliable_f128)',
171+
'cfg(target_has_reliable_f128_math)',
166172
]

‎library/std/build.rs

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ fn main() {
77
let target_vendor =
88
env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set");
99
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
10-
let target_abi = env::var("CARGO_CFG_TARGET_ABI").expect("CARGO_CFG_TARGET_ABI was not set");
11-
let target_pointer_width: u32 = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
12-
.expect("CARGO_CFG_TARGET_POINTER_WIDTH was not set")
13-
.parse()
14-
.unwrap();
15-
let is_miri = env::var_os("CARGO_CFG_MIRI").is_some();
1610

1711
println!("cargo:rustc-check-cfg=cfg(netbsd10)");
1812
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
@@ -80,108 +74,4 @@ fn main() {
8074
println!("cargo:rustc-cfg=backtrace_in_libstd");
8175

8276
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
83-
84-
// Emit these on platforms that have no known ABI bugs, LLVM selection bugs, lowering bugs,
85-
// missing symbols, or other problems, to determine when tests get run.
86-
// If more broken platforms are found, please update the tracking issue at
87-
// <https://github.com/rust-lang/rust/issues/116909>
88-
//
89-
// Some of these match arms are redundant; the goal is to separate reasons that the type is
90-
// unreliable, even when multiple reasons might fail the same platform.
91-
println!("cargo:rustc-check-cfg=cfg(reliable_f16)");
92-
println!("cargo:rustc-check-cfg=cfg(reliable_f128)");
93-
94-
// This is a step beyond only having the types and basic functions available. Math functions
95-
// aren't consistently available or correct.
96-
println!("cargo:rustc-check-cfg=cfg(reliable_f16_math)");
97-
println!("cargo:rustc-check-cfg=cfg(reliable_f128_math)");
98-
99-
let has_reliable_f16 = match (target_arch.as_str(), target_os.as_str()) {
100-
// We can always enable these in Miri as that is not affected by codegen bugs.
101-
_ if is_miri => true,
102-
// Selection failure <https://github.com/llvm/llvm-project/issues/50374>
103-
("s390x", _) => false,
104-
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
105-
("arm64ec", _) => false,
106-
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
107-
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
108-
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
109-
("csky", _) => false,
110-
("hexagon", _) => false,
111-
("powerpc" | "powerpc64", _) => false,
112-
("sparc" | "sparc64", _) => false,
113-
("wasm32" | "wasm64", _) => false,
114-
// `f16` support only requires that symbols converting to and from `f32` are available. We
115-
// provide these in `compiler-builtins`, so `f16` should be available on all platforms that
116-
// do not have other ABI issues or LLVM crashes.
117-
_ => true,
118-
};
119-
120-
let has_reliable_f128 = match (target_arch.as_str(), target_os.as_str()) {
121-
// We can always enable these in Miri as that is not affected by codegen bugs.
122-
_ if is_miri => true,
123-
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
124-
("arm64ec", _) => false,
125-
// Selection bug <https://github.com/llvm/llvm-project/issues/96432>
126-
("mips64" | "mips64r6", _) => false,
127-
// Selection bug <https://github.com/llvm/llvm-project/issues/95471>
128-
("nvptx64", _) => false,
129-
// ABI bugs <https://github.com/rust-lang/rust/issues/125109> et al. (full
130-
// list at <https://github.com/rust-lang/rust/issues/116909>)
131-
("powerpc" | "powerpc64", _) => false,
132-
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
133-
("sparc", _) => false,
134-
// Stack alignment bug <https://github.com/llvm/llvm-project/issues/77401>. NB: tests may
135-
// not fail if our compiler-builtins is linked.
136-
("x86", _) => false,
137-
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
138-
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
139-
// There are no known problems on other platforms, so the only requirement is that symbols
140-
// are available. `compiler-builtins` provides all symbols required for core `f128`
141-
// support, so this should work for everything else.
142-
_ => true,
143-
};
144-
145-
// Configure platforms that have reliable basics but may have unreliable math.
146-
147-
// LLVM is currently adding missing routines, <https://github.com/llvm/llvm-project/issues/93566>
148-
let has_reliable_f16_math = has_reliable_f16
149-
&& match (target_arch.as_str(), target_os.as_str()) {
150-
// FIXME: Disabled on Miri as the intrinsics are not implemented yet.
151-
_ if is_miri => false,
152-
// x86 has a crash for `powi`: <https://github.com/llvm/llvm-project/issues/105747>
153-
("x86" | "x86_64", _) => false,
154-
// Assume that working `f16` means working `f16` math for most platforms, since
155-
// operations just go through `f32`.
156-
_ => true,
157-
};
158-
159-
let has_reliable_f128_math = has_reliable_f128
160-
&& match (target_arch.as_str(), target_os.as_str()) {
161-
// FIXME: Disabled on Miri as the intrinsics are not implemented yet.
162-
_ if is_miri => false,
163-
// LLVM lowers `fp128` math to `long double` symbols even on platforms where
164-
// `long double` is not IEEE binary128. See
165-
// <https://github.com/llvm/llvm-project/issues/44744>.
166-
//
167-
// This rules out anything that doesn't have `long double` = `binary128`; <= 32 bits
168-
// (ld is `f64`), anything other than Linux (Windows and MacOS use `f64`), and `x86`
169-
// (ld is 80-bit extended precision).
170-
("x86_64", _) => false,
171-
(_, "linux") if target_pointer_width == 64 => true,
172-
_ => false,
173-
};
174-
175-
if has_reliable_f16 {
176-
println!("cargo:rustc-cfg=reliable_f16");
177-
}
178-
if has_reliable_f128 {
179-
println!("cargo:rustc-cfg=reliable_f128");
180-
}
181-
if has_reliable_f16_math {
182-
println!("cargo:rustc-cfg=reliable_f16_math");
183-
}
184-
if has_reliable_f128_math {
185-
println!("cargo:rustc-cfg=reliable_f128_math");
186-
}
18777
}

‎library/std/src/f128.rs

Lines changed: 225 additions & 45 deletions
Large diffs are not rendered by default.

‎library/std/src/f16.rs

Lines changed: 225 additions & 45 deletions
Large diffs are not rendered by default.

‎library/std/tests/floats/f128.rs

Lines changed: 98 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
2-
#![cfg(reliable_f128)]
2+
#![cfg(not(bootstrap))]
3+
#![cfg(target_has_reliable_f128)]
34

45
use std::f128::consts;
56
use std::num::FpCategory as Fp;
6-
#[cfg(reliable_f128_math)]
7+
#[cfg(not(miri))]
8+
#[cfg(not(bootstrap))]
9+
#[cfg(target_has_reliable_f128_math)]
710
use std::ops::Rem;
811
use std::ops::{Add, Div, Mul, Sub};
912

@@ -19,7 +22,9 @@ const TOL: f128 = 1e-12;
1922

2023
/// Tolerances for math that is allowed to be imprecise, usually due to multiple chained
2124
/// operations.
22-
#[cfg(reliable_f128_math)]
25+
#[cfg(not(miri))]
26+
#[cfg(not(bootstrap))]
27+
#[cfg(target_has_reliable_f128_math)]
2328
const TOL_IMPR: f128 = 1e-10;
2429

2530
/// Smallest number
@@ -66,37 +71,50 @@ fn test_num_f128() {
6671
assert_eq!(ten.div(two), ten / two);
6772
}
6873

74+
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
75+
// the intrinsics.
76+
6977
#[test]
70-
#[cfg(reliable_f128_math)]
78+
#[cfg(not(miri))]
79+
#[cfg(not(bootstrap))]
80+
#[cfg(target_has_reliable_f128_math)]
7181
fn test_num_f128_rem() {
7282
let ten = 10f128;
7383
let two = 2f128;
7484
assert_eq!(ten.rem(two), ten % two);
7585
}
7686

7787
#[test]
78-
#[cfg(reliable_f128_math)]
88+
#[cfg(not(miri))]
89+
#[cfg(not(bootstrap))]
90+
#[cfg(target_has_reliable_f128_math)]
7991
fn test_min_nan() {
8092
assert_eq!(f128::NAN.min(2.0), 2.0);
8193
assert_eq!(2.0f128.min(f128::NAN), 2.0);
8294
}
8395

8496
#[test]
85-
#[cfg(reliable_f128_math)]
97+
#[cfg(not(miri))]
98+
#[cfg(not(bootstrap))]
99+
#[cfg(target_has_reliable_f128_math)]
86100
fn test_max_nan() {
87101
assert_eq!(f128::NAN.max(2.0), 2.0);
88102
assert_eq!(2.0f128.max(f128::NAN), 2.0);
89103
}
90104

91105
#[test]
92-
#[cfg(reliable_f128_math)]
106+
#[cfg(not(miri))]
107+
#[cfg(not(bootstrap))]
108+
#[cfg(target_has_reliable_f128_math)]
93109
fn test_minimum() {
94110
assert!(f128::NAN.minimum(2.0).is_nan());
95111
assert!(2.0f128.minimum(f128::NAN).is_nan());
96112
}
97113

98114
#[test]
99-
#[cfg(reliable_f128_math)]
115+
#[cfg(not(miri))]
116+
#[cfg(not(bootstrap))]
117+
#[cfg(target_has_reliable_f128_math)]
100118
fn test_maximum() {
101119
assert!(f128::NAN.maximum(2.0).is_nan());
102120
assert!(2.0f128.maximum(f128::NAN).is_nan());
@@ -253,7 +271,9 @@ fn test_classify() {
253271
}
254272

255273
#[test]
256-
#[cfg(reliable_f128_math)]
274+
#[cfg(not(miri))]
275+
#[cfg(not(bootstrap))]
276+
#[cfg(target_has_reliable_f128_math)]
257277
fn test_floor() {
258278
assert_approx_eq!(1.0f128.floor(), 1.0f128, TOL_PRECISE);
259279
assert_approx_eq!(1.3f128.floor(), 1.0f128, TOL_PRECISE);
@@ -268,7 +288,9 @@ fn test_floor() {
268288
}
269289

270290
#[test]
271-
#[cfg(reliable_f128_math)]
291+
#[cfg(not(miri))]
292+
#[cfg(not(bootstrap))]
293+
#[cfg(target_has_reliable_f128_math)]
272294
fn test_ceil() {
273295
assert_approx_eq!(1.0f128.ceil(), 1.0f128, TOL_PRECISE);
274296
assert_approx_eq!(1.3f128.ceil(), 2.0f128, TOL_PRECISE);
@@ -283,7 +305,9 @@ fn test_ceil() {
283305
}
284306

285307
#[test]
286-
#[cfg(reliable_f128_math)]
308+
#[cfg(not(miri))]
309+
#[cfg(not(bootstrap))]
310+
#[cfg(target_has_reliable_f128_math)]
287311
fn test_round() {
288312
assert_approx_eq!(2.5f128.round(), 3.0f128, TOL_PRECISE);
289313
assert_approx_eq!(1.0f128.round(), 1.0f128, TOL_PRECISE);
@@ -299,7 +323,9 @@ fn test_round() {
299323
}
300324

301325
#[test]
302-
#[cfg(reliable_f128_math)]
326+
#[cfg(not(miri))]
327+
#[cfg(not(bootstrap))]
328+
#[cfg(target_has_reliable_f128_math)]
303329
fn test_round_ties_even() {
304330
assert_approx_eq!(2.5f128.round_ties_even(), 2.0f128, TOL_PRECISE);
305331
assert_approx_eq!(1.0f128.round_ties_even(), 1.0f128, TOL_PRECISE);
@@ -315,7 +341,9 @@ fn test_round_ties_even() {
315341
}
316342

317343
#[test]
318-
#[cfg(reliable_f128_math)]
344+
#[cfg(not(miri))]
345+
#[cfg(not(bootstrap))]
346+
#[cfg(target_has_reliable_f128_math)]
319347
fn test_trunc() {
320348
assert_approx_eq!(1.0f128.trunc(), 1.0f128, TOL_PRECISE);
321349
assert_approx_eq!(1.3f128.trunc(), 1.0f128, TOL_PRECISE);
@@ -330,7 +358,9 @@ fn test_trunc() {
330358
}
331359

332360
#[test]
333-
#[cfg(reliable_f128_math)]
361+
#[cfg(not(miri))]
362+
#[cfg(not(bootstrap))]
363+
#[cfg(target_has_reliable_f128_math)]
334364
fn test_fract() {
335365
assert_approx_eq!(1.0f128.fract(), 0.0f128, TOL_PRECISE);
336366
assert_approx_eq!(1.3f128.fract(), 0.3f128, TOL_PRECISE);
@@ -345,7 +375,9 @@ fn test_fract() {
345375
}
346376

347377
#[test]
348-
#[cfg(reliable_f128_math)]
378+
#[cfg(not(miri))]
379+
#[cfg(not(bootstrap))]
380+
#[cfg(target_has_reliable_f128_math)]
349381
fn test_abs() {
350382
assert_eq!(f128::INFINITY.abs(), f128::INFINITY);
351383
assert_eq!(1f128.abs(), 1f128);
@@ -445,7 +477,9 @@ fn test_next_down() {
445477
}
446478

447479
#[test]
448-
#[cfg(reliable_f128_math)]
480+
#[cfg(not(miri))]
481+
#[cfg(not(bootstrap))]
482+
#[cfg(target_has_reliable_f128_math)]
449483
fn test_mul_add() {
450484
let nan: f128 = f128::NAN;
451485
let inf: f128 = f128::INFINITY;
@@ -462,7 +496,9 @@ fn test_mul_add() {
462496
}
463497

464498
#[test]
465-
#[cfg(reliable_f16_math)]
499+
#[cfg(not(miri))]
500+
#[cfg(not(bootstrap))]
501+
#[cfg(target_has_reliable_f128_math)]
466502
fn test_recip() {
467503
let nan: f128 = f128::NAN;
468504
let inf: f128 = f128::INFINITY;
@@ -484,7 +520,9 @@ fn test_recip() {
484520
// Many math functions allow for less accurate results, so the next tolerance up is used
485521

486522
#[test]
487-
#[cfg(reliable_f128_math)]
523+
#[cfg(not(miri))]
524+
#[cfg(not(bootstrap))]
525+
#[cfg(target_has_reliable_f128_math)]
488526
fn test_powi() {
489527
let nan: f128 = f128::NAN;
490528
let inf: f128 = f128::INFINITY;
@@ -499,7 +537,9 @@ fn test_powi() {
499537
}
500538

501539
#[test]
502-
#[cfg(reliable_f128_math)]
540+
#[cfg(not(miri))]
541+
#[cfg(not(bootstrap))]
542+
#[cfg(target_has_reliable_f128_math)]
503543
fn test_powf() {
504544
let nan: f128 = f128::NAN;
505545
let inf: f128 = f128::INFINITY;
@@ -516,7 +556,9 @@ fn test_powf() {
516556
}
517557

518558
#[test]
519-
#[cfg(reliable_f128_math)]
559+
#[cfg(not(miri))]
560+
#[cfg(not(bootstrap))]
561+
#[cfg(target_has_reliable_f128_math)]
520562
fn test_sqrt_domain() {
521563
assert!(f128::NAN.sqrt().is_nan());
522564
assert!(f128::NEG_INFINITY.sqrt().is_nan());
@@ -528,7 +570,9 @@ fn test_sqrt_domain() {
528570
}
529571

530572
#[test]
531-
#[cfg(reliable_f128_math)]
573+
#[cfg(not(miri))]
574+
#[cfg(not(bootstrap))]
575+
#[cfg(target_has_reliable_f128_math)]
532576
fn test_exp() {
533577
assert_eq!(1.0, 0.0f128.exp());
534578
assert_approx_eq!(consts::E, 1.0f128.exp(), TOL);
@@ -543,7 +587,9 @@ fn test_exp() {
543587
}
544588

545589
#[test]
546-
#[cfg(reliable_f128_math)]
590+
#[cfg(not(miri))]
591+
#[cfg(not(bootstrap))]
592+
#[cfg(target_has_reliable_f128_math)]
547593
fn test_exp2() {
548594
assert_eq!(32.0, 5.0f128.exp2());
549595
assert_eq!(1.0, 0.0f128.exp2());
@@ -557,7 +603,9 @@ fn test_exp2() {
557603
}
558604

559605
#[test]
560-
#[cfg(reliable_f128_math)]
606+
#[cfg(not(miri))]
607+
#[cfg(not(bootstrap))]
608+
#[cfg(target_has_reliable_f128_math)]
561609
fn test_ln() {
562610
let nan: f128 = f128::NAN;
563611
let inf: f128 = f128::INFINITY;
@@ -573,7 +621,9 @@ fn test_ln() {
573621
}
574622

575623
#[test]
576-
#[cfg(reliable_f128_math)]
624+
#[cfg(not(miri))]
625+
#[cfg(not(bootstrap))]
626+
#[cfg(target_has_reliable_f128_math)]
577627
fn test_log() {
578628
let nan: f128 = f128::NAN;
579629
let inf: f128 = f128::INFINITY;
@@ -592,7 +642,9 @@ fn test_log() {
592642
}
593643

594644
#[test]
595-
#[cfg(reliable_f128_math)]
645+
#[cfg(not(miri))]
646+
#[cfg(not(bootstrap))]
647+
#[cfg(target_has_reliable_f128_math)]
596648
fn test_log2() {
597649
let nan: f128 = f128::NAN;
598650
let inf: f128 = f128::INFINITY;
@@ -609,7 +661,9 @@ fn test_log2() {
609661
}
610662

611663
#[test]
612-
#[cfg(reliable_f128_math)]
664+
#[cfg(not(miri))]
665+
#[cfg(not(bootstrap))]
666+
#[cfg(target_has_reliable_f128_math)]
613667
fn test_log10() {
614668
let nan: f128 = f128::NAN;
615669
let inf: f128 = f128::INFINITY;
@@ -659,7 +713,9 @@ fn test_to_radians() {
659713
}
660714

661715
#[test]
662-
#[cfg(reliable_f128_math)]
716+
#[cfg(not(miri))]
717+
#[cfg(not(bootstrap))]
718+
#[cfg(target_has_reliable_f128_math)]
663719
fn test_asinh() {
664720
// Lower accuracy results are allowed, use increased tolerances
665721
assert_eq!(0.0f128.asinh(), 0.0f128);
@@ -690,7 +746,9 @@ fn test_asinh() {
690746
}
691747

692748
#[test]
693-
#[cfg(reliable_f128_math)]
749+
#[cfg(not(miri))]
750+
#[cfg(not(bootstrap))]
751+
#[cfg(target_has_reliable_f128_math)]
694752
fn test_acosh() {
695753
assert_eq!(1.0f128.acosh(), 0.0f128);
696754
assert!(0.999f128.acosh().is_nan());
@@ -709,7 +767,9 @@ fn test_acosh() {
709767
}
710768

711769
#[test]
712-
#[cfg(reliable_f128_math)]
770+
#[cfg(not(miri))]
771+
#[cfg(not(bootstrap))]
772+
#[cfg(target_has_reliable_f128_math)]
713773
fn test_atanh() {
714774
assert_eq!(0.0f128.atanh(), 0.0f128);
715775
assert_eq!((-0.0f128).atanh(), -0.0f128);
@@ -729,7 +789,9 @@ fn test_atanh() {
729789
}
730790

731791
#[test]
732-
#[cfg(reliable_f128_math)]
792+
#[cfg(not(miri))]
793+
#[cfg(not(bootstrap))]
794+
#[cfg(target_has_reliable_f128_math)]
733795
fn test_gamma() {
734796
// precision can differ among platforms
735797
assert_approx_eq!(1.0f128.gamma(), 1.0f128, TOL_IMPR);
@@ -750,7 +812,9 @@ fn test_gamma() {
750812
}
751813

752814
#[test]
753-
#[cfg(reliable_f128_math)]
815+
#[cfg(not(miri))]
816+
#[cfg(not(bootstrap))]
817+
#[cfg(target_has_reliable_f128_math)]
754818
fn test_ln_gamma() {
755819
assert_approx_eq!(1.0f128.ln_gamma().0, 0.0f128, TOL_IMPR);
756820
assert_eq!(1.0f128.ln_gamma().1, 1);
@@ -781,7 +845,9 @@ fn test_real_consts() {
781845
assert_approx_eq!(frac_1_pi, 1f128 / pi, TOL_PRECISE);
782846
assert_approx_eq!(frac_2_pi, 2f128 / pi, TOL_PRECISE);
783847

784-
#[cfg(reliable_f128_math)]
848+
#[cfg(not(miri))]
849+
#[cfg(not(bootstrap))]
850+
#[cfg(target_has_reliable_f128_math)]
785851
{
786852
let frac_2_sqrtpi: f128 = consts::FRAC_2_SQRT_PI;
787853
let sqrt2: f128 = consts::SQRT_2;

‎library/std/tests/floats/f16.rs

Lines changed: 92 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
2-
#![cfg(reliable_f16)]
2+
#![cfg(not(bootstrap))]
3+
#![cfg(target_has_reliable_f16)]
34

45
use std::f16::consts;
56
use std::num::FpCategory as Fp;
@@ -57,29 +58,40 @@ fn test_num_f16() {
5758
crate::test_num(10f16, 2f16);
5859
}
5960

61+
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
62+
// the intrinsics.
63+
6064
#[test]
61-
#[cfg(reliable_f16_math)]
65+
#[cfg(not(miri))]
66+
#[cfg(not(bootstrap))]
67+
#[cfg(target_has_reliable_f16_math)]
6268
fn test_min_nan() {
6369
assert_eq!(f16::NAN.min(2.0), 2.0);
6470
assert_eq!(2.0f16.min(f16::NAN), 2.0);
6571
}
6672

6773
#[test]
68-
#[cfg(reliable_f16_math)]
74+
#[cfg(not(miri))]
75+
#[cfg(not(bootstrap))]
76+
#[cfg(target_has_reliable_f16_math)]
6977
fn test_max_nan() {
7078
assert_eq!(f16::NAN.max(2.0), 2.0);
7179
assert_eq!(2.0f16.max(f16::NAN), 2.0);
7280
}
7381

7482
#[test]
75-
#[cfg(reliable_f16_math)]
83+
#[cfg(not(miri))]
84+
#[cfg(not(bootstrap))]
85+
#[cfg(target_has_reliable_f16_math)]
7686
fn test_minimum() {
7787
assert!(f16::NAN.minimum(2.0).is_nan());
7888
assert!(2.0f16.minimum(f16::NAN).is_nan());
7989
}
8090

8191
#[test]
82-
#[cfg(reliable_f16_math)]
92+
#[cfg(not(miri))]
93+
#[cfg(not(bootstrap))]
94+
#[cfg(target_has_reliable_f16_math)]
8395
fn test_maximum() {
8496
assert!(f16::NAN.maximum(2.0).is_nan());
8597
assert!(2.0f16.maximum(f16::NAN).is_nan());
@@ -236,7 +248,9 @@ fn test_classify() {
236248
}
237249

238250
#[test]
239-
#[cfg(reliable_f16_math)]
251+
#[cfg(not(miri))]
252+
#[cfg(not(bootstrap))]
253+
#[cfg(target_has_reliable_f16_math)]
240254
fn test_floor() {
241255
assert_approx_eq!(1.0f16.floor(), 1.0f16, TOL_0);
242256
assert_approx_eq!(1.3f16.floor(), 1.0f16, TOL_0);
@@ -251,7 +265,9 @@ fn test_floor() {
251265
}
252266

253267
#[test]
254-
#[cfg(reliable_f16_math)]
268+
#[cfg(not(miri))]
269+
#[cfg(not(bootstrap))]
270+
#[cfg(target_has_reliable_f16_math)]
255271
fn test_ceil() {
256272
assert_approx_eq!(1.0f16.ceil(), 1.0f16, TOL_0);
257273
assert_approx_eq!(1.3f16.ceil(), 2.0f16, TOL_0);
@@ -266,7 +282,9 @@ fn test_ceil() {
266282
}
267283

268284
#[test]
269-
#[cfg(reliable_f16_math)]
285+
#[cfg(not(miri))]
286+
#[cfg(not(bootstrap))]
287+
#[cfg(target_has_reliable_f16_math)]
270288
fn test_round() {
271289
assert_approx_eq!(2.5f16.round(), 3.0f16, TOL_0);
272290
assert_approx_eq!(1.0f16.round(), 1.0f16, TOL_0);
@@ -282,7 +300,9 @@ fn test_round() {
282300
}
283301

284302
#[test]
285-
#[cfg(reliable_f16_math)]
303+
#[cfg(not(miri))]
304+
#[cfg(not(bootstrap))]
305+
#[cfg(target_has_reliable_f16_math)]
286306
fn test_round_ties_even() {
287307
assert_approx_eq!(2.5f16.round_ties_even(), 2.0f16, TOL_0);
288308
assert_approx_eq!(1.0f16.round_ties_even(), 1.0f16, TOL_0);
@@ -298,7 +318,9 @@ fn test_round_ties_even() {
298318
}
299319

300320
#[test]
301-
#[cfg(reliable_f16_math)]
321+
#[cfg(not(miri))]
322+
#[cfg(not(bootstrap))]
323+
#[cfg(target_has_reliable_f16_math)]
302324
fn test_trunc() {
303325
assert_approx_eq!(1.0f16.trunc(), 1.0f16, TOL_0);
304326
assert_approx_eq!(1.3f16.trunc(), 1.0f16, TOL_0);
@@ -313,7 +335,9 @@ fn test_trunc() {
313335
}
314336

315337
#[test]
316-
#[cfg(reliable_f16_math)]
338+
#[cfg(not(miri))]
339+
#[cfg(not(bootstrap))]
340+
#[cfg(target_has_reliable_f16_math)]
317341
fn test_fract() {
318342
assert_approx_eq!(1.0f16.fract(), 0.0f16, TOL_0);
319343
assert_approx_eq!(1.3f16.fract(), 0.3f16, TOL_0);
@@ -328,7 +352,9 @@ fn test_fract() {
328352
}
329353

330354
#[test]
331-
#[cfg(reliable_f16_math)]
355+
#[cfg(not(miri))]
356+
#[cfg(not(bootstrap))]
357+
#[cfg(target_has_reliable_f16_math)]
332358
fn test_abs() {
333359
assert_eq!(f16::INFINITY.abs(), f16::INFINITY);
334360
assert_eq!(1f16.abs(), 1f16);
@@ -428,7 +454,9 @@ fn test_next_down() {
428454
}
429455

430456
#[test]
431-
#[cfg(reliable_f16_math)]
457+
#[cfg(not(miri))]
458+
#[cfg(not(bootstrap))]
459+
#[cfg(target_has_reliable_f16_math)]
432460
fn test_mul_add() {
433461
let nan: f16 = f16::NAN;
434462
let inf: f16 = f16::INFINITY;
@@ -445,7 +473,9 @@ fn test_mul_add() {
445473
}
446474

447475
#[test]
448-
#[cfg(reliable_f16_math)]
476+
#[cfg(not(miri))]
477+
#[cfg(not(bootstrap))]
478+
#[cfg(target_has_reliable_f16_math)]
449479
fn test_recip() {
450480
let nan: f16 = f16::NAN;
451481
let inf: f16 = f16::INFINITY;
@@ -461,7 +491,9 @@ fn test_recip() {
461491
}
462492

463493
#[test]
464-
#[cfg(reliable_f16_math)]
494+
#[cfg(not(miri))]
495+
#[cfg(not(bootstrap))]
496+
#[cfg(target_has_reliable_f16_math)]
465497
fn test_powi() {
466498
let nan: f16 = f16::NAN;
467499
let inf: f16 = f16::INFINITY;
@@ -476,7 +508,9 @@ fn test_powi() {
476508
}
477509

478510
#[test]
479-
#[cfg(reliable_f16_math)]
511+
#[cfg(not(miri))]
512+
#[cfg(not(bootstrap))]
513+
#[cfg(target_has_reliable_f16_math)]
480514
fn test_powf() {
481515
let nan: f16 = f16::NAN;
482516
let inf: f16 = f16::INFINITY;
@@ -493,7 +527,9 @@ fn test_powf() {
493527
}
494528

495529
#[test]
496-
#[cfg(reliable_f16_math)]
530+
#[cfg(not(miri))]
531+
#[cfg(not(bootstrap))]
532+
#[cfg(target_has_reliable_f16_math)]
497533
fn test_sqrt_domain() {
498534
assert!(f16::NAN.sqrt().is_nan());
499535
assert!(f16::NEG_INFINITY.sqrt().is_nan());
@@ -505,7 +541,9 @@ fn test_sqrt_domain() {
505541
}
506542

507543
#[test]
508-
#[cfg(reliable_f16_math)]
544+
#[cfg(not(miri))]
545+
#[cfg(not(bootstrap))]
546+
#[cfg(target_has_reliable_f16_math)]
509547
fn test_exp() {
510548
assert_eq!(1.0, 0.0f16.exp());
511549
assert_approx_eq!(2.718282, 1.0f16.exp(), TOL_0);
@@ -520,7 +558,9 @@ fn test_exp() {
520558
}
521559

522560
#[test]
523-
#[cfg(reliable_f16_math)]
561+
#[cfg(not(miri))]
562+
#[cfg(not(bootstrap))]
563+
#[cfg(target_has_reliable_f16_math)]
524564
fn test_exp2() {
525565
assert_eq!(32.0, 5.0f16.exp2());
526566
assert_eq!(1.0, 0.0f16.exp2());
@@ -534,7 +574,9 @@ fn test_exp2() {
534574
}
535575

536576
#[test]
537-
#[cfg(reliable_f16_math)]
577+
#[cfg(not(miri))]
578+
#[cfg(not(bootstrap))]
579+
#[cfg(target_has_reliable_f16_math)]
538580
fn test_ln() {
539581
let nan: f16 = f16::NAN;
540582
let inf: f16 = f16::INFINITY;
@@ -550,7 +592,9 @@ fn test_ln() {
550592
}
551593

552594
#[test]
553-
#[cfg(reliable_f16_math)]
595+
#[cfg(not(miri))]
596+
#[cfg(not(bootstrap))]
597+
#[cfg(target_has_reliable_f16_math)]
554598
fn test_log() {
555599
let nan: f16 = f16::NAN;
556600
let inf: f16 = f16::INFINITY;
@@ -569,7 +613,9 @@ fn test_log() {
569613
}
570614

571615
#[test]
572-
#[cfg(reliable_f16_math)]
616+
#[cfg(not(miri))]
617+
#[cfg(not(bootstrap))]
618+
#[cfg(target_has_reliable_f16_math)]
573619
fn test_log2() {
574620
let nan: f16 = f16::NAN;
575621
let inf: f16 = f16::INFINITY;
@@ -586,7 +632,9 @@ fn test_log2() {
586632
}
587633

588634
#[test]
589-
#[cfg(reliable_f16_math)]
635+
#[cfg(not(miri))]
636+
#[cfg(not(bootstrap))]
637+
#[cfg(target_has_reliable_f16_math)]
590638
fn test_log10() {
591639
let nan: f16 = f16::NAN;
592640
let inf: f16 = f16::INFINITY;
@@ -634,7 +682,9 @@ fn test_to_radians() {
634682
}
635683

636684
#[test]
637-
#[cfg(reliable_f16_math)]
685+
#[cfg(not(miri))]
686+
#[cfg(not(bootstrap))]
687+
#[cfg(target_has_reliable_f16_math)]
638688
fn test_asinh() {
639689
assert_eq!(0.0f16.asinh(), 0.0f16);
640690
assert_eq!((-0.0f16).asinh(), -0.0f16);
@@ -659,7 +709,9 @@ fn test_asinh() {
659709
}
660710

661711
#[test]
662-
#[cfg(reliable_f16_math)]
712+
#[cfg(not(miri))]
713+
#[cfg(not(bootstrap))]
714+
#[cfg(target_has_reliable_f16_math)]
663715
fn test_acosh() {
664716
assert_eq!(1.0f16.acosh(), 0.0f16);
665717
assert!(0.999f16.acosh().is_nan());
@@ -678,7 +730,9 @@ fn test_acosh() {
678730
}
679731

680732
#[test]
681-
#[cfg(reliable_f16_math)]
733+
#[cfg(not(miri))]
734+
#[cfg(not(bootstrap))]
735+
#[cfg(target_has_reliable_f16_math)]
682736
fn test_atanh() {
683737
assert_eq!(0.0f16.atanh(), 0.0f16);
684738
assert_eq!((-0.0f16).atanh(), -0.0f16);
@@ -698,7 +752,9 @@ fn test_atanh() {
698752
}
699753

700754
#[test]
701-
#[cfg(reliable_f16_math)]
755+
#[cfg(not(miri))]
756+
#[cfg(not(bootstrap))]
757+
#[cfg(target_has_reliable_f16_math)]
702758
fn test_gamma() {
703759
// precision can differ among platforms
704760
assert_approx_eq!(1.0f16.gamma(), 1.0f16, TOL_0);
@@ -719,7 +775,9 @@ fn test_gamma() {
719775
}
720776

721777
#[test]
722-
#[cfg(reliable_f16_math)]
778+
#[cfg(not(miri))]
779+
#[cfg(not(bootstrap))]
780+
#[cfg(target_has_reliable_f16_math)]
723781
fn test_ln_gamma() {
724782
assert_approx_eq!(1.0f16.ln_gamma().0, 0.0f16, TOL_0);
725783
assert_eq!(1.0f16.ln_gamma().1, 1);
@@ -752,7 +810,9 @@ fn test_real_consts() {
752810
assert_approx_eq!(frac_1_pi, 1f16 / pi, TOL_0);
753811
assert_approx_eq!(frac_2_pi, 2f16 / pi, TOL_0);
754812

755-
#[cfg(reliable_f16_math)]
813+
#[cfg(not(miri))]
814+
#[cfg(not(bootstrap))]
815+
#[cfg(target_has_reliable_f16_math)]
756816
{
757817
let frac_2_sqrtpi: f16 = consts::FRAC_2_SQRT_PI;
758818
let sqrt2: f16 = consts::SQRT_2;
@@ -813,7 +873,9 @@ fn test_clamp_max_is_nan() {
813873
}
814874

815875
#[test]
816-
#[cfg(reliable_f16_math)]
876+
#[cfg(not(miri))]
877+
#[cfg(not(bootstrap))]
878+
#[cfg(target_has_reliable_f16_math)]
817879
fn test_total_cmp() {
818880
use core::cmp::Ordering;
819881

‎library/std/tests/floats/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![feature(f16, f128, float_algebraic, float_gamma, float_minimum_maximum)]
2+
#![cfg_attr(not(bootstrap), feature(cfg_target_has_reliable_f16_f128))]
3+
#![cfg_attr(not(bootstrap), expect(internal_features))] // for reliable_f16_f128
24

35
use std::fmt;
46
use std::ops::{Add, Div, Mul, Rem, Sub};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: unexpected `--cfg target_has_reliable_f128` flag
2+
|
3+
= note: config `target_has_reliable_f128` is only supposed to be controlled by `--target`
4+
= note: manually setting a built-in cfg can and does create incoherent behaviors
5+
= note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: unexpected `--cfg target_has_reliable_f128_math` flag
2+
|
3+
= note: config `target_has_reliable_f128_math` is only supposed to be controlled by `--target`
4+
= note: manually setting a built-in cfg can and does create incoherent behaviors
5+
= note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: unexpected `--cfg target_has_reliable_f16` flag
2+
|
3+
= note: config `target_has_reliable_f16` is only supposed to be controlled by `--target`
4+
= note: manually setting a built-in cfg can and does create incoherent behaviors
5+
= note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: unexpected `--cfg target_has_reliable_f16_math` flag
2+
|
3+
= note: config `target_has_reliable_f16_math` is only supposed to be controlled by `--target`
4+
= note: manually setting a built-in cfg can and does create incoherent behaviors
5+
= note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
6+
7+
error: aborting due to 1 previous error
8+

‎tests/ui/cfg/disallowed-cli-cfgs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//@ revisions: target_thread_local_ relocation_model_
99
//@ revisions: fmt_debug_
1010
//@ revisions: emscripten_wasm_eh_
11+
//@ revisions: reliable_f16_ reliable_f16_math_ reliable_f128_ reliable_f128_math_
1112

1213
//@ [overflow_checks_]compile-flags: --cfg overflow_checks
1314
//@ [debug_assertions_]compile-flags: --cfg debug_assertions
@@ -35,6 +36,10 @@
3536
//@ [relocation_model_]compile-flags: --cfg relocation_model="a"
3637
//@ [fmt_debug_]compile-flags: --cfg fmt_debug="shallow"
3738
//@ [emscripten_wasm_eh_]compile-flags: --cfg emscripten_wasm_eh
39+
//@ [reliable_f16_]compile-flags: --cfg target_has_reliable_f16
40+
//@ [reliable_f16_math_]compile-flags: --cfg target_has_reliable_f16_math
41+
//@ [reliable_f128_]compile-flags: --cfg target_has_reliable_f128
42+
//@ [reliable_f128_math_]compile-flags: --cfg target_has_reliable_f128_math
3843

3944
fn main() {}
4045

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ compile-flags: --check-cfg=cfg(target_has_reliable_f16,target_has_reliable_f16_math,target_has_reliable_f128,target_has_reliable_f128_math)
2+
3+
fn main() {
4+
cfg!(target_has_reliable_f16);
5+
//~^ ERROR `cfg(target_has_reliable_f16)` is experimental and subject to change
6+
cfg!(target_has_reliable_f16_math);
7+
//~^ ERROR `cfg(target_has_reliable_f16_math)` is experimental and subject to change
8+
cfg!(target_has_reliable_f128);
9+
//~^ ERROR `cfg(target_has_reliable_f128)` is experimental and subject to change
10+
cfg!(target_has_reliable_f128_math);
11+
//~^ ERROR `cfg(target_has_reliable_f128_math)` is experimental and subject to change
12+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0658]: `cfg(target_has_reliable_f16)` is experimental and subject to change
2+
--> $DIR/feature-gate-cfg-target-has-reliable-f16-f128.rs:4:10
3+
|
4+
LL | cfg!(target_has_reliable_f16);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(cfg_target_has_reliable_f16_f128)]` to the crate attributes to enable
8+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9+
10+
error[E0658]: `cfg(target_has_reliable_f16_math)` is experimental and subject to change
11+
--> $DIR/feature-gate-cfg-target-has-reliable-f16-f128.rs:6:10
12+
|
13+
LL | cfg!(target_has_reliable_f16_math);
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= help: add `#![feature(cfg_target_has_reliable_f16_f128)]` to the crate attributes to enable
17+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
18+
19+
error[E0658]: `cfg(target_has_reliable_f128)` is experimental and subject to change
20+
--> $DIR/feature-gate-cfg-target-has-reliable-f16-f128.rs:8:10
21+
|
22+
LL | cfg!(target_has_reliable_f128);
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^
24+
|
25+
= help: add `#![feature(cfg_target_has_reliable_f16_f128)]` to the crate attributes to enable
26+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
27+
28+
error[E0658]: `cfg(target_has_reliable_f128_math)` is experimental and subject to change
29+
--> $DIR/feature-gate-cfg-target-has-reliable-f16-f128.rs:10:10
30+
|
31+
LL | cfg!(target_has_reliable_f128_math);
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
|
34+
= help: add `#![feature(cfg_target_has_reliable_f16_f128)]` to the crate attributes to enable
35+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
36+
37+
error: aborting due to 4 previous errors
38+
39+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ run-pass
2+
//@ compile-flags: --check-cfg=cfg(target_has_reliable_f16,target_has_reliable_f16_math,target_has_reliable_f128,target_has_reliable_f128_math)
3+
// Verify that the feature gates and config work and are registered as known config
4+
// options.
5+
6+
#![deny(unexpected_cfgs)]
7+
#![feature(cfg_target_has_reliable_f16_f128)]
8+
9+
#[cfg(target_has_reliable_f16)]
10+
pub fn has_f16() {}
11+
12+
#[cfg(target_has_reliable_f16_math)]
13+
pub fn has_f16_math() {}
14+
15+
#[cfg(target_has_reliable_f128 )]
16+
pub fn has_f128() {}
17+
18+
#[cfg(target_has_reliable_f128_math)]
19+
pub fn has_f128_math() {}
20+
21+
fn main() {
22+
if cfg!(target_arch = "aarch64") && cfg!(target_os = "linux") {
23+
// Aarch64+Linux is one target that has support for all features, so use it to spot
24+
// check that the compiler does indeed enable these gates.
25+
26+
assert!(cfg!(target_has_reliable_f16));
27+
assert!(cfg!(target_has_reliable_f16_math));
28+
assert!(cfg!(target_has_reliable_f128));
29+
assert!(cfg!(target_has_reliable_f128_math));
30+
}
31+
}

0 commit comments

Comments
 (0)
This repository has been archived.