]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/ptr_int_transmute.rs
Rollup merge of #105784 - yanns:update_stdarch, r=Amanieu
[rust.git] / src / tools / miri / tests / pass / ptr_int_transmute.rs
1 // Test what happens when we read parts of a pointer.
2 // Related to <https://github.com/rust-lang/rust/issues/69488>.
3 fn ptr_partial_read() {
4     let x = 13;
5     let y = &x;
6     let z = &y as *const &i32 as *const u8;
7
8     // This just strips provenance, but should work fine otherwise.
9     let _val = unsafe { *z };
10 }
11
12 fn transmute_strip_provenance() {
13     let r = &mut 42;
14     let addr = r as *mut _ as usize;
15     let i: usize = unsafe { std::mem::transmute(r) };
16     assert_eq!(i, addr);
17 }
18
19 fn main() {
20     ptr_partial_read();
21     transmute_strip_provenance();
22 }