Skip to content

Commit 4aa4376

Browse files
committed
add -Zmiri-no-extra-rounding-error to specifically disable just that part of float-nondet
1 parent eef454f commit 4aa4376

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

src/tools/miri/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,6 @@ environment variable. We first document the most relevant and most commonly used
286286
specific circumstances, but Miri's behavior will also be more stable across versions and targets.
287287
This is equivalent to `-Zmiri-fixed-schedule -Zmiri-compare-exchange-weak-failure-rate=0.0
288288
-Zmiri-address-reuse-cross-thread-rate=0.0 -Zmiri-disable-weak-memory-emulation`.
289-
* `-Zmiri-deterministic-floats` makes Miri's floating-point behavior fully deterministic. This means
290-
that operations will always return the preferred NaN, imprecise operations will not have any
291-
random error applied to them, and `min`/`max` as "maybe fused" multiply-add all behave
292-
deterministically. Note that Miri still uses host floats for some operations, so behavior can
293-
still differ depending on the host target and setup.
294289
* `-Zmiri-disable-isolation` disables host isolation. As a consequence,
295290
the program has access to host resources such as environment variables, file
296291
systems, and randomness.
@@ -324,6 +319,8 @@ environment variable. We first document the most relevant and most commonly used
324319
Can be used without a value; in that case the range defaults to `0..64`.
325320
* `-Zmiri-many-seeds-keep-going` tells Miri to really try all the seeds in the given range, even if
326321
a failing seed has already been found. This is useful to determine which fraction of seeds fails.
322+
* `-Zmiri-no-extra-rounding-error` stops Miri from adding extra rounding errors to float operations
323+
that do not have a guaranteed precision.
327324
* `-Zmiri-num-cpus` states the number of available CPUs to be reported by miri. By default, the
328325
number of available CPUs is `1`. Note that this flag does not affect how miri handles threads in
329326
any way.
@@ -376,6 +373,12 @@ to Miri failing to detect cases of undefined behavior in a program.
376373
will always fail and `0.0` means it will never fail. Note that setting it to
377374
`1.0` will likely cause hangs, since it means programs using
378375
`compare_exchange_weak` cannot make progress.
376+
* `-Zmiri-deterministic-floats` makes Miri's floating-point behavior fully deterministic. This means
377+
that operations will always return the preferred NaN, imprecise operations will not have any
378+
random error applied to them, and `min`/`max` and "maybe fused" multiply-add all behave
379+
deterministically. Note that Miri still uses host floats for some operations, so behavior can
380+
still differ depending on the host target and setup. See `-Zmiri-no-extra-rounding-error` for
381+
a flag that specifically only disables the random error.
379382
* `-Zmiri-disable-alignment-check` disables checking pointer alignment, so you
380383
can focus on other failures, but it means Miri can miss bugs in your program.
381384
Using this flag is **unsound**.

src/tools/miri/src/bin/miri.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ fn main() {
562562
miri_config.force_intrinsic_fallback = true;
563563
} else if arg == "-Zmiri-deterministic-floats" {
564564
miri_config.float_nondet = false;
565+
} else if arg == "-Zmiri-no-extra-rounding-error" {
566+
miri_config.float_rounding_error = false;
565567
} else if arg == "-Zmiri-strict-provenance" {
566568
miri_config.provenance_mode = ProvenanceMode::Strict;
567569
} else if arg == "-Zmiri-permissive-provenance" {

src/tools/miri/src/eval.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ pub struct MiriConfig {
170170
pub force_intrinsic_fallback: bool,
171171
/// Whether floating-point operations can behave non-deterministically.
172172
pub float_nondet: bool,
173+
/// Whether floating-point operations can have a non-deterministic rounding error.
174+
pub float_rounding_error: bool,
173175
}
174176

175177
impl Default for MiriConfig {
@@ -211,6 +213,7 @@ impl Default for MiriConfig {
211213
fixed_scheduling: false,
212214
force_intrinsic_fallback: false,
213215
float_nondet: true,
216+
float_rounding_error: true,
214217
}
215218
}
216219
}

src/tools/miri/src/machine.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ pub struct MiriMachine<'tcx> {
617617

618618
/// Whether floating-point operations can behave non-deterministically.
619619
pub float_nondet: bool,
620+
/// Whether floating-point operations can have a non-deterministic rounding error.
621+
pub float_rounding_error: bool,
620622
}
621623

622624
impl<'tcx> MiriMachine<'tcx> {
@@ -775,6 +777,7 @@ impl<'tcx> MiriMachine<'tcx> {
775777
mangle_internal_symbol_cache: Default::default(),
776778
force_intrinsic_fallback: config.force_intrinsic_fallback,
777779
float_nondet: config.float_nondet,
780+
float_rounding_error: config.float_rounding_error,
778781
}
779782
}
780783

@@ -951,6 +954,7 @@ impl VisitProvenance for MiriMachine<'_> {
951954
mangle_internal_symbol_cache: _,
952955
force_intrinsic_fallback: _,
953956
float_nondet: _,
957+
float_rounding_error: _,
954958
} = self;
955959

956960
threads.visit_provenance(visit);

src/tools/miri/src/math.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) fn apply_random_float_error<F: rustc_apfloat::Float>(
1515
val: F,
1616
err_scale: i32,
1717
) -> F {
18-
if !ecx.machine.float_nondet {
18+
if !ecx.machine.float_nondet || !ecx.machine.float_rounding_error {
1919
return val;
2020
}
2121

0 commit comments

Comments
 (0)