about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/validity/invalid_enum_cast.rs
blob: ed451a435b958b06a7fada268025b4e02a404600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Make sure we find these even with many checks disabled.
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation

#[derive(Copy, Clone)]
#[allow(unused)]
enum E {
    A,
    B,
    C,
}

fn cast(ptr: *const E) {
    unsafe {
        let _val = *ptr as u32; //~ERROR: enum value has invalid tag
    }
}

pub fn main() {
    let v = u32::MAX;
    cast(&v as *const u32 as *const E);
}