Skip to content

Commit 60e3bf4

Browse files
authored
Merge pull request rust-lang#4109 from RalfJung/flags
Error on some invalid flag combinations
2 parents cb73bb6 + 35f10b1 commit 60e3bf4

File tree

4 files changed

+24
-44
lines changed

4 files changed

+24
-44
lines changed

src/tools/miri/README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,10 @@ environment variable. We first document the most relevant and most commonly used
294294
will always fail and `0.0` means it will never fail. Note that setting it to
295295
`1.0` will likely cause hangs, since it means programs using
296296
`compare_exchange_weak` cannot make progress.
297-
* `-Zmiri-disable-isolation` disables host isolation. As a consequence,
297+
* `-Zmiri-disable-isolation` disables host isolation. As a consequence,
298298
the program has access to host resources such as environment variables, file
299299
systems, and randomness.
300+
This overwrites a previous `-Zmiri-isolation-error`.
300301
* `-Zmiri-disable-leak-backtraces` disables backtraces reports for memory leaks. By default, a
301302
backtrace is captured for every allocation when it is created, just in case it leaks. This incurs
302303
some memory overhead to store data that is almost never used. This flag is implied by
@@ -317,6 +318,7 @@ environment variable. We first document the most relevant and most commonly used
317318
execution with a "permission denied" error being returned to the program.
318319
`warn` prints a full backtrace each time that happens; `warn-nobacktrace` is less
319320
verbose and shown at most once per operation. `hide` hides the warning entirely.
321+
This overwrites a previous `-Zmiri-disable-isolation`.
320322
* `-Zmiri-many-seeds=[<from>]..<to>` runs the program multiple times with different seeds for Miri's
321323
RNG. With different seeds, Miri will make different choices to resolve non-determinism such as the
322324
order in which concurrent threads are scheduled, or the exact addresses assigned to allocations.
@@ -347,8 +349,8 @@ environment variable. We first document the most relevant and most commonly used
347349
can increase test coverage by running Miri multiple times with different seeds.
348350
* `-Zmiri-strict-provenance` enables [strict
349351
provenance](https://github.com/rust-lang/rust/issues/95228) checking in Miri. This means that
350-
casting an integer to a pointer yields a result with 'invalid' provenance, i.e., with provenance
351-
that cannot be used for any memory access.
352+
casting an integer to a pointer will stop execution because the provenance of the pointer
353+
cannot be determined.
352354
* `-Zmiri-symbolic-alignment-check` makes the alignment check more strict. By default, alignment is
353355
checked by casting the pointer to an integer, and making sure that is a multiple of the alignment.
354356
This can lead to cases where a program passes the alignment check by pure chance, because things
@@ -437,6 +439,8 @@ to Miri failing to detect cases of undefined behavior in a program.
437439
of Rust will be stricter than Tree Borrows. In other words, if you use Tree Borrows,
438440
even if your code is accepted today, it might be declared UB in the future.
439441
This is much less likely with Stacked Borrows.
442+
Using Tree Borrows currently implies `-Zmiri-strict-provenance` because integer-to-pointer
443+
casts are not supported in this mode, but that may change in the future.
440444
* `-Zmiri-force-page-size=<num>` overrides the default page size for an architecture, in multiples of 1k.
441445
`4` is default for most targets. This value should always be a power of 2 and nonzero.
442446
* `-Zmiri-unique-is-unique` performs additional aliasing checks for `core::ptr::Unique` to ensure

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

+15-33
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,6 @@ fn main() {
514514

515515
let mut rustc_args = vec![];
516516
let mut after_dashdash = false;
517-
// If user has explicitly enabled/disabled isolation
518-
let mut isolation_enabled: Option<bool> = None;
519517

520518
// Note that we require values to be given with `=`, not with a space.
521519
// This matches how rustc parses `-Z`.
@@ -539,6 +537,7 @@ fn main() {
539537
miri_config.borrow_tracker = None;
540538
} else if arg == "-Zmiri-tree-borrows" {
541539
miri_config.borrow_tracker = Some(BorrowTrackerMethod::TreeBorrows);
540+
miri_config.provenance_mode = ProvenanceMode::Strict;
542541
} else if arg == "-Zmiri-unique-is-unique" {
543542
miri_config.unique_is_unique = true;
544543
} else if arg == "-Zmiri-disable-data-race-detector" {
@@ -548,19 +547,7 @@ fn main() {
548547
miri_config.check_alignment = miri::AlignmentCheck::None;
549548
} else if arg == "-Zmiri-symbolic-alignment-check" {
550549
miri_config.check_alignment = miri::AlignmentCheck::Symbolic;
551-
} else if arg == "-Zmiri-disable-abi-check" {
552-
eprintln!(
553-
"WARNING: the flag `-Zmiri-disable-abi-check` no longer has any effect; \
554-
ABI checks cannot be disabled any more"
555-
);
556550
} else if arg == "-Zmiri-disable-isolation" {
557-
if matches!(isolation_enabled, Some(true)) {
558-
show_error!(
559-
"-Zmiri-disable-isolation cannot be used along with -Zmiri-isolation-error"
560-
);
561-
} else {
562-
isolation_enabled = Some(false);
563-
}
564551
miri_config.isolated_op = miri::IsolatedOp::Allow;
565552
} else if arg == "-Zmiri-disable-leak-backtraces" {
566553
miri_config.collect_leak_backtraces = false;
@@ -569,14 +556,6 @@ fn main() {
569556
} else if arg == "-Zmiri-track-weak-memory-loads" {
570557
miri_config.track_outdated_loads = true;
571558
} else if let Some(param) = arg.strip_prefix("-Zmiri-isolation-error=") {
572-
if matches!(isolation_enabled, Some(false)) {
573-
show_error!(
574-
"-Zmiri-isolation-error cannot be used along with -Zmiri-disable-isolation"
575-
);
576-
} else {
577-
isolation_enabled = Some(true);
578-
}
579-
580559
miri_config.isolated_op = match param {
581560
"abort" => miri::IsolatedOp::Reject(miri::RejectOpWith::Abort),
582561
"hide" => miri::IsolatedOp::Reject(miri::RejectOpWith::NoWarning),
@@ -622,10 +601,6 @@ fn main() {
622601
many_seeds = Some(0..64);
623602
} else if arg == "-Zmiri-many-seeds-keep-going" {
624603
many_seeds_keep_going = true;
625-
} else if let Some(_param) = arg.strip_prefix("-Zmiri-env-exclude=") {
626-
show_error!(
627-
"`-Zmiri-env-exclude` has been removed; unset env vars before starting Miri instead"
628-
);
629604
} else if let Some(param) = arg.strip_prefix("-Zmiri-env-forward=") {
630605
miri_config.forwarded_env_vars.push(param.to_owned());
631606
} else if let Some(param) = arg.strip_prefix("-Zmiri-env-set=") {
@@ -728,13 +703,20 @@ fn main() {
728703
"-Zmiri-unique-is-unique only has an effect when -Zmiri-tree-borrows is also used"
729704
);
730705
}
731-
// Tree Borrows + permissive provenance does not work.
732-
if miri_config.provenance_mode == ProvenanceMode::Permissive
733-
&& matches!(miri_config.borrow_tracker, Some(BorrowTrackerMethod::TreeBorrows))
734-
{
735-
show_error!(
736-
"Tree Borrows does not support integer-to-pointer casts, and is hence not compatible with permissive provenance"
737-
);
706+
// Tree Borrows implies strict provenance, and is not compatible with native calls.
707+
if matches!(miri_config.borrow_tracker, Some(BorrowTrackerMethod::TreeBorrows)) {
708+
if miri_config.provenance_mode != ProvenanceMode::Strict {
709+
show_error!(
710+
"Tree Borrows does not support integer-to-pointer casts, and hence requires strict provenance"
711+
);
712+
}
713+
if miri_config.native_lib.is_some() {
714+
show_error!("Tree Borrows is not compatible with calling native functions");
715+
}
716+
}
717+
// Native calls and strict provenance are not compatible.
718+
if miri_config.native_lib.is_some() && miri_config.provenance_mode == ProvenanceMode::Strict {
719+
show_error!("strict provenance is not compatible with calling native functions");
738720
}
739721
// You can set either one seed or many.
740722
if many_seeds.is_some() && miri_config.seed.is_some() {

src/tools/miri/tests/pass/ptr_int_casts.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
//@revisions: stack tree
2-
// Tree Borrows doesn't support int2ptr casts, but let's make sure we don't immediately crash either.
3-
//@[tree]compile-flags: -Zmiri-tree-borrows
4-
//@[stack]compile-flags: -Zmiri-permissive-provenance
1+
//@compile-flags: -Zmiri-permissive-provenance
52
use std::{mem, ptr};
63

74
fn eq_ref<T>(x: &T, y: &T) -> bool {

src/tools/miri/tests/pass/ptr_int_from_exposed.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
//@revisions: stack tree
2-
// Tree Borrows doesn't support int2ptr casts, but let's make sure we don't immediately crash either.
3-
//@[tree]compile-flags: -Zmiri-tree-borrows
4-
//@[stack]compile-flags: -Zmiri-permissive-provenance
1+
//@compile-flags: -Zmiri-permissive-provenance
52

63
use std::ptr;
74

0 commit comments

Comments
 (0)