rust/tests/compile-fail/provenance/ptr_legacy_provenance.rs
2022-05-23 12:19:42 +02:00

22 lines
564 B
Rust

// compile-flags: -Zmiri-disable-stacked-borrows
#![feature(strict_provenance)]
use std::ptr;
// Make sure that with legacy provenance, the allocation id of
// a casted pointer is determined at cast-time
fn main() {
let x: i32 = 0;
let y: i32 = 1;
let x_ptr = &x as *const i32;
let y_ptr = &y as *const i32;
let x_usize = x_ptr.expose_addr();
let y_usize = y_ptr.expose_addr();
let ptr = ptr::from_exposed_addr::<i32>(y_usize);
let ptr = ptr.with_addr(x_usize);
assert_eq!(unsafe { *ptr }, 0); //~ ERROR is out-of-bounds
}