From d8bee92aee3394d2fd9a0b83516651ee7141b032 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 13 Nov 2021 15:40:26 -0500 Subject: [PATCH] rename track-raw-pointers flag to tag-raw-pointers --- README.md | 15 +++++++-------- src/bin/miri.rs | 8 +++++++- src/eval.rs | 4 ++-- src/machine.rs | 2 +- src/stacked_borrows.rs | 10 +++++----- test-cargo-miri/run-test.py | 2 +- tests/compile-fail/box-cell-alias.rs | 2 +- .../compile-fail/stacked_borrows/raw_tracking.rs | 2 +- tests/compile-fail/stacked_borrows/zst_slice.rs | 2 +- tests/run-pass/btreemap.rs | 2 +- .../concurrency/tls_lib_drop_single_thread.rs | 2 +- tests/run-pass/rc.rs | 2 +- tests/run-pass/slices.rs | 2 +- tests/run-pass/stacked-borrows/stacked-borrows.rs | 2 +- tests/run-pass/strings.rs | 2 +- tests/run-pass/vec.rs | 2 +- tests/run-pass/vecdeque.rs | 2 +- 17 files changed, 34 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 504759eabd24..487f8aeb2baf 100644 --- a/README.md +++ b/README.md @@ -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 `` 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 + `` 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 diff --git a/src/bin/miri.rs b/src/bin/miri.rs index cf32e6332269..672c7e8c9675 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -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; diff --git a/src/eval.rs b/src/eval.rs index ac32af30c1de..e3f252b50a92 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -87,7 +87,7 @@ pub struct MiriConfig { /// The allocation id to report about. pub tracked_alloc_id: Option, /// 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, diff --git a/src/machine.rs b/src/machine.rs index 0ead28b36c75..201854e76fa4 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -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 diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index 65678b6f01fe..57c09ea40b68 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -105,7 +105,7 @@ pub struct GlobalState { /// The call id to trace tracked_call_id: Option, /// 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; @@ -156,7 +156,7 @@ impl GlobalState { pub fn new( tracked_pointer_tag: Option, tracked_call_id: Option, - 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()), } diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index 18671b2e29da..19965639489b 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -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"], diff --git a/tests/compile-fail/box-cell-alias.rs b/tests/compile-fail/box-cell-alias.rs index 5d63fc1d44a5..58fc3530d7bf 100644 --- a/tests/compile-fail/box-cell-alias.rs +++ b/tests/compile-fail/box-cell-alias.rs @@ -1,4 +1,4 @@ -// compile-flags: -Zmiri-track-raw-pointers +// compile-flags: -Zmiri-tag-raw-pointers // Taken from . diff --git a/tests/compile-fail/stacked_borrows/raw_tracking.rs b/tests/compile-fail/stacked_borrows/raw_tracking.rs index 975aec945c7f..0d6d0198fbe9 100644 --- a/tests/compile-fail/stacked_borrows/raw_tracking.rs +++ b/tests/compile-fail/stacked_borrows/raw_tracking.rs @@ -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() { diff --git a/tests/compile-fail/stacked_borrows/zst_slice.rs b/tests/compile-fail/stacked_borrows/zst_slice.rs index 0804f7303082..14d5d77a2bb6 100644 --- a/tests/compile-fail/stacked_borrows/zst_slice.rs +++ b/tests/compile-fail/stacked_borrows/zst_slice.rs @@ -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() { diff --git a/tests/run-pass/btreemap.rs b/tests/run-pass/btreemap.rs index b704b89fd050..842ba0f4a874 100644 --- a/tests/run-pass/btreemap.rs +++ b/tests/run-pass/btreemap.rs @@ -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; diff --git a/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs b/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs index cd1bd6480bcf..16ca8a0d2eff 100644 --- a/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs +++ b/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs @@ -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)] diff --git a/tests/run-pass/rc.rs b/tests/run-pass/rc.rs index 91de20ae2b7f..e00d9df32eec 100644 --- a/tests/run-pass/rc.rs +++ b/tests/run-pass/rc.rs @@ -1,4 +1,4 @@ -// compile-flags: -Zmiri-track-raw-pointers +// compile-flags: -Zmiri-tag-raw-pointers #![feature(new_uninit)] #![feature(get_mut_unchecked)] diff --git a/tests/run-pass/slices.rs b/tests/run-pass/slices.rs index 83d9ff115188..9d98c44741b4 100644 --- a/tests/run-pass/slices.rs +++ b/tests/run-pass/slices.rs @@ -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)] diff --git a/tests/run-pass/stacked-borrows/stacked-borrows.rs b/tests/run-pass/stacked-borrows/stacked-borrows.rs index 0401a6640fd3..8aea945f9093 100644 --- a/tests/run-pass/stacked-borrows/stacked-borrows.rs +++ b/tests/run-pass/stacked-borrows/stacked-borrows.rs @@ -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. diff --git a/tests/run-pass/strings.rs b/tests/run-pass/strings.rs index b009e8bc6c4a..6998ec6e59b9 100644 --- a/tests/run-pass/strings.rs +++ b/tests/run-pass/strings.rs @@ -1,4 +1,4 @@ -// compile-flags: -Zmiri-track-raw-pointers +// compile-flags: -Zmiri-tag-raw-pointers fn empty() -> &'static str { "" diff --git a/tests/run-pass/vec.rs b/tests/run-pass/vec.rs index 8ed81a5e343f..c0cf42134527 100644 --- a/tests/run-pass/vec.rs +++ b/tests/run-pass/vec.rs @@ -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) { diff --git a/tests/run-pass/vecdeque.rs b/tests/run-pass/vecdeque.rs index 54aeb89ec83f..f45c21d20781 100644 --- a/tests/run-pass/vecdeque.rs +++ b/tests/run-pass/vecdeque.rs @@ -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) {