rust/tests/fail/provenance/ptr_int_unexposed.rs

13 lines
398 B
Rust
Raw Normal View History

2022-07-08 11:08:32 -05:00
//@compile-flags: -Zmiri-permissive-provenance
2022-06-03 07:47:00 -05:00
#![feature(strict_provenance)]
2022-05-22 15:22:05 -05:00
fn main() {
let x: i32 = 3;
let x_ptr = &x as *const i32;
2022-06-03 07:47:00 -05:00
let x_usize: usize = x_ptr.addr();
// Cast back an address that did *not* get exposed.
let ptr = std::ptr::from_exposed_addr::<i32>(x_usize);
assert_eq!(unsafe { *ptr }, 3); //~ ERROR: Undefined Behavior: dereferencing pointer failed
2022-05-22 15:22:05 -05:00
}