Skip to content

Commit 880229d

Browse files
committed
escape-on-cast, now ptr-deref does not change the tag at all, ever
1 parent b7dbb5e commit 880229d

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,9 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
461461
// No tracking
462462
Ok(place.ptr)
463463
} else {
464-
let ptr = place.ptr.to_ptr()?; // assert this is not a scalar
465-
let tag = ecx.tag_dereference(place, size, mutability.into())?;
466-
Ok(Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag)))
464+
ecx.ptr_dereference(place, size, mutability.into())?;
465+
// We never change the pointer
466+
Ok(place.ptr)
467467
}
468468
}
469469

src/stacked_borrows.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,12 @@ impl<'tcx> Stacks {
405405

406406

407407
pub trait EvalContextExt<'tcx> {
408-
fn tag_dereference(
408+
fn ptr_dereference(
409409
&self,
410410
place: MPlaceTy<'tcx, Borrow>,
411411
size: Size,
412412
mutability: Option<Mutability>,
413-
) -> EvalResult<'tcx, Borrow>;
413+
) -> EvalResult<'tcx>;
414414

415415
fn tag_new_allocation(
416416
&mut self,
@@ -480,13 +480,13 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for MiriEvalContext<'a, 'mir, 'tcx> {
480480
///
481481
/// Note that this does NOT mean that all this memory will actually get accessed/referenced!
482482
/// We could be in the middle of `&(*var).1`.
483-
fn tag_dereference(
483+
fn ptr_dereference(
484484
&self,
485485
place: MPlaceTy<'tcx, Borrow>,
486486
size: Size,
487487
mutability: Option<Mutability>,
488-
) -> EvalResult<'tcx, Borrow> {
489-
trace!("tag_dereference: Accessing {} reference for {:?} (pointee {})",
488+
) -> EvalResult<'tcx> {
489+
trace!("ptr_dereference: Accessing {} reference for {:?} (pointee {})",
490490
if let Some(mutability) = mutability { format!("{:?}", mutability) } else { format!("raw") },
491491
place.ptr, place.layout.ty);
492492
let ptr = place.ptr.to_ptr()?;
@@ -497,12 +497,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for MiriEvalContext<'a, 'mir, 'tcx> {
497497
// That can transmute a raw ptr to a (shared/mut) ref, and a mut ref to a shared one.
498498
match (mutability, ptr.tag) {
499499
(None, _) => {
500-
// Don't use the tag, this is a raw access! They should happen tagless.
501-
// This is needed for `*mut` to make any sense: Writes *do* enforce the
502-
// `Uniq` tag to be up top, but we must make sure raw writes do not do that.
503-
// This does mean, however, that `&*foo` is *not* a NOP *if* `foo` is a raw ptr.
504-
// Also don't do any further validation, this is raw after all.
505-
return Ok(Borrow::default());
500+
// No further validation on raw accesses.
501+
return Ok(());
506502
}
507503
(Some(MutMutable), Borrow::Uniq(_)) |
508504
(Some(MutImmutable), Borrow::Shr(_)) => {
@@ -543,8 +539,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for MiriEvalContext<'a, 'mir, 'tcx> {
543539
alloc.extra.deref(ptr, size, kind)?;
544540
}
545541

546-
// All is good, and do not change the tag
547-
Ok(ptr.tag)
542+
// All is good
543+
Ok(())
548544
}
549545

550546
/// The given place may henceforth be accessed through raw pointers.
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// error-pattern: mutable reference with frozen tag
2-
31
mod safe {
42
use std::slice::from_raw_parts_mut;
53

@@ -12,10 +10,8 @@ mod safe {
1210

1311
fn main() {
1412
let v = vec![0,1,2];
15-
let _v1 = safe::as_mut_slice(&v);
16-
/*
17-
let v2 = safe::as_mut_slice(&v);
13+
let v1 = safe::as_mut_slice(&v);
14+
let _v2 = safe::as_mut_slice(&v);
1815
v1[1] = 5;
19-
v1[1] = 6;
20-
*/
16+
//~^ ERROR does not exist on the stack
2117
}

tests/compile-fail-fullmir/stacked_borrows/transmute-is-no-escape.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ use std::mem;
88
fn main() {
99
let mut x: i32 = 42;
1010
let raw: *mut i32 = unsafe { mem::transmute(&mut x) };
11+
let raw = raw as usize as *mut i32; // make sure we killed the tag
1112
unsafe { *raw = 13; } //~ ERROR does not exist on the stack
1213
}

0 commit comments

Comments
 (0)