Skip to content

Commit 9b35886

Browse files
committed
make sure we also detect mixed-size races that begin at different addresses
1 parent 32d4968 commit 9b35886

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: Undefined Behavior: Race condition detected between (1) 2-byte atomic store on thread `unnamed-ID` and (2) 1-byte atomic store on thread `unnamed-ID` at ALLOC. (2) just happened here
2+
--> tests/fail/data_race/mixed_size_write_write.rs:LL:CC
3+
|
4+
LL | a8[idx].store(1, Ordering::SeqCst);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte atomic store on thread `unnamed-ID` and (2) 1-byte atomic store on thread `unnamed-ID` at ALLOC. (2) just happened here
6+
|
7+
help: and (1) occurred earlier here
8+
--> tests/fail/data_race/mixed_size_write_write.rs:LL:CC
9+
|
10+
LL | a16.store(1, Ordering::SeqCst);
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= help: overlapping unsynchronized atomic accesses must use the same access size
13+
= help: see https://doc.rust-lang.org/nightly/std/sync/atomic/index.html#memory-model-for-atomic-accesses for more information about the Rust memory model
14+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
15+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
16+
= note: BACKTRACE (of the first span) on thread `unnamed-ID`:
17+
= note: inside closure at tests/fail/data_race/mixed_size_write_write.rs:LL:CC
18+
19+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
20+
21+
error: aborting due to 1 previous error
22+

src/tools/miri/tests/fail/data_race/mixed_size_write_write.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@compile-flags: -Zmiri-preemption-rate=0.0 -Zmiri-disable-weak-memory-emulation
22
// Avoid accidental synchronization via address reuse inside `thread::spawn`.
33
//@compile-flags: -Zmiri-address-reuse-cross-thread-rate=0
4+
//@revisions: fst snd
45

56
use std::sync::atomic::{AtomicU8, AtomicU16, Ordering};
67
use std::thread;
@@ -21,7 +22,8 @@ fn main() {
2122
a16.store(1, Ordering::SeqCst);
2223
});
2324
s.spawn(|| {
24-
a8[0].store(1, Ordering::SeqCst);
25+
let idx = if cfg!(fst) { 0 } else { 1 };
26+
a8[idx].store(1, Ordering::SeqCst);
2527
//~^ ERROR: Race condition detected between (1) 2-byte atomic store on thread `unnamed-1` and (2) 1-byte atomic store on thread `unnamed-2`
2628
});
2729
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: Undefined Behavior: Race condition detected between (1) 2-byte atomic store on thread `unnamed-ID` and (2) 1-byte atomic store on thread `unnamed-ID` at ALLOC+0x1. (2) just happened here
2+
--> tests/fail/data_race/mixed_size_write_write.rs:LL:CC
3+
|
4+
LL | a8[idx].store(1, Ordering::SeqCst);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte atomic store on thread `unnamed-ID` and (2) 1-byte atomic store on thread `unnamed-ID` at ALLOC+0x1. (2) just happened here
6+
|
7+
help: and (1) occurred earlier here
8+
--> tests/fail/data_race/mixed_size_write_write.rs:LL:CC
9+
|
10+
LL | a16.store(1, Ordering::SeqCst);
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= help: overlapping unsynchronized atomic accesses must use the same access size
13+
= help: see https://doc.rust-lang.org/nightly/std/sync/atomic/index.html#memory-model-for-atomic-accesses for more information about the Rust memory model
14+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
15+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
16+
= note: BACKTRACE (of the first span) on thread `unnamed-ID`:
17+
= note: inside closure at tests/fail/data_race/mixed_size_write_write.rs:LL:CC
18+
19+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
20+
21+
error: aborting due to 1 previous error
22+

0 commit comments

Comments
 (0)