Skip to content

indexing expressions can ignore fake borrows when an index diverges #161852

Description

@dianne

Currently for chained-together indexing expressions, we emit fake reads for fake borrows only at the very end. This means that if control flow diverges within an index expression such that the fake reads are unreachable, they can't keep fake borrows on indexed-into slice references alive.

For example:

fn unsound() {
    let mut x: &[&[&[u32]]] = &[&[&[0]]];
    let y: &[&[&[u32]]] = &[];
    x[0][{ x = y; 0 }][{ return; 0 }];
}

This compiles successfully because the fake read on the fake borrow of x is unreachable, but Miri detects UB in x[0][{ x = y; 0 }]. This checks that 0 is within-bounds for y[0], but y[0] is itself out-of-bounds, so it's UB to read its length.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-sliceArea: `[T]`C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions