about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/uninit/padding-union.rs
blob: 294578607b37d488bdc1871cb02aeaf31278b39c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::mem;

#[allow(unused)]
#[repr(C)]
union U {
    field: (u8, u16),
}

fn main() {
    unsafe {
        let p: U = mem::transmute(0u32); // The copy when `U` is returned from `transmute` should destroy padding.
        let c = &p as *const _ as *const [u8; 4];
        // Read the entire thing, definitely contains the padding byte.
        let _val = *c;
        //~^ERROR: uninitialized
    }
}