diff options
| author | Johannes Hostert <jhostert@ethz.ch> | 2025-09-11 19:15:50 +0200 |
|---|---|---|
| committer | Johannes Hostert <jhostert@ethz.ch> | 2025-09-11 19:15:50 +0200 |
| commit | 16b34c6f7056701bbe66892e2d5300d80eae0830 (patch) | |
| tree | cd94aacb1705cf7796ec302b8a819d3ae3d584b5 | |
| parent | 2b5b191965571142cff8fab04aad9f243041ca19 (diff) | |
| download | rust-16b34c6f7056701bbe66892e2d5300d80eae0830.tar.gz rust-16b34c6f7056701bbe66892e2d5300d80eae0830.zip | |
move zero-sized protector dealloc test
| -rw-r--r-- | src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs | 10 | ||||
| -rw-r--r-- | src/tools/miri/tests/pass/both_borrows/zero-sized-protected.rs | 15 |
2 files changed, 10 insertions, 15 deletions
diff --git a/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs b/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs index 82976326a8d..115e232dde4 100644 --- a/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs +++ b/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs @@ -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); } } diff --git a/src/tools/miri/tests/pass/both_borrows/zero-sized-protected.rs b/src/tools/miri/tests/pass/both_borrows/zero-sized-protected.rs deleted file mode 100644 index 23d283ff4a1..00000000000 --- a/src/tools/miri/tests/pass/both_borrows/zero-sized-protected.rs +++ /dev/null @@ -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) }; -} |
