]> git.proxmox.com Git - rustc.git/blame - src/tools/miri/tests/compile-fail/transmute-pair-undef.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / tools / miri / tests / compile-fail / transmute-pair-undef.rs
CommitLineData
ea8adc8c
XL
1#![feature(core_intrinsics)]
2
3use std::mem;
4
5fn main() {
6 let x: Option<Box<[u8]>> = unsafe {
7 let z = std::intrinsics::add_with_overflow(0usize, 0usize);
8 std::mem::transmute::<(usize, bool), Option<Box<[u8]>>>(z)
9 };
10 let y = &x;
11 // 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.
12 let z : *const u8 = y as *const _ as *const _;
13 let first_undef = mem::size_of::<usize>() as isize + 1;
14 for i in 0..first_undef {
15 let byte = unsafe { *z.offset(i) };
16 assert_eq!(byte, 0);
17 }
18 let v = unsafe { *z.offset(first_undef) };
19 if v == 0 {} //~ ERROR attempted to read undefined bytes
20}