add a test for zero-sized protectors
This commit is contained in:
parent
f203b42166
commit
13b02e3d86
@ -13,7 +13,5 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let l = Layout::from_size_align(1, 1).unwrap();
|
let l = Layout::from_size_align(1, 1).unwrap();
|
||||||
let ptr = Global.allocate(l).unwrap().as_non_null_ptr();
|
let ptr = Global.allocate(l).unwrap().as_non_null_ptr();
|
||||||
unsafe {
|
unsafe { System.deallocate(ptr, l) };
|
||||||
System.deallocate(ptr, l);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ LL | FREE();
|
|||||||
note: inside `main`
|
note: inside `main`
|
||||||
--> $DIR/global_system_mixup.rs:LL:CC
|
--> $DIR/global_system_mixup.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | System.deallocate(ptr, l);
|
LL | unsafe { System.deallocate(ptr, l) };
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
//@revisions: stack tree
|
||||||
|
//@[tree]compile-flags: -Zmiri-tree-borrows
|
||||||
|
//@[tree]error-in-other-file: /deallocation .* is forbidden/
|
||||||
|
use std::alloc::{alloc, dealloc, Layout};
|
||||||
|
|
||||||
|
// `x` is strongly protected but covers zero bytes.
|
||||||
|
// Let's see if deallocating the allocation x points to is UB:
|
||||||
|
// in TB, it is UB, but in SB it is not.
|
||||||
|
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) };
|
||||||
|
// In SB the test would pass if it weren't for this line.
|
||||||
|
unsafe { std::hint::unreachable_unchecked() }; //~[stack] ERROR: unreachable
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
error: Undefined Behavior: entering unreachable code
|
||||||
|
--> $DIR/zero-sized-protected.rs:LL:CC
|
||||||
|
|
|
||||||
|
LL | unsafe { std::hint::unreachable_unchecked() };
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entering unreachable code
|
||||||
|
|
|
||||||
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
|
= note: BACKTRACE:
|
||||||
|
= note: inside `main` at $DIR/zero-sized-protected.rs:LL:CC
|
||||||
|
|
||||||
|
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
@ -0,0 +1,36 @@
|
|||||||
|
error: Undefined Behavior: deallocation through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
|
||||||
|
--> RUSTLIB/alloc/src/alloc.rs:LL:CC
|
||||||
|
|
|
||||||
|
LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocation through <TAG> (root of the allocation) at ALLOC[0x0] is forbidden
|
||||||
|
|
|
||||||
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
|
||||||
|
= help: the allocation of the accessed tag <TAG> (root of the allocation) also contains the strongly protected tag <TAG>
|
||||||
|
= help: the strongly protected tag <TAG> disallows deallocations
|
||||||
|
help: the accessed tag <TAG> was created here
|
||||||
|
--> $DIR/zero-sized-protected.rs:LL:CC
|
||||||
|
|
|
||||||
|
LL | let ptr = unsafe { alloc(l) };
|
||||||
|
| ^^^^^^^^
|
||||||
|
help: the strongly protected tag <TAG> was created here, in the initial state Reserved
|
||||||
|
--> $DIR/zero-sized-protected.rs:LL:CC
|
||||||
|
|
|
||||||
|
LL | fn test(_x: &mut (), ptr: *mut u8, l: Layout) {
|
||||||
|
| ^^
|
||||||
|
= note: BACKTRACE (of the first span):
|
||||||
|
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
|
||||||
|
note: inside `test`
|
||||||
|
--> $DIR/zero-sized-protected.rs:LL:CC
|
||||||
|
|
|
||||||
|
LL | unsafe { dealloc(ptr, l) };
|
||||||
|
| ^^^^^^^^^^^^^^^
|
||||||
|
note: inside `main`
|
||||||
|
--> $DIR/zero-sized-protected.rs:LL:CC
|
||||||
|
|
|
||||||
|
LL | unsafe { test(&mut *ptr.cast::<()>(), ptr, l) };
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user