Skip to content

PlaceMention-style UB not detected when in closure #4258

Open
@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-interpreterArea: affects the core interpreterC-bugCategory: This is a bug.I-misses-UBImpact: makes Miri miss UB, i.e., a false negative (with default settings)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions