-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
218 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/tools/miri/tests/fail/data_race/mixed_size_read_read_write.match_first_load.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error: Undefined Behavior: Race condition detected between (1) multiple differently-sized atomic loads, including one load on thread `unnamed-ID` and (2) 2-byte atomic store on thread `unnamed-ID` at ALLOC. (2) just happened here | ||
--> tests/fail/data_race/mixed_size_read_read_write.rs:LL:CC | ||
| | ||
LL | a16.store(0, Ordering::SeqCst); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) multiple differently-sized atomic loads, including one load on thread `unnamed-ID` and (2) 2-byte atomic store on thread `unnamed-ID` at ALLOC. (2) just happened here | ||
| | ||
help: and (1) occurred earlier here | ||
--> tests/fail/data_race/mixed_size_read_read_write.rs:LL:CC | ||
| | ||
LL | a16.load(Ordering::SeqCst); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= help: overlapping unsynchronized atomic accesses must use the same access size | ||
= 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 | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: BACKTRACE (of the first span) on thread `unnamed-ID`: | ||
= note: inside closure at tests/fail/data_race/mixed_size_read_read_write.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
22 changes: 22 additions & 0 deletions
22
src/tools/miri/tests/fail/data_race/mixed_size_read_read_write.match_second_load.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error: Undefined Behavior: Race condition detected between (1) multiple differently-sized atomic loads, including one load on thread `unnamed-ID` and (2) 1-byte atomic store on thread `unnamed-ID` at ALLOC. (2) just happened here | ||
--> tests/fail/data_race/mixed_size_read_read_write.rs:LL:CC | ||
| | ||
LL | a8[0].store(0, Ordering::SeqCst); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) multiple differently-sized atomic loads, including one load on thread `unnamed-ID` and (2) 1-byte atomic store on thread `unnamed-ID` at ALLOC. (2) just happened here | ||
| | ||
help: and (1) occurred earlier here | ||
--> tests/fail/data_race/mixed_size_read_read_write.rs:LL:CC | ||
| | ||
LL | a16.load(Ordering::SeqCst); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= help: overlapping unsynchronized atomic accesses must use the same access size | ||
= 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 | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: BACKTRACE (of the first span) on thread `unnamed-ID`: | ||
= note: inside closure at tests/fail/data_race/mixed_size_read_read_write.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
39 changes: 39 additions & 0 deletions
39
src/tools/miri/tests/fail/data_race/mixed_size_read_read_write.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//@compile-flags: -Zmiri-preemption-rate=0.0 -Zmiri-disable-weak-memory-emulation | ||
// Avoid accidental synchronization via address reuse inside `thread::spawn`. | ||
//@compile-flags: -Zmiri-address-reuse-cross-thread-rate=0 | ||
// Two variants: the atomic store matches the size of the first or second atomic load. | ||
//@revisions: match_first_load match_second_load | ||
|
||
use std::sync::atomic::{AtomicU16, AtomicU8, Ordering}; | ||
use std::thread; | ||
|
||
fn convert(a: &AtomicU16) -> &[AtomicU8; 2] { | ||
unsafe { std::mem::transmute(a) } | ||
} | ||
|
||
// We can't allow mixed-size accesses; they are not possible in C++ and even | ||
// Intel says you shouldn't do it. | ||
fn main() { | ||
let a = AtomicU16::new(0); | ||
let a16 = &a; | ||
let a8 = convert(a16); | ||
|
||
thread::scope(|s| { | ||
s.spawn(|| { | ||
a16.load(Ordering::SeqCst); | ||
}); | ||
s.spawn(|| { | ||
a8[0].load(Ordering::SeqCst); | ||
}); | ||
s.spawn(|| { | ||
thread::yield_now(); // make sure this happens last | ||
if cfg!(match_first_load) { | ||
a16.store(0, Ordering::SeqCst); | ||
//~[match_first_load]^ ERROR: Race condition detected between (1) multiple differently-sized atomic loads, including one load on thread `unnamed-1` and (2) 2-byte atomic store on thread `unnamed-3` | ||
} else { | ||
a8[0].store(0, Ordering::SeqCst); | ||
//~[match_second_load]^ ERROR: Race condition detected between (1) multiple differently-sized atomic loads, including one load on thread `unnamed-1` and (2) 1-byte atomic store on thread `unnamed-3` | ||
} | ||
}); | ||
}); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/tools/miri/tests/fail/data_race/mixed_size_read_write.read_write.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error: Undefined Behavior: Race condition detected between (1) 1-byte atomic load on thread `unnamed-ID` and (2) 2-byte atomic store on thread `unnamed-ID` at ALLOC. (2) just happened here | ||
--> tests/fail/data_race/mixed_size_read_write.rs:LL:CC | ||
| | ||
LL | a16.store(1, Ordering::SeqCst); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 1-byte atomic load on thread `unnamed-ID` and (2) 2-byte atomic store on thread `unnamed-ID` at ALLOC. (2) just happened here | ||
| | ||
help: and (1) occurred earlier here | ||
--> tests/fail/data_race/mixed_size_read_write.rs:LL:CC | ||
| | ||
LL | a8[0].load(Ordering::SeqCst); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= help: overlapping unsynchronized atomic accesses must use the same access size | ||
= 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 | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: BACKTRACE (of the first span) on thread `unnamed-ID`: | ||
= note: inside closure at tests/fail/data_race/mixed_size_read_write.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
39 changes: 39 additions & 0 deletions
39
src/tools/miri/tests/fail/data_race/mixed_size_read_write.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//@compile-flags: -Zmiri-preemption-rate=0.0 -Zmiri-disable-weak-memory-emulation | ||
// Avoid accidental synchronization via address reuse inside `thread::spawn`. | ||
//@compile-flags: -Zmiri-address-reuse-cross-thread-rate=0 | ||
// Two revisions, depending on which access goes first. | ||
//@revisions: read_write write_read | ||
|
||
use std::sync::atomic::{AtomicU16, AtomicU8, Ordering}; | ||
use std::thread; | ||
|
||
fn convert(a: &AtomicU16) -> &[AtomicU8; 2] { | ||
unsafe { std::mem::transmute(a) } | ||
} | ||
|
||
// We can't allow mixed-size accesses; they are not possible in C++ and even | ||
// Intel says you shouldn't do it. | ||
fn main() { | ||
let a = AtomicU16::new(0); | ||
let a16 = &a; | ||
let a8 = convert(a16); | ||
|
||
thread::scope(|s| { | ||
s.spawn(|| { | ||
if cfg!(read_write) { | ||
// Let the other one go first. | ||
thread::yield_now(); | ||
} | ||
a16.store(1, Ordering::SeqCst); | ||
//~[read_write]^ ERROR: Race condition detected between (1) 1-byte atomic load on thread `unnamed-2` and (2) 2-byte atomic store on thread `unnamed-1` | ||
}); | ||
s.spawn(|| { | ||
if cfg!(write_read) { | ||
// Let the other one go first. | ||
thread::yield_now(); | ||
} | ||
a8[0].load(Ordering::SeqCst); | ||
//~[write_read]^ ERROR: Race condition detected between (1) 2-byte atomic store on thread `unnamed-1` and (2) 1-byte atomic load on thread `unnamed-2` | ||
}); | ||
}); | ||
} |
14 changes: 7 additions & 7 deletions
14
...sts/fail/data_race/mixed_size_read.stderr → ...e/mixed_size_read_write.write_read.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.