Skip to content

Commit cea8099

Browse files
authored
Rollup merge of rust-lang#105317 - RalfJung:retag-rework, r=oli-obk
make retagging work even with 'unstable' places This is based on top of rust-lang#105301. Only the last two commits are new. While investigating rust-lang/unsafe-code-guidelines#381 I realized that we would have caught this issue much earlier if the add_retag pass wouldn't bail out on assignments of the form `*ptr = ...`. So this PR changes our retag strategy: - When a new reference is created via `Rvalue::Ref` (or a raw ptr via `Rvalue::AddressOf`), we do the retagging as part of just executing that address-taking operation. - For everything else, we still insert retags -- these retags basically serve to ensure that references stored in local variables (and their fields) are always freshly tagged, so skipping this for assignments like `*ptr = ...` is less egregious. r? ```@oli-obk```
2 parents 3abccef + c12f02e commit cea8099

File tree

5 files changed

+239
-179
lines changed

5 files changed

+239
-179
lines changed

src/borrow_tracker/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_target::abi::Size;
1111

1212
use crate::*;
1313
pub mod stacked_borrows;
14-
use stacked_borrows::diagnostics::RetagCause;
1514

1615
pub type CallId = NonZeroU64;
1716

@@ -265,11 +264,19 @@ impl GlobalStateInner {
265264

266265
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
267266
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
268-
fn retag(&mut self, kind: RetagKind, place: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
267+
fn retag_ptr_value(&mut self, kind: RetagKind, val: &ImmTy<'tcx, Provenance>) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
269268
let this = self.eval_context_mut();
270269
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
271270
match method {
272-
BorrowTrackerMethod::StackedBorrows => this.sb_retag(kind, place),
271+
BorrowTrackerMethod::StackedBorrows => this.sb_retag_ptr_value(kind, val),
272+
}
273+
}
274+
275+
fn retag_place_contents(&mut self, kind: RetagKind, place: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
276+
let this = self.eval_context_mut();
277+
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
278+
match method {
279+
BorrowTrackerMethod::StackedBorrows => this.sb_retag_place_contents(kind, place),
273280
}
274281
}
275282

src/borrow_tracker/stacked_borrows/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,10 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
459459
Operation::Dealloc(_) => format!(" due to deallocation"),
460460
Operation::Access(AccessOp { kind, tag, .. }) =>
461461
format!(" due to {kind:?} access for {tag:?}"),
462-
Operation::Retag(RetagOp { orig_tag, permission, .. }) => {
462+
Operation::Retag(RetagOp { orig_tag, permission, new_tag, .. }) => {
463463
let permission = permission
464464
.expect("start_grant should set the current permission before popping a tag");
465-
format!(" due to {permission:?} retag from {orig_tag:?}")
465+
format!(" due to {permission:?} retag from {orig_tag:?} (that retag created {new_tag:?})")
466466
}
467467
};
468468

0 commit comments

Comments
 (0)