1 // We want to control preemption here.
2 //@compile-flags: -Zmiri-preemption-rate=0
4 use std::thread::spawn;
7 struct EvilSend<T>(pub T);
9 unsafe impl<T> Send for EvilSend<T> {}
10 unsafe impl<T> Sync for EvilSend<T> {}
13 fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
16 // Shared atomic pointer
17 let pointer: *mut usize = Box::into_raw(Box::new(0usize));
18 let ptr = EvilSend(pointer);
21 let j1 = spawn(move || {
24 std::mem::size_of::<usize>(),
25 std::mem::align_of::<usize>(),
29 let j2 = spawn(move || {
30 // Also an error of the form: Data race detected between Write on thread `<unnamed>` and Deallocate on thread `<unnamed>`
31 // but the invalid allocation is detected first.
32 *ptr.0 = 2; //~ ERROR: dereferenced after this allocation got freed