Skip to content

Commit 2de4561

Browse files
committed
show an error on some invalid flag combinations: TB + permissive provenance; strict provenance + native calls
1 parent cb73bb6 commit 2de4561

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

Diff for: src/tools/miri/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ environment variable. We first document the most relevant and most commonly used
347347
can increase test coverage by running Miri multiple times with different seeds.
348348
* `-Zmiri-strict-provenance` enables [strict
349349
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.
350+
casting an integer to a pointer will stop execution because the provenance of the pointer
351+
cannot be determined.
352352
* `-Zmiri-symbolic-alignment-check` makes the alignment check more strict. By default, alignment is
353353
checked by casting the pointer to an integer, and making sure that is a multiple of the alignment.
354354
This can lead to cases where a program passes the alignment check by pure chance, because things
@@ -437,6 +437,8 @@ to Miri failing to detect cases of undefined behavior in a program.
437437
of Rust will be stricter than Tree Borrows. In other words, if you use Tree Borrows,
438438
even if your code is accepted today, it might be declared UB in the future.
439439
This is much less likely with Stacked Borrows.
440+
Using Tree Borrows currently implies `-Zmiri-strict-provenance` because integer-to-pointer
441+
casts are not supported in this mode, but that may change in the future.
440442
* `-Zmiri-force-page-size=<num>` overrides the default page size for an architecture, in multiples of 1k.
441443
`4` is default for most targets. This value should always be a power of 2 and nonzero.
442444
* `-Zmiri-unique-is-unique` performs additional aliasing checks for `core::ptr::Unique` to ensure

Diff for: src/tools/miri/src/bin/miri.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ fn main() {
539539
miri_config.borrow_tracker = None;
540540
} else if arg == "-Zmiri-tree-borrows" {
541541
miri_config.borrow_tracker = Some(BorrowTrackerMethod::TreeBorrows);
542+
miri_config.provenance_mode = ProvenanceMode::Strict;
542543
} else if arg == "-Zmiri-unique-is-unique" {
543544
miri_config.unique_is_unique = true;
544545
} else if arg == "-Zmiri-disable-data-race-detector" {
@@ -728,13 +729,20 @@ fn main() {
728729
"-Zmiri-unique-is-unique only has an effect when -Zmiri-tree-borrows is also used"
729730
);
730731
}
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-
);
732+
// Tree Borrows implies strict provenance, and is not compatible with native calls.
733+
if matches!(miri_config.borrow_tracker, Some(BorrowTrackerMethod::TreeBorrows)) {
734+
if miri_config.provenance_mode != ProvenanceMode::Strict {
735+
show_error!(
736+
"Tree Borrows does not support integer-to-pointer casts, and hence requires strict provenance"
737+
);
738+
}
739+
if miri_config.native_lib.is_some() {
740+
show_error!("Tree Borrows is not compatible with calling native functions");
741+
}
742+
}
743+
// Native calls and strict provenance are not compatible.
744+
if miri_config.native_lib.is_some() && miri_config.provenance_mode == ProvenanceMode::Strict {
745+
show_error!("strict provenance is not compatible with calling native functions");
738746
}
739747
// You can set either one seed or many.
740748
if many_seeds.is_some() && miri_config.seed.is_some() {

Diff for: 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 {

Diff for: 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)