about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/ptr_int_transmute.rs
blob: d99c25413e640d92f84ac3de08ea0331d51b87ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
// Test what happens when we read parts of a pointer.
// Related to <https://github.com/rust-lang/rust/issues/69488>.
fn ptr_partial_read() {
    let x = 13;
    let y = &x;
    let z = &y as *const &i32 as *const u8;

    // This just strips provenance, but should work fine otherwise.
    let _val = unsafe { *z };
}

fn transmute_strip_provenance() {
    let r = &mut 42;
    let addr = r as *mut _ as usize;
    let i: usize = unsafe { std::mem::transmute(r) };
    assert_eq!(i, addr);
}

fn main() {
    ptr_partial_read();
    transmute_strip_provenance();
}