From 9d3e35ceaaa6d38b0f5e2eb1b815fa0c2cf71262 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 7 Jul 2023 12:50:07 +0200 Subject: [PATCH] Add tests for #102403 and #113407 --- tests/ui/const_prop/apfloat-f64-roundtrip.rs | 9 +++++++++ .../ui/const_prop/apfloat-remainder-regression.rs | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/ui/const_prop/apfloat-f64-roundtrip.rs create mode 100644 tests/ui/const_prop/apfloat-remainder-regression.rs diff --git a/tests/ui/const_prop/apfloat-f64-roundtrip.rs b/tests/ui/const_prop/apfloat-f64-roundtrip.rs new file mode 100644 index 00000000000..9fb2ac96beb --- /dev/null +++ b/tests/ui/const_prop/apfloat-f64-roundtrip.rs @@ -0,0 +1,9 @@ +// run-pass +// compile-flags: -O -Zmir-opt-level=3 -Cno-prepopulate-passes +// min-llvm-version: 16.0 (requires APFloat fixes in LLVM) + +// Regression test for a broken MIR optimization (issue #113407). +pub fn main() { + let f = f64::from_bits(0x19873cc2) as f32; + assert_eq!(f.to_bits(), 0); +} diff --git a/tests/ui/const_prop/apfloat-remainder-regression.rs b/tests/ui/const_prop/apfloat-remainder-regression.rs new file mode 100644 index 00000000000..08932c333fd --- /dev/null +++ b/tests/ui/const_prop/apfloat-remainder-regression.rs @@ -0,0 +1,15 @@ +// run-pass +// compile-flags: -O -Zmir-opt-level=3 -Cno-prepopulate-passes + +// Regression test for a broken MIR optimization (issue #102403). +pub fn f() -> f64 { + std::hint::black_box(-1.0) % std::hint::black_box(-1.0) +} + +pub fn g() -> f64 { + -1.0 % -1.0 +} + +pub fn main() { + assert_eq!(f().signum(), g().signum()); +}