Skip to content

PlaceMention-style UB not detected when in closure #4258

@meithecatte

Description

@meithecatte
use std::mem::transmute;

fn main() {
    let r: &&u32 = unsafe {
        let x = 42;
        transmute(&&x)
    };

    // no UB detected
    let f = || { let _ = **r; };
    f();
    
    // UB due to the inner deref
    let _ = **r;
}

Playground

Found this when prompted by @Nadrieril:

In fact the other calls to {try_}to_place in match MIR lowering are potential places where we mess things up. E.g. here, we want to add a PlaceMention to the scrutinee which we can't do if it's not captured, could that have weird consequences maybe?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mirArea: this is about the MIR that we are executing, not about how we are executing itC-bugCategory: This is a bug.I-misses-theoretical-UBImpact: Miri does not report UB when it should, but codegen also "misses" this UB

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions