1 // We want to control preemption here.
2 //@compile-flags: -Zmiri-preemption-rate=0
4 #![feature(core_intrinsics)]
7 use std::sync::atomic::AtomicU32;
8 use std::sync::atomic::Ordering::*;
9 use std::thread::spawn;
11 fn static_atomic_u32(val: u32) -> &'static AtomicU32 {
12 let ret = Box::leak(Box::new(AtomicU32::new(val)));
16 fn split_u32_ptr(dword: *const u32) -> *const [u16; 2] {
17 unsafe { std::mem::transmute::<*const u32, *const [u16; 2]>(dword) }
20 // Wine's SRWLock implementation does this, which is definitely undefined in C++ memory model
21 // https://github.com/wine-mirror/wine/blob/303f8042f9db508adaca02ef21f8de4992cb9c03/dlls/ntdll/sync.c#L543-L566
22 // Though it probably works just fine on x86
24 let x = static_atomic_u32(0);
25 let j1 = spawn(move || {
29 let j2 = spawn(move || {
30 let x_ptr = x as *const AtomicU32 as *const u32;
31 let x_split = split_u32_ptr(x_ptr);
33 let hi = ptr::addr_of!((*x_split)[0]);
34 std::intrinsics::atomic_load_relaxed(hi); //~ ERROR: imperfectly overlapping