Skip to content

Commit 14dc656

Browse files
Fix miri issue 4579 by checking if the strong protector is actually "active".
Where "active" means that the accessed bit is set. This also reverts miri PR 3831.
1 parent 6f1f392 commit 14dc656

File tree

4 files changed

+4
-52
lines changed

4 files changed

+4
-52
lines changed

src/borrow_tracker/tree_borrows/tree.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ impl<'tcx> Tree {
756756
// Don't check for protector if it is a Cell (see `unsafe_cell_deallocate` in `interior_mutability.rs`).
757757
// Related to https://github.com/rust-lang/rust/issues/55005.
758758
&& !perm.permission().is_cell()
759+
// Only trigger UB if the accessed bit is set, i.e. if the protector is actually protecting this offset. See #4579.
760+
&& perm.is_accessed()
759761
{
760762
Err(TransitionError::ProtectedDealloc)
761763
} else {

tests/fail/both_borrows/zero-sized-protected.stack.stderr

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/fail/both_borrows/zero-sized-protected.tree.stderr

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/fail/both_borrows/zero-sized-protected.rs renamed to tests/pass/both_borrows/zero-sized-protected.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
use std::alloc::{Layout, alloc, dealloc};
44

55
// `x` is strongly protected but covers zero bytes.
6-
// Let's see if deallocating the allocation x points to is UB:
7-
// in TB, it is UB, but in SB it is not.
6+
// This should never be UB.
87
fn test(_x: &mut (), ptr: *mut u8, l: Layout) {
9-
unsafe { dealloc(ptr, l) }; //~[tree] ERROR: /deallocation .* is forbidden/
8+
unsafe { dealloc(ptr, l) };
109
}
1110

1211
fn main() {
1312
let l = Layout::from_size_align(1, 1).unwrap();
1413
let ptr = unsafe { alloc(l) };
1514
unsafe { test(&mut *ptr.cast::<()>(), ptr, l) };
16-
// In SB the test would pass if it weren't for this line.
17-
unsafe { std::hint::unreachable_unchecked() }; //~[stack] ERROR: unreachable
1815
}

0 commit comments

Comments
 (0)