]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/copy_half_a_pointer.rs
Add 'src/tools/miri/' from commit '75dd959a3a40eb5b4574f8d2e23aa6efbeb33573'
[rust.git] / src / tools / miri / tests / fail / copy_half_a_pointer.rs
1 //@normalize-stderr-test: "\+0x[48]" -> "+HALF_PTR"
2 #![allow(dead_code)]
3
4 // We use packed structs to get around alignment restrictions
5 #[repr(packed)]
6 struct Data {
7     pad: u8,
8     ptr: &'static i32,
9 }
10
11 static G: i32 = 0;
12
13 fn main() {
14     let mut d = Data { pad: 0, ptr: &G };
15
16     // Get a pointer to the beginning of the Data struct (one u8 byte, then the pointer bytes).
17     let d_alias = &mut d as *mut _ as *mut *const u8;
18     unsafe {
19         let _x = d_alias.read_unaligned(); //~ERROR: unable to copy parts of a pointer
20     }
21 }