Skip to content

Do aliasing requirements carry over from const-time to run-time? #424

Open
@RalfJung

Description

@RalfJung

If a pointer is created as read-only during one program execution stage, is that restrictions inherited by future stages? IOW, is this code UB?

struct Foo(*mut i32);
unsafe impl Sync for Foo {}

static mut FOO: i32 = 0;
static PTR: Foo = Foo(unsafe { &FOO as *const i32 as *mut i32 });

fn main() {
    unsafe {
        let _r = &mut *PTR.0;
    }
}

If this would be running in a single instance of the AM then clearly this is UB. But does the alias information carry over from the compiletime AM to the initial state of the runtime AM?

Maybe thr answer is "obviously yes", but it doesn't seem so obvious for me. First of all, we'd need to set up extra machinery to even be able to put such alias information into the initial state of the runtime AM (i.e., even once Stacked/Tree Borrows are implemented for MiniRust, this won't be UB in MiniRust since the initial value of a "global" can't express that PTR is read-only). We could of course add that machinery. Then the question becomes: what is the benefit of doing so? We need aliasing restrictions to perform analyses and reasoning on references that alias with unknown code; with the results of const-eval being completely known to later stages, there's no clear benefit. Sure we can construct artificial examples, but is it worth it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-aliasing-modelTopic: Related to the aliasing model (e.g. Stacked/Tree Borrows)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions