summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_gcc/tests/run/volatile.rs
blob: 8b0433125936bd4b8737a54829de212db8185228 (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
// Compiler:
//
// Run-time:
//   status: 0

use std::mem::MaybeUninit;

#[derive(Debug)]
struct Struct {
    pointer: *const (),
    func: unsafe fn(*const ()),
}

fn func(ptr: *const ()) {
}

fn main() {
    let mut x = MaybeUninit::<&Struct>::uninit();
    x.write(&Struct {
        pointer: std::ptr::null(),
        func,
    });
    let x = unsafe { x.assume_init() };
    let value = unsafe { (x as *const Struct).read_volatile() };
    println!("{:?}", value);
}