Closed
Description
Miri should be able to detect that the following is UB because it prints uninitialized memory:
use std::mem;
#[repr(C)]
struct Pair(u8, u16);
fn main() { unsafe {
let p: Pair = mem::transmute(0u32); // The copy when `Pair` is returned from `transmute` should destroy padding.
let c = &p as *const _ as *const u8;
println!("{}", *c.add(1)); // Print the padding byte.
} }
However, currently assignment is just implemented as an untyped memcpy
, so we incorrectly preserve padding.