about summary refs log tree commit diff
path: root/src/tools/miri/tests/panic/transmute_fat2.rs
blob: 7441f25d03ea7138acc62bb58fcc2622dae7ccf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#![allow(integer_to_ptr_transmutes)]

fn main() {
    #[cfg(all(target_endian = "little", target_pointer_width = "64"))]
    let bad = unsafe { std::mem::transmute::<u128, &[u8]>(42) };
    #[cfg(all(target_endian = "big", target_pointer_width = "64"))]
    let bad = unsafe { std::mem::transmute::<u128, &[u8]>(42 << 64) };
    #[cfg(all(target_endian = "little", target_pointer_width = "32"))]
    let bad = unsafe { std::mem::transmute::<u64, &[u8]>(42) };
    #[cfg(all(target_endian = "big", target_pointer_width = "32"))]
    let bad = unsafe { std::mem::transmute::<u64, &[u8]>(42 << 32) };
    // This created a slice with length 0, so the following will fail the bounds check.
    bad[0];
}