From 38d129eeb4162c5b896c56ae68d5a8c80d690d65 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 2 Oct 2025 09:13:29 +0200 Subject: [PATCH 1/2] rustup --- src/tools/miri/rust-version | 2 +- src/tools/miri/tests/genmc/pass/std/arc.check_count.stderr | 2 +- src/tools/miri/tests/genmc/pass/std/arc.try_upgrade.stderr | 2 +- src/tools/miri/tests/genmc/pass/std/empty_main.stderr | 2 +- src/tools/miri/tests/genmc/pass/std/spawn_std_threads.stderr | 2 +- src/tools/miri/tests/genmc/pass/std/thread_locals.stderr | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index 70374af27e9c..4e388e04ea44 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -29b7717de23f3969ceeb5bef5b01d9223f807655 +42b384ec0dfcd528d99a4db0a337d9188a9eecaa diff --git a/src/tools/miri/tests/genmc/pass/std/arc.check_count.stderr b/src/tools/miri/tests/genmc/pass/std/arc.check_count.stderr index f2c574283cbf..3dccd7059538 100644 --- a/src/tools/miri/tests/genmc/pass/std/arc.check_count.stderr +++ b/src/tools/miri/tests/genmc/pass/std/arc.check_count.stderr @@ -12,7 +12,7 @@ LL | intrinsics::atomic_cxchgweak::::unwrap_or_else::<{closure@std::thread::current::id::get_or_init::{closure#0}}>` at RUSTLIB/core/src/option.rs:LL:CC = note: inside `std::thread::current::id::get_or_init` at RUSTLIB/std/src/thread/current.rs:LL:CC - = note: inside `std::thread::current::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC + = note: inside `std::thread::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC = note: inside `std::rt::init` at RUSTLIB/std/src/rt.rs:LL:CC = note: inside closure at RUSTLIB/std/src/rt.rs:LL:CC = note: inside `std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at RUSTLIB/std/src/panicking.rs:LL:CC diff --git a/src/tools/miri/tests/genmc/pass/std/arc.try_upgrade.stderr b/src/tools/miri/tests/genmc/pass/std/arc.try_upgrade.stderr index a7dacdeba4e4..dc59632558c8 100644 --- a/src/tools/miri/tests/genmc/pass/std/arc.try_upgrade.stderr +++ b/src/tools/miri/tests/genmc/pass/std/arc.try_upgrade.stderr @@ -12,7 +12,7 @@ LL | intrinsics::atomic_cxchgweak::::unwrap_or_else::<{closure@std::thread::current::id::get_or_init::{closure#0}}>` at RUSTLIB/core/src/option.rs:LL:CC = note: inside `std::thread::current::id::get_or_init` at RUSTLIB/std/src/thread/current.rs:LL:CC - = note: inside `std::thread::current::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC + = note: inside `std::thread::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC = note: inside `std::rt::init` at RUSTLIB/std/src/rt.rs:LL:CC = note: inside closure at RUSTLIB/std/src/rt.rs:LL:CC = note: inside `std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at RUSTLIB/std/src/panicking.rs:LL:CC diff --git a/src/tools/miri/tests/genmc/pass/std/empty_main.stderr b/src/tools/miri/tests/genmc/pass/std/empty_main.stderr index 36ba5481f472..44c307a6b3e4 100644 --- a/src/tools/miri/tests/genmc/pass/std/empty_main.stderr +++ b/src/tools/miri/tests/genmc/pass/std/empty_main.stderr @@ -12,7 +12,7 @@ LL | intrinsics::atomic_cxchgweak::::unwrap_or_else::<{closure@std::thread::current::id::get_or_init::{closure#0}}>` at RUSTLIB/core/src/option.rs:LL:CC = note: inside `std::thread::current::id::get_or_init` at RUSTLIB/std/src/thread/current.rs:LL:CC - = note: inside `std::thread::current::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC + = note: inside `std::thread::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC = note: inside `std::rt::init` at RUSTLIB/std/src/rt.rs:LL:CC = note: inside closure at RUSTLIB/std/src/rt.rs:LL:CC = note: inside `std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at RUSTLIB/std/src/panicking.rs:LL:CC diff --git a/src/tools/miri/tests/genmc/pass/std/spawn_std_threads.stderr b/src/tools/miri/tests/genmc/pass/std/spawn_std_threads.stderr index d6195b4e9b21..22a58f4e9cef 100644 --- a/src/tools/miri/tests/genmc/pass/std/spawn_std_threads.stderr +++ b/src/tools/miri/tests/genmc/pass/std/spawn_std_threads.stderr @@ -12,7 +12,7 @@ LL | intrinsics::atomic_cxchgweak::::unwrap_or_else::<{closure@std::thread::current::id::get_or_init::{closure#0}}>` at RUSTLIB/core/src/option.rs:LL:CC = note: inside `std::thread::current::id::get_or_init` at RUSTLIB/std/src/thread/current.rs:LL:CC - = note: inside `std::thread::current::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC + = note: inside `std::thread::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC = note: inside `std::rt::init` at RUSTLIB/std/src/rt.rs:LL:CC = note: inside closure at RUSTLIB/std/src/rt.rs:LL:CC = note: inside `std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at RUSTLIB/std/src/panicking.rs:LL:CC diff --git a/src/tools/miri/tests/genmc/pass/std/thread_locals.stderr b/src/tools/miri/tests/genmc/pass/std/thread_locals.stderr index ff971301bc66..e9b780fc007f 100644 --- a/src/tools/miri/tests/genmc/pass/std/thread_locals.stderr +++ b/src/tools/miri/tests/genmc/pass/std/thread_locals.stderr @@ -12,7 +12,7 @@ LL | intrinsics::atomic_cxchgweak::::unwrap_or_else::<{closure@std::thread::current::id::get_or_init::{closure#0}}>` at RUSTLIB/core/src/option.rs:LL:CC = note: inside `std::thread::current::id::get_or_init` at RUSTLIB/std/src/thread/current.rs:LL:CC - = note: inside `std::thread::current::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC + = note: inside `std::thread::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC = note: inside `std::rt::init` at RUSTLIB/std/src/rt.rs:LL:CC = note: inside closure at RUSTLIB/std/src/rt.rs:LL:CC = note: inside `std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at RUSTLIB/std/src/panicking.rs:LL:CC From a5d16293706cdf02ea275e976ce9f6c3a20c3d3f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 2 Oct 2025 09:25:19 +0200 Subject: [PATCH 2/2] make cur_span and current_span harder to mix up --- .../borrow_tracker/stacked_borrows/diagnostics.rs | 8 ++++---- .../miri/src/borrow_tracker/tree_borrows/mod.rs | 12 ++++++------ src/tools/miri/src/concurrency/data_race.rs | 14 +++++++------- src/tools/miri/src/concurrency/genmc/helper.rs | 6 +++++- src/tools/miri/src/concurrency/thread.rs | 4 ++-- src/tools/miri/src/helpers.rs | 4 ++-- src/tools/miri/src/machine.rs | 6 +++--- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs b/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs index 63b18028a5b9..997d7799a5f1 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs @@ -221,7 +221,7 @@ impl AllocHistory { pub fn new(id: AllocId, item: Item, machine: &MiriMachine<'_>) -> Self { Self { id, - root: (item, machine.current_span()), + root: (item, machine.current_user_relevant_span()), creations: SmallVec::new(), invalidations: SmallVec::new(), protectors: SmallVec::new(), @@ -269,11 +269,11 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> { }; self.history .creations - .push(Creation { retag: op.clone(), span: self.machine.current_span() }); + .push(Creation { retag: op.clone(), span: self.machine.current_user_relevant_span() }); } pub fn log_invalidation(&mut self, tag: BorTag) { - let mut span = self.machine.current_span(); + let mut span = self.machine.current_user_relevant_span(); let (range, cause) = match &self.operation { Operation::Retag(RetagOp { info, range, permission, .. }) => { if info.cause == RetagCause::FnEntry { @@ -298,7 +298,7 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> { }; self.history .protectors - .push(Protection { tag: op.new_tag, span: self.machine.current_span() }); + .push(Protection { tag: op.new_tag, span: self.machine.current_user_relevant_span() }); } pub fn get_logs_relevant_to( diff --git a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs index 6e5b5c807aa2..865097af1018 100644 --- a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs @@ -33,7 +33,7 @@ impl<'tcx> Tree { machine: &MiriMachine<'tcx>, ) -> Self { let tag = state.root_ptr_tag(id, machine); // Fresh tag for the root - let span = machine.current_span(); + let span = machine.current_user_relevant_span(); Tree::new(tag, size, span) } @@ -61,7 +61,7 @@ impl<'tcx> Tree { ProvenanceExtra::Wildcard => return interp_ok(()), }; let global = machine.borrow_tracker.as_ref().unwrap(); - let span = machine.current_span(); + let span = machine.current_user_relevant_span(); self.perform_access( tag, Some((range, access_kind, diagnostics::AccessCause::Explicit(access_kind))), @@ -86,7 +86,7 @@ impl<'tcx> Tree { ProvenanceExtra::Wildcard => return interp_ok(()), }; let global = machine.borrow_tracker.as_ref().unwrap(); - let span = machine.current_span(); + let span = machine.current_user_relevant_span(); self.dealloc(tag, alloc_range(Size::ZERO, size), global, alloc_id, span) } @@ -107,7 +107,7 @@ impl<'tcx> Tree { tag: BorTag, alloc_id: AllocId, // diagnostics ) -> InterpResult<'tcx> { - let span = machine.current_span(); + let span = machine.current_user_relevant_span(); // `None` makes it the magic on-protector-end operation self.perform_access(tag, None, global, alloc_id, span) } @@ -360,7 +360,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Some((range_in_alloc, AccessKind::Read, diagnostics::AccessCause::Reborrow)), this.machine.borrow_tracker.as_ref().unwrap(), alloc_id, - this.machine.current_span(), + this.machine.current_user_relevant_span(), )?; // Also inform the data race model (but only if any bytes are actually affected). @@ -386,7 +386,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> { inside_perms, new_perm.outside_perm, protected, - this.machine.current_span(), + this.machine.current_user_relevant_span(), )?; drop(tree_borrows); diff --git a/src/tools/miri/src/concurrency/data_race.rs b/src/tools/miri/src/concurrency/data_race.rs index 1ad9ace1b5d1..1f30f9d7288a 100644 --- a/src/tools/miri/src/concurrency/data_race.rs +++ b/src/tools/miri/src/concurrency/data_race.rs @@ -1208,7 +1208,7 @@ impl VClockAlloc { ty: Option>, machine: &MiriMachine<'_>, ) -> InterpResult<'tcx> { - let current_span = machine.current_span(); + let current_span = machine.current_user_relevant_span(); let global = machine.data_race.as_vclocks_ref().unwrap(); if !global.race_detecting() { return interp_ok(()); @@ -1250,7 +1250,7 @@ impl VClockAlloc { ty: Option>, machine: &mut MiriMachine<'_>, ) -> InterpResult<'tcx> { - let current_span = machine.current_span(); + let current_span = machine.current_user_relevant_span(); let global = machine.data_race.as_vclocks_mut().unwrap(); if !global.race_detecting() { return interp_ok(()); @@ -1304,7 +1304,7 @@ impl Default for LocalClocks { impl FrameState { pub fn local_write(&self, local: mir::Local, storage_live: bool, machine: &MiriMachine<'_>) { - let current_span = machine.current_span(); + let current_span = machine.current_user_relevant_span(); let global = machine.data_race.as_vclocks_ref().unwrap(); if !global.race_detecting() { return; @@ -1334,7 +1334,7 @@ impl FrameState { } pub fn local_read(&self, local: mir::Local, machine: &MiriMachine<'_>) { - let current_span = machine.current_span(); + let current_span = machine.current_user_relevant_span(); let global = machine.data_race.as_vclocks_ref().unwrap(); if !global.race_detecting() { return; @@ -1573,7 +1573,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { size.bytes() ); - let current_span = this.machine.current_span(); + let current_span = this.machine.current_user_relevant_span(); // Perform the atomic operation. data_race.maybe_perform_sync_operation( &this.machine.threads, @@ -1827,7 +1827,7 @@ impl GlobalState { machine: &MiriMachine<'tcx>, atomic: AtomicFenceOrd, ) -> InterpResult<'tcx> { - let current_span = machine.current_span(); + let current_span = machine.current_user_relevant_span(); self.maybe_perform_sync_operation(&machine.threads, current_span, |index, mut clocks| { trace!("Atomic fence on {:?} with ordering {:?}", index, atomic); @@ -1915,7 +1915,7 @@ impl GlobalState { callback: impl FnOnce(&VClock) -> R, ) -> R { let thread = threads.active_thread(); - let span = threads.active_thread_ref().current_span(); + let span = threads.active_thread_ref().current_user_relevant_span(); let (index, mut clocks) = self.thread_state_mut(thread); let r = callback(&clocks.clock); // Increment the clock, so that all following events cannot be confused with anything that diff --git a/src/tools/miri/src/concurrency/genmc/helper.rs b/src/tools/miri/src/concurrency/genmc/helper.rs index ebbef23a2a54..b79fe0e94299 100644 --- a/src/tools/miri/src/concurrency/genmc/helper.rs +++ b/src/tools/miri/src/concurrency/genmc/helper.rs @@ -37,7 +37,11 @@ pub(super) fn emit_warning<'tcx>( cache: &WarningCache, diagnostic: impl FnOnce() -> NonHaltingDiagnostic, ) { - let span = ecx.machine.current_span(); + // FIXME: This is not the right span to use (it's always inside the local crates so if the same + // operation is invoked from multiple places it will warn multiple times). `cur_span` is not + // right either though (we should honor `#[track_caller]`). Ultimately what we want is "the + // primary span the warning would point at". + let span = ecx.machine.current_user_relevant_span(); if cache.read().unwrap().contains(&span) { return; } diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs index 246300f8dda1..0d9dbe052e39 100644 --- a/src/tools/miri/src/concurrency/thread.rs +++ b/src/tools/miri/src/concurrency/thread.rs @@ -263,7 +263,7 @@ impl<'tcx> Thread<'tcx> { self.top_user_relevant_frame.or_else(|| self.stack.len().checked_sub(1)) } - pub fn current_span(&self) -> Span { + pub fn current_user_relevant_span(&self) -> Span { self.top_user_relevant_frame() .map(|frame_idx| self.stack[frame_idx].current_span()) .unwrap_or(rustc_span::DUMMY_SP) @@ -867,7 +867,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let mut state = tls::TlsDtorsState::default(); Box::new(move |m| state.on_stack_empty(m)) }); - let current_span = this.machine.current_span(); + let current_span = this.machine.current_user_relevant_span(); match &mut this.machine.data_race { GlobalDataRaceHandler::None => {} GlobalDataRaceHandler::Vclocks(data_race) => diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index e0c077e99319..3f736435bbc4 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -1128,8 +1128,8 @@ impl<'tcx> MiriMachine<'tcx> { /// `#[track_caller]`. /// This function is backed by a cache, and can be assumed to be very fast. /// It will work even when the stack is empty. - pub fn current_span(&self) -> Span { - self.threads.active_thread_ref().current_span() + pub fn current_user_relevant_span(&self) -> Span { + self.threads.active_thread_ref().current_user_relevant_span() } /// Returns the span of the *caller* of the current operation, again diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 53b8fea979c7..a1e63f6ae4ec 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -919,7 +919,7 @@ impl<'tcx> MiriMachine<'tcx> { &ecx.machine.threads, size, kind, - ecx.machine.current_span(), + ecx.machine.current_user_relevant_span(), ), data_race.weak_memory.then(weak_memory::AllocState::new_allocation), ), @@ -943,7 +943,7 @@ impl<'tcx> MiriMachine<'tcx> { ecx.machine .allocation_spans .borrow_mut() - .insert(id, (ecx.machine.current_span(), None)); + .insert(id, (ecx.machine.current_user_relevant_span(), None)); } interp_ok(AllocExtra { borrow_tracker, data_race, backtrace, sync: FxHashMap::default() }) @@ -1566,7 +1566,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { } if let Some((_, deallocated_at)) = machine.allocation_spans.borrow_mut().get_mut(&alloc_id) { - *deallocated_at = Some(machine.current_span()); + *deallocated_at = Some(machine.current_user_relevant_span()); } machine.free_alloc_id(alloc_id, size, align, kind); interp_ok(())