move zero-sized protector dealloc test
This commit is contained in:
parent
2b5b191965
commit
16b34c6f70
2 changed files with 10 additions and 15 deletions
|
|
@ -1,6 +1,7 @@
|
|||
//@revisions: stack tree
|
||||
//@[tree]compile-flags: -Zmiri-tree-borrows
|
||||
#![feature(allocator_api)]
|
||||
use std::alloc::{Layout, alloc, dealloc};
|
||||
use std::cell::Cell;
|
||||
use std::ptr;
|
||||
|
||||
|
|
@ -305,5 +306,14 @@ fn zst() {
|
|||
let ptr = &raw mut *b as *mut ();
|
||||
drop(b);
|
||||
let _ref = &mut *ptr;
|
||||
|
||||
// zero-sized protectors do not affect deallocation
|
||||
fn with_protector(_x: &mut (), ptr: *mut u8, l: Layout) {
|
||||
// `_x` here is strongly protected but covers zero bytes.
|
||||
unsafe { dealloc(ptr, l) };
|
||||
}
|
||||
let l = Layout::from_size_align(1, 1).unwrap();
|
||||
let ptr = alloc(l);
|
||||
with_protector(&mut *ptr.cast::<()>(), ptr, l);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
//@revisions: stack tree
|
||||
//@[tree]compile-flags: -Zmiri-tree-borrows
|
||||
use std::alloc::{Layout, alloc, dealloc};
|
||||
|
||||
// `x` is strongly protected but covers zero bytes.
|
||||
// This should never be UB.
|
||||
fn test(_x: &mut (), ptr: *mut u8, l: Layout) {
|
||||
unsafe { dealloc(ptr, l) };
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let l = Layout::from_size_align(1, 1).unwrap();
|
||||
let ptr = unsafe { alloc(l) };
|
||||
unsafe { test(&mut *ptr.cast::<()>(), ptr, l) };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue