diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-30 10:18:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-30 10:18:28 +0200 |
| commit | 254f050eb43ac5ceb00b35e77150bc792d815359 (patch) | |
| tree | e56405e75d4b7bb1902adf84d60454ad3cbfb57b /compiler/rustc_const_eval/src | |
| parent | 1267f0c07c4766bf44ed1b97b2d1388bd7d131a8 (diff) | |
| parent | 2393e447eba2edf86c90812a78b78b37a5374f6b (diff) | |
| download | rust-254f050eb43ac5ceb00b35e77150bc792d815359.tar.gz rust-254f050eb43ac5ceb00b35e77150bc792d815359.zip | |
Rollup merge of #140439 - RalfJung:miri-algebraic-float-nondet, r=oli-obk
miri: algebraic intrinsics: bring back float non-determinism Fixes https://github.com/rust-lang/miri/issues/4289 Cc ```@bjoernager``` r? ```@oli-obk```
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/intrinsics.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/machine.rs | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 97d066ffe3f..d67b547ba1a 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -183,8 +183,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let res = self.binary_op(op, &a, &b)?; // `binary_op` already called `generate_nan` if needed. - - // FIXME: Miri should add some non-determinism to the result here to catch any dependences on exact computations. This has previously been done, but the behaviour was removed as part of constification. + let res = M::apply_float_nondet(self, res)?; self.write_immediate(*res, dest)?; } diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index e5026eff21f..a1386b4e1be 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -276,6 +276,14 @@ pub trait Machine<'tcx>: Sized { F2::NAN } + /// Apply non-determinism to float operations that do not return a precise result. + fn apply_float_nondet( + _ecx: &mut InterpCx<'tcx, Self>, + val: ImmTy<'tcx, Self::Provenance>, + ) -> InterpResult<'tcx, ImmTy<'tcx, Self::Provenance>> { + interp_ok(val) + } + /// Determines the result of `min`/`max` on floats when the arguments are equal. fn equal_float_min_max<F: Float>(_ecx: &InterpCx<'tcx, Self>, a: F, _b: F) -> F { // By default, we pick the left argument. |
