-
Notifications
You must be signed in to change notification settings - Fork 420
Open
Labels
A-mirArea: this is about the MIR that we are executing, not about how we are executing itArea: this is about the MIR that we are executing, not about how we are executing itC-bugCategory: This is a bug.Category: This is a bug.I-misses-theoretical-UBImpact: Miri does not report UB when it should, but codegen also "misses" this UBImpact: Miri does not report UB when it should, but codegen also "misses" this UB
Description
Examples by @meithecatte; Cc @Nadrieril
The following code should likely trigger UB, but currently Miri raises no error:
#![feature(never_type)]
#[repr(C)]
#[allow(dead_code)]
enum E {
V1, // discriminant: 0
V2(!), // 1
}
fn main() {
assert_eq!(std::mem::size_of::<E>(), 4);
let val = 1u32;
let ptr = (&raw const val).cast::<E>();
let r = unsafe { &*ptr };
match r { //~ we'd probably want ERROR: read discriminant of an uninhabited enum variant
E::V1 => {}
E::V2(_) => {}
}
}The same goes for this variant that adds a closure (to check interactions with rust-lang/rust#138961):
#![feature(never_type)]
#[repr(C)]
#[allow(dead_code)]
enum E {
V0, // discriminant: 0
V2(!), // 2
}
fn main() {
assert_eq!(std::mem::size_of::<E>(), 4);
let val = 2u32;
let ptr = (&raw const val).cast::<E>();
let r = unsafe { &*ptr };
let f = || {
// After rust-lang/rust#138961, constructing the closure performs a reborrow of r.
// Nevertheless, the discriminant is only actually inspected when the closure
// is called.
match r { //~ ERROR: read discriminant of an uninhabited enum variant
E::V0 => {}
E::V2(_) => {}
}
};
f();
}Metadata
Metadata
Assignees
Labels
A-mirArea: this is about the MIR that we are executing, not about how we are executing itArea: this is about the MIR that we are executing, not about how we are executing itC-bugCategory: This is a bug.Category: This is a bug.I-misses-theoretical-UBImpact: Miri does not report UB when it should, but codegen also "misses" this UBImpact: Miri does not report UB when it should, but codegen also "misses" this UB