File tree 2 files changed +42
-0
lines changed
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ // compile-flags: -Zmiri-preemption-rate=0
2
+ use std:: thread;
3
+
4
+ #[ derive( Copy , Clone ) ]
5
+ struct MakeSend ( * const i32 ) ;
6
+ unsafe impl Send for MakeSend { }
7
+
8
+ fn main ( ) { race ( 0 ) ; }
9
+
10
+ // Using an argument for the ptr to point to, since those do not get StorageDead.
11
+ fn race ( local : i32 ) {
12
+ let ptr = MakeSend ( & local as * const i32 ) ;
13
+ thread:: spawn ( move || {
14
+ let ptr = ptr;
15
+ let _val = unsafe { * ptr. 0 } ;
16
+ } ) ;
17
+ // Make the other thread go first so that it does not UAF.
18
+ thread:: yield_now ( ) ;
19
+ // Deallocating the local (when `main` returns)
20
+ // races with the read in the other thread.
21
+ // Make sure the error points at this function's end, not just the call site.
22
+ } //~ERROR Data race detected between Deallocate on thread `main` and Read on thread `<unnamed>`
Original file line number Diff line number Diff line change
1
+ error: Undefined Behavior: Data race detected between Deallocate on thread `main` and Read on thread `<unnamed>` at ALLOC
2
+ --> $DIR/stack_pop_race.rs:LL:CC
3
+ |
4
+ LL | }
5
+ | ^ Data race detected between Deallocate on thread `main` and Read on thread `<unnamed>` at ALLOC
6
+ |
7
+ = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8
+ = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9
+ = note: backtrace:
10
+ = note: inside `race` at $DIR/stack_pop_race.rs:LL:CC
11
+ note: inside `main` at $DIR/stack_pop_race.rs:LL:CC
12
+ --> $DIR/stack_pop_race.rs:LL:CC
13
+ |
14
+ LL | fn main() { race(0); }
15
+ | ^^^^^^^
16
+
17
+ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
18
+
19
+ error: aborting due to previous error
20
+
You can’t perform that action at this time.
0 commit comments