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.
|
2022-06-21 13:27:44 -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) };
|
2022-07-11 06:44:55 -05:00
|
|
|
//~^ ERROR: uninitialized
|
2022-06-21 13:27:44 -05:00
|
|
|
if v == 0 {
|
|
|
|
println!("it is zero");
|
|
|
|
}
|
2017-07-03 15:57:18 -05:00
|
|
|
}
|