1 // compile-flags: -Zmir-opt-level=0
2 #![feature(const_float_bits_conv)]
3 #![feature(const_float_classify)]
6 const fn nop<T>(x: T) -> T { x }
8 macro_rules! const_assert {
11 const _: () = assert!($a);
15 ($a:expr, $b:expr) => {
17 const _: () = assert!($a == $b);
18 assert_eq!(nop($a), nop($b));
24 // Check that NaNs roundtrip their bits regardless of signalingness
25 // 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
26 // ...actually, let's just check that these break. :D
27 const MASKED_NAN1: u32 = f32::NAN.to_bits() ^ 0x002A_AAAA;
28 const MASKED_NAN2: u32 = f32::NAN.to_bits() ^ 0x0055_5555;
30 const_assert!(f32::from_bits(MASKED_NAN1).is_nan());
31 //~^ ERROR any use of this value will cause an error
32 //~| WARNING this was previously accepted
33 const_assert!(f32::from_bits(MASKED_NAN1).is_nan());
34 //~^ ERROR any use of this value will cause an error
35 //~| WARNING this was previously accepted
37 // LLVM does not guarantee that loads and stores of NaNs preserve their exact bit pattern.
38 // In practice, this seems to only cause a problem on x86, since the most widely used calling
39 // convention mandates that floating point values are returned on the x87 FPU stack. See #73328.
40 if !cfg!(target_arch = "x86") {
41 const_assert!(f32::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
42 //~^ ERROR any use of this value will cause an error
43 //~| WARNING this was previously accepted
44 const_assert!(f32::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
45 //~^ ERROR any use of this value will cause an error
46 //~| WARNING this was previously accepted
51 // Check that NaNs roundtrip their bits regardless of signalingness
52 // 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
53 // ...actually, let's just check that these break. :D
54 const MASKED_NAN1: u64 = f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA;
55 const MASKED_NAN2: u64 = f64::NAN.to_bits() ^ 0x0005_5555_5555_5555;
57 const_assert!(f64::from_bits(MASKED_NAN1).is_nan());
58 //~^ ERROR any use of this value will cause an error
59 //~| WARNING this was previously accepted
60 const_assert!(f64::from_bits(MASKED_NAN1).is_nan());
61 //~^ ERROR any use of this value will cause an error
62 //~| WARNING this was previously accepted
65 if !cfg!(target_arch = "x86") {
66 const_assert!(f64::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
67 //~^ ERROR any use of this value will cause an error
68 //~| WARNING this was previously accepted
69 const_assert!(f64::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
70 //~^ ERROR any use of this value will cause an error
71 //~| WARNING this was previously accepted