2022-05-23 08:44:27 -05:00
|
|
|
// compile-flags: -Zmiri-allow-uninit-numbers
|
2017-07-03 15:57:18 -05:00
|
|
|
#![feature(core_intrinsics)]
|
|
|
|
|
2017-07-03 18:16:05 -05:00
|
|
|
use std::mem;
|
|
|
|
|
2017-07-03 15:57:18 -05:00
|
|
|
fn main() {
|
|
|
|
let x: Option<Box<[u8]>> = unsafe {
|
|
|
|
let z = std::intrinsics::add_with_overflow(0usize, 0usize);
|
|
|
|
std::mem::transmute::<(usize, bool), Option<Box<[u8]>>>(z)
|
|
|
|
};
|
|
|
|
let y = &x;
|
2019-02-15 19:43:56 -06:00
|
|
|
// Now read this bytewise. There should be (`ptr_size + 1`) def bytes followed by
|
|
|
|
// (`ptr_size - 1`) undef bytes (the padding after the bool) in there.
|
2017-07-03 15:57:18 -05:00
|
|
|
let z : *const u8 = y as *const _ as *const _;
|
2017-07-03 18:16:05 -05:00
|
|
|
let first_undef = mem::size_of::<usize>() as isize + 1;
|
|
|
|
for i in 0..first_undef {
|
2017-07-03 15:57:18 -05:00
|
|
|
let byte = unsafe { *z.offset(i) };
|
|
|
|
assert_eq!(byte, 0);
|
|
|
|
}
|
2017-07-03 18:16:05 -05:00
|
|
|
let v = unsafe { *z.offset(first_undef) };
|
2021-02-23 02:23:49 -06:00
|
|
|
if v == 0 { println!("it is zero"); }
|
2020-03-08 17:34:54 -05:00
|
|
|
//~^ ERROR this operation requires initialized memory
|
2017-07-03 15:57:18 -05:00
|
|
|
}
|