Protocol violations in libstd and miri's test suite
Exclusive UnsafeCell(AtomicBool::get_mut)
pubfnget_mut(&mutself) -> &mutbool {
unsafe { &mut *(self.v.get() as *mutbool) }
}
The get here is UnsafeCell::get which returns a raw ptr, so the self borrow is very short. Once we turn the returned ptr into a ref again, we have two overlapping mutable reference.
(Found because miri ran into it.)
passing ownership via raw ptrs(mem::swap,Vec::into_boxed_slice, std::panicking::try::do_call)
pubfnswap<T>(x: &mut T, y: &mut T) {
unsafe {
ptr::swap_nonoverlapping(x, y, 1);
}
}
swap_nonoverlapping takes raw pointers, so the write lock stays in swap. Similar for ptr::read.
Exclusive UnsafeCell (AtomicBool::get_mut)
pub fn get_mut(&mut self) -> &mut bool {
unsafe { &mut *(self.v.get() as *mut bool) }
}
passing ownership via raw ptrs (mem::swap, Vec::into_boxed_slice, std::panicking::try::do_call)
pub fn swap<T>(x: &mut T, y: &mut T) {
unsafe {
ptr::swap_nonoverlapping(x, y, 1);
}
}
split_at_mut
fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
let len = self.len();
let ptr = self.as_mut_ptr();
unsafe {
assert!(mid <= len);
(from_raw_parts_mut(ptr, mid),
from_raw_parts_mut(ptr.offset(mid as isize), len - mid))
}
}
Box::from_raw
RawVec::into_box
pub unsafe fn into_box(self) -> Box<[T]> {
// NOTE: not calling `cap()` here, actually using the real `cap` field!
let slice = slice::from_raw_parts_mut(self.ptr(), self.cap);
let output: Box<[T]> = Box::from_raw(slice);
mem::forget(self);
output
}
Ordering of StorageDead and EndRegion (rustc bug)
fn slice_index() -> u8 {
let arr: &[_] = &[101, 102, 103, 104, 105, 106];
arr[5]
}
Validate(Suspend(ReScope(Remainder(BlockRemainder { block: NodeId(92), first_statement_index: 0 }))), [_4@[u8; 6]]);
_3 = &_4;
...