Skip to content

Cheat Miri #1742

@nightkidxmd

Description

@nightkidxmd

Build borrow record like below,
Then I can access user.y via ptr successfully.

#![allow(unused)]
fn main() {
    use std::slice;
    struct Test {
        x: [i32; 3],
        y: i32,
    }
    let user = Test { x: [1, 2, 3], y: 4 };
    let ptr = &(user.x) as *const i32;
    let ptr2 = &(user.y) as *const i32; // build borrow record
    for i in 0..4 {
       unsafe { println!("ptr offset {} : {:?} addr{:?}", i, ptr.offset(i), *ptr.offset(i)) };
    }
    let slice = unsafe { slice::from_raw_parts(ptr, 4) };
    println!("slice[3] : {:?}", slice[3]);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-aliasingArea: This affects the aliasing model (Stacked/Tree Borrows)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions