Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 33 additions & 36 deletions tests/ui/float/classify-runtime-const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,43 @@
//@ revisions: opt noopt ctfe
//@[opt] compile-flags: -O
//@[noopt] compile-flags: -Zmir-opt-level=0
//@ min-llvm-version: 22
//@ compile-flags: --check-cfg=cfg(target_has_reliable_f16)
//@ min-llvm-version: 23

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect, but have not checked, that this is needed for the black_box calls. Anyway, it seems fine to only test this for LLVM 23.

//@ compile-flags: --check-cfg=cfg(target_has_reliable_f16,target_has_reliable_f128)
// ignore-tidy-file-linelength
#![feature(cfg_target_has_reliable_f16_f128)]
#![cfg_attr(target_has_reliable_f16, feature(f16))]
#![cfg_attr(target_has_reliable_f128, feature(f128))]

// This tests the float classification functions, for regular runtime code and for const evaluation.


use std::num::FpCategory::*;

#[cfg(not(ctfe))]
use std::hint::black_box;
#[cfg(ctfe)]
#[allow(unused)]
const fn black_box<T>(x: T) -> T { x }
use std::num::FpCategory::*;

#[cfg(not(ctfe))]
macro_rules! assert_test {
($a:expr, NonDet) => {
{
// Compute `a`, but do not compare with anything as the result is non-deterministic.
let _val = $a;
}
};
($a:expr, $b:ident) => {
{
// Let-bind to avoid promotion.
// No black_box here! That can mask x87 failures.
let a = $a;
let b = $b;
assert_eq!(a, b, "{} produces wrong result", stringify!($a));
}
};
($a:expr, NonDet) => {{
// Compute `a`, but do not compare with anything as the result is non-deterministic.
let _val = $a;
}};
($a:expr, $b:ident) => {{
// Let-bind to avoid promotion.
// No black_box here! That can mask x87 failures.
let a = $a;
let b = $b;
assert_eq!(a, b, "{} produces wrong result", stringify!($a));
}};
}
#[cfg(ctfe)]
macro_rules! assert_test {
($a:expr, NonDet) => {
{
// Compute `a`, but do not compare with anything as the result is non-deterministic.
const _: () = { let _val = $a; };
}
};
($a:expr, $b:ident) => {
{
const _: () = assert!(matches!($a, $b));
}
};
($a:expr, NonDet) => {{
// Compute `a`, but do not compare with anything as the result is non-deterministic.
const _: () = {
let _val = $a;
};
}};
($a:expr, $b:ident) => {{
const _: () = assert!(matches!($a, $b));
}};
}

macro_rules! suite {
Expand All @@ -72,6 +61,13 @@ macro_rules! suite {
type $tyname = f64;
suite_inner!(f64 => $($tt)*);
}

#[cfg(target_has_reliable_f128)]
fn f128() {
#[allow(unused)]
type $tyname = f128;
suite_inner!(f128 => $($tt)*);
}
}
}

Expand Down Expand Up @@ -136,5 +132,6 @@ fn main() {
f16();
f32();
f64();
// FIXME(f128): also test f128
#[cfg(target_has_reliable_f128)]
f128();
}
Loading