rename track-raw-pointers flag to tag-raw-pointers

This commit is contained in:
Ralf Jung 2021-11-13 15:40:26 -05:00
parent a8b976eb35
commit d8bee92aee
17 changed files with 34 additions and 29 deletions

View File

@ -276,14 +276,13 @@ environment variable:
is popped from a borrow stack (which is where the tag becomes invalid and any
future use of it will error). This helps you in finding out why UB is
happening and where in your code would be a good place to look for it.
* `-Zmiri-track-raw-pointers` makes Stacked Borrows track a pointer tag even for
raw pointers. This can make valid code fail to pass the checks, but also can
help identify latent aliasing issues in code that Miri accepts by default. You
can recognize false positives by `<untagged>` occurring in the message -- this
indicates a pointer that was cast from an integer, so Miri was unable to track
this pointer. Note that it is not currently guaranteed that code that works
with `-Zmiri-track-raw-pointers` also works without
`-Zmiri-track-raw-pointers`, but for the vast majority of code, this will be the case.
* `-Zmiri-tag-raw-pointers` makes Stacked Borrows assign proper tags even for raw pointers. This can
make valid code using int-to-ptr casts fail to pass the checks, but also can help identify latent
aliasing issues in code that Miri accepts by default. You can recognize false positives by
`<untagged>` occurring in the message -- this indicates a pointer that was cast from an integer,
so Miri was unable to track this pointer. Note that it is not currently guaranteed that code that
works with `-Zmiri-tag-raw-pointers` also works without `-Zmiri-tag-raw-pointers`, but for the
vast majority of code, this will be the case.
[function ABI]: https://doc.rust-lang.org/reference/items/functions.html#extern-function-qualifier

View File

@ -359,8 +359,14 @@ fn main() {
"-Zmiri-panic-on-unsupported" => {
miri_config.panic_on_unsupported = true;
}
"-Zmiri-tag-raw-pointers" => {
miri_config.tag_raw = true;
}
"-Zmiri-track-raw-pointers" => {
miri_config.track_raw = true;
eprintln!(
"WARNING: -Zmiri-track-raw-pointers has been renamed to -Zmiri-tag-raw-pointers, the old name is deprecated."
);
miri_config.tag_raw = true;
}
"--" => {
after_dashdash = true;

View File

@ -87,7 +87,7 @@ pub struct MiriConfig {
/// The allocation id to report about.
pub tracked_alloc_id: Option<AllocId>,
/// Whether to track raw pointers in stacked borrows.
pub track_raw: bool,
pub tag_raw: bool,
/// Determine if data race detection should be enabled
pub data_race_detector: bool,
/// Rate of spurious failures for compare_exchange_weak atomic operations,
@ -116,7 +116,7 @@ impl Default for MiriConfig {
tracked_pointer_tag: None,
tracked_call_id: None,
tracked_alloc_id: None,
track_raw: false,
tag_raw: false,
data_race_detector: true,
cmpxchg_weak_failure_rate: 0.8,
measureme_out: None,

View File

@ -194,7 +194,7 @@ impl MemoryExtra {
Some(RefCell::new(stacked_borrows::GlobalState::new(
config.tracked_pointer_tag,
config.tracked_call_id,
config.track_raw,
config.tag_raw,
)))
} else {
None

View File

@ -105,7 +105,7 @@ pub struct GlobalState {
/// The call id to trace
tracked_call_id: Option<CallId>,
/// Whether to track raw pointers.
track_raw: bool,
tag_raw: bool,
}
/// Memory extra state gives us interior mutable access to the global state.
pub type MemoryExtra = RefCell<GlobalState>;
@ -156,7 +156,7 @@ impl GlobalState {
pub fn new(
tracked_pointer_tag: Option<PtrId>,
tracked_call_id: Option<CallId>,
track_raw: bool,
tag_raw: bool,
) -> Self {
GlobalState {
next_ptr_id: NonZeroU64::new(1).unwrap(),
@ -165,7 +165,7 @@ impl GlobalState {
active_calls: FxHashSet::default(),
tracked_pointer_tag,
tracked_call_id,
track_raw,
tag_raw,
}
}
@ -532,7 +532,7 @@ impl Stacks {
MiriMemoryKind::Rust | MiriMemoryKind::C | MiriMemoryKind::WinHeap,
) => {
let tag =
if extra.track_raw { extra.base_tag(id) } else { extra.base_tag_untagged(id) };
if extra.tag_raw { extra.base_tag(id) } else { extra.base_tag_untagged(id) };
(tag, Permission::SharedReadWrite)
}
};
@ -719,7 +719,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let mem_extra = this.memory.extra.stacked_borrows.as_mut().unwrap().get_mut();
match kind {
// Give up tracking for raw pointers.
RefKind::Raw { .. } if !mem_extra.track_raw => SbTag::Untagged,
RefKind::Raw { .. } if !mem_extra.tag_raw => SbTag::Untagged,
// All other pointers are properly tracked.
_ => SbTag::Tagged(mem_extra.new_ptr()),
}

View File

@ -127,7 +127,7 @@ def test_cargo_miri_test():
test("`cargo miri test` (raw-ptr tracking)",
cargo_miri("test"),
default_ref, "test.stderr-empty.ref",
env={'MIRIFLAGS': "-Zmiri-track-raw-pointers"},
env={'MIRIFLAGS': "-Zmiri-tag-raw-pointers"},
)
test("`cargo miri test` (with filter)",
cargo_miri("test") + ["--", "--format=pretty", "le1"],

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
// Taken from <https://github.com/rust-lang/unsafe-code-guidelines/issues/194#issuecomment-520934222>.

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
//! This demonstrates a provenance problem that requires tracking of raw pointers to be detected.
fn main() {

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
// error-pattern: does not have an appropriate item in the borrow stack
fn main() {

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
#![feature(btree_drain_filter)]
use std::collections::{BTreeMap, BTreeSet};
use std::mem;

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
//! Check that destructors of the thread locals are executed on all OSes.
#![feature(thread_local_const_init)]

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
#![feature(new_uninit)]
#![feature(get_mut_unchecked)]

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
#![feature(new_uninit)]
#![feature(slice_as_chunks)]
#![feature(slice_partition_dedup)]

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
use std::ptr;
// Test various stacked-borrows-related things.

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
fn empty() -> &'static str {
""

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
// Gather all references from a mutable iterator and make sure Miri notices if
// using them is dangerous.
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {

View File

@ -1,4 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
// compile-flags: -Zmiri-tag-raw-pointers
use std::collections::VecDeque;
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {