about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/intrinsics/ptr_metadata_uninit_thin.rs
blob: 3ba29847337435ba3cefe1ddf43808c130cf4678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//@compile-flags: -Zmiri-disable-validation
//@ normalize-stderr-test: "(\n)ALLOC \(.*\) \{\n(.*\n)*\}(\n)" -> "${1}ALLOC DUMP${3}"
//@ normalize-stderr-test: "\[0x[0-9a-z]..0x[0-9a-z]\]" -> "[0xX..0xY]"

#![feature(core_intrinsics, custom_mir)]
use std::intrinsics::mir::*;

// This disables validation and uses custom MIR hit exactly the UB in the intrinsic,
// rather than getting UB from the typed load or parameter passing.

#[custom_mir(dialect = "runtime")]
pub unsafe fn deref_meta(p: *const *const i32) -> () {
    mir! {
        {
            RET = PtrMetadata(*p); //~ ERROR: /Undefined Behavior: .*, but memory is uninitialized/
            Return()
        }
    }
}

fn main() {
    // Even though the meta is the trivially-valid `()`, this is still UB

    let p = std::mem::MaybeUninit::<*const i32>::uninit();
    unsafe {
        let _meta = deref_meta(p.as_ptr());
    }
}