move zero-sized protector dealloc test

This commit is contained in:
Johannes Hostert 2025-09-11 19:15:50 +02:00
parent 2b5b191965
commit 16b34c6f70
No known key found for this signature in database
GPG key ID: 0BA6032B5A38D049
2 changed files with 10 additions and 15 deletions

View file

@ -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);
}
}

View file

@ -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) };
}