From 1296a4c689b3e2aa0ecc3122982d6b0f96b90e0c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 2 Jan 2023 16:05:49 +0100 Subject: [PATCH] tweaks to retag diagnostic handling --- .../borrow_tracker/stacked_borrows/diagnostics.rs | 12 ++++-------- .../miri/src/borrow_tracker/stacked_borrows/mod.rs | 2 +- .../tests/fail/stacked_borrows/aliasing_mut3.stderr | 4 ++-- .../fail/stacked_borrows/fnentry_invalidation.stderr | 2 +- .../stacked_borrows/fnentry_invalidation2.stderr | 2 +- 5 files changed, 9 insertions(+), 13 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 5f132bf11a92a..2cc8f03546602 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs @@ -88,11 +88,7 @@ impl fmt::Display for InvalidationCause { match self { InvalidationCause::Access(kind) => write!(f, "{kind}"), InvalidationCause::Retag(perm, kind) => - if *kind == RetagCause::FnEntry { - write!(f, "{perm:?} FnEntry retag") - } else { - write!(f, "{perm:?} retag") - }, + write!(f, "{perm:?} {retag}", retag = kind.summary()), } } } @@ -193,7 +189,7 @@ struct RetagOp { #[derive(Debug, Clone, Copy, PartialEq)] pub enum RetagCause { Normal, - FnReturn, + FnReturnPlace, FnEntry, TwoPhase, } @@ -495,8 +491,8 @@ impl RetagCause { fn summary(&self) -> String { match self { RetagCause::Normal => "retag", - RetagCause::FnEntry => "FnEntry retag", - RetagCause::FnReturn => "FnReturn retag", + RetagCause::FnEntry => "function-entry retag", + RetagCause::FnReturnPlace => "return-place retag", RetagCause::TwoPhase => "two-phase retag", } .to_string() diff --git a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs index bcdf2e751790e..ec555ba2895c8 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs @@ -998,7 +998,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { access: Some(AccessKind::Write), protector: Some(ProtectorKind::StrongProtector), }; - let val = this.sb_retag_reference(&val, new_perm, RetagCause::FnReturn)?; + let val = this.sb_retag_reference(&val, new_perm, RetagCause::FnReturnPlace)?; // And use reborrowed pointer for return place. let return_place = this.ref_to_mplace(&val)?; this.frame_mut().return_place = return_place.into(); diff --git a/src/tools/miri/tests/fail/stacked_borrows/aliasing_mut3.stderr b/src/tools/miri/tests/fail/stacked_borrows/aliasing_mut3.stderr index 55aaed62f4f5f..ae54d0248dc3d 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/aliasing_mut3.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/aliasing_mut3.stderr @@ -5,7 +5,7 @@ LL | pub fn safe(_x: &mut i32, _y: &i32) {} | ^^ | | | trying to retag from for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location - | this error occurs as part of FnEntry retag at ALLOC[0x0..0x4] + | this error occurs as part of function-entry retag at ALLOC[0x0..0x4] | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -14,7 +14,7 @@ help: was created by a SharedReadOnly retag at offsets [0x0..0x4] | LL | safe_raw(xraw, xshr); | ^^^^ -help: was later invalidated at offsets [0x0..0x4] by a Unique FnEntry retag inside this call +help: was later invalidated at offsets [0x0..0x4] by a Unique function-entry retag inside this call --> $DIR/aliasing_mut3.rs:LL:CC | LL | safe_raw(xraw, xshr); diff --git a/src/tools/miri/tests/fail/stacked_borrows/fnentry_invalidation.stderr b/src/tools/miri/tests/fail/stacked_borrows/fnentry_invalidation.stderr index e3bffde1f0176..236c8fb0187de 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/fnentry_invalidation.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/fnentry_invalidation.stderr @@ -14,7 +14,7 @@ help: was created by a SharedReadWrite retag at offsets [0x0..0x4] | LL | let z = &mut x as *mut i32; | ^^^^^^ -help: was later invalidated at offsets [0x0..0x4] by a Unique FnEntry retag inside this call +help: was later invalidated at offsets [0x0..0x4] by a Unique function-entry retag inside this call --> $DIR/fnentry_invalidation.rs:LL:CC | LL | x.do_bad(); diff --git a/src/tools/miri/tests/fail/stacked_borrows/fnentry_invalidation2.stderr b/src/tools/miri/tests/fail/stacked_borrows/fnentry_invalidation2.stderr index b104de4b8d94d..45c2197050a1b 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/fnentry_invalidation2.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/fnentry_invalidation2.stderr @@ -14,7 +14,7 @@ help: was created by a SharedReadOnly retag at offsets [0x0..0xc] | LL | let ptr = t.sli.as_ptr(); | ^^^^^^^^^^^^^^ -help: was later invalidated at offsets [0x0..0xc] by a Unique FnEntry retag inside this call +help: was later invalidated at offsets [0x0..0xc] by a Unique function-entry retag inside this call --> $DIR/fnentry_invalidation2.rs:LL:CC | LL | let _ = t.sli.as_mut_ptr();