forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#3149 - RalfJung:atomic-readonly-loads, r=Ralf…
…Jung accept some atomic loads from read-only memory matches rust-lang#115577
- Loading branch information
Showing
10 changed files
with
135 additions
and
62 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 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
12 changes: 4 additions & 8 deletions
12
src/tools/miri/tests/fail/concurrency/read_only_atomic_cmpxchg.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
21 changes: 0 additions & 21 deletions
21
src/tools/miri/tests/fail/concurrency/read_only_atomic_load.stderr
This file was deleted.
Oops, something went wrong.
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
19 changes: 19 additions & 0 deletions
19
src/tools/miri/tests/fail/concurrency/read_only_atomic_load_acquire.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,19 @@ | ||
error: Undefined Behavior: non-relaxed atomic load operations cannot be performed on read-only memory | ||
these operations sometimes have to be implemented using read-modify-write operations, which require writeable memory | ||
see <https://doc.rust-lang.org/nightly/std/sync/atomic/index.html#atomic-accesses-to-read-only-memory> for more information | ||
--> $DIR/read_only_atomic_load_acquire.rs:LL:CC | ||
| | ||
LL | x.load(Ordering::Acquire); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ non-relaxed atomic load operations cannot be performed on read-only memory | ||
these operations sometimes have to be implemented using read-modify-write operations, which require writeable memory | ||
see <https://doc.rust-lang.org/nightly/std/sync/atomic/index.html#atomic-accesses-to-read-only-memory> for more information | ||
| | ||
= 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: | ||
= note: inside `main` at $DIR/read_only_atomic_load_acquire.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
18 changes: 18 additions & 0 deletions
18
src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.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,18 @@ | ||
// Should not rely on the aliasing model for its failure. | ||
//@compile-flags: -Zmiri-disable-stacked-borrows | ||
// Needs atomic accesses larger than the pointer size | ||
//@ignore-64bit | ||
|
||
use std::sync::atomic::{AtomicI64, Ordering}; | ||
|
||
#[repr(align(8))] | ||
struct AlignedI64(i64); | ||
|
||
fn main() { | ||
static X: AlignedI64 = AlignedI64(0); | ||
let x = &X as *const AlignedI64 as *const AtomicI64; | ||
let x = unsafe { &*x }; | ||
// Some targets can implement atomic loads via compare_exchange, so we cannot allow them on | ||
// read-only memory. | ||
x.load(Ordering::Relaxed); //~ERROR: cannot be performed on read-only memory | ||
} |
19 changes: 19 additions & 0 deletions
19
src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.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,19 @@ | ||
error: Undefined Behavior: large atomic load operations cannot be performed on read-only memory | ||
these operations often have to be implemented using read-modify-write operations, which require writeable memory | ||
see <https://doc.rust-lang.org/nightly/std/sync/atomic/index.html#atomic-accesses-to-read-only-memory> for more information | ||
--> $DIR/read_only_atomic_load_large.rs:LL:CC | ||
| | ||
LL | x.load(Ordering::Relaxed); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ large atomic load operations cannot be performed on read-only memory | ||
these operations often have to be implemented using read-modify-write operations, which require writeable memory | ||
see <https://doc.rust-lang.org/nightly/std/sync/atomic/index.html#atomic-accesses-to-read-only-memory> for more information | ||
| | ||
= 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: | ||
= note: inside `main` at $DIR/read_only_atomic_load_large.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
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,12 @@ | ||
// Stacked Borrows doesn't like this. | ||
//@compile-flags: -Zmiri-tree-borrows | ||
|
||
use std::sync::atomic::*; | ||
|
||
fn main() { | ||
// Atomic loads from read-only memory are fine if they are relaxed and small. | ||
static X: i32 = 0; | ||
let x = &X as *const i32 as *const AtomicI32; | ||
let x = unsafe { &*x }; | ||
x.load(Ordering::Relaxed); | ||
} |