Skip to content

Miscompilation, exposed provenance not picked up correctly #156622

@orlp

Description

@orlp

I tried this code:

#[inline(never)]
fn test(x: &i32) {
    let addr = (x as *const i32).wrapping_sub(1).addr();
    let p: *mut i32 = std::ptr::with_exposed_provenance_mut(addr);
    unsafe { *p += 1 };
}

fn main() {
    let mut arr = [0, 0];
    let [a, b] = arr.get_disjoint_mut([0, 1]).unwrap();
    (a as *mut i32).expose_provenance();
    test(&b);
    dbg!(arr);
}

I expected to see this happen: I'd expect to see [1, 0] printed.

Instead, this happened: in debug mode [1, 0] gets printed, but in release mode [0, 0] gets printed.

Occurs on 1.95 stable and latest nightly.

Found by @ruriww.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-opsemRelevant to the opsem team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions