Skip to content

Commit 43d3963

Browse files
committed
more detailed error message
1 parent 927ab19 commit 43d3963

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/concurrency/data_race.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -997,14 +997,23 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
997997
)?;
998998
// Ensure the allocation is mutable. Even failing (read-only) compare_exchange need mutable
999999
// memory on many targets (i.e., they segfault if taht memory is mapped read-only), and
1000-
// atomic loads can be implemented via compare_exchange on some targets. See
1001-
// <https://github.com/rust-lang/miri/issues/2463>.
1000+
// atomic loads can be implemented via compare_exchange on some targets. There could
1001+
// possibly be some very specific exceptions to this, see
1002+
// <https://github.com/rust-lang/miri/pull/2464#discussion_r939636130> for details.
10021003
// We avoid `get_ptr_alloc` since we do *not* want to run the access hooks -- the actual
10031004
// access will happen later.
10041005
let (alloc_id, _offset, _prov) =
10051006
this.ptr_try_get_alloc_id(place.ptr).expect("there are no zero-sized atomic accesses");
10061007
if this.get_alloc_mutability(alloc_id)? == Mutability::Not {
1007-
throw_ub_format!("atomic operations cannot be performed on read-only memory");
1008+
// FIXME: make this prettier, once these messages have separate title/span/help messages.
1009+
throw_ub_format!(
1010+
"atomic operations cannot be performed on read-only memory\n\
1011+
many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails \
1012+
(and is hence nominally read-only)\n\
1013+
some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; \
1014+
it is possible that we could have an exception permitting this for specific kinds of loads\n\
1015+
please report an issue at <https://github.com/rust-lang/miri/issues> if this is a problem for you"
1016+
);
10081017
}
10091018
Ok(())
10101019
}

tests/fail/concurrency/read_only_atomic_cmpxchg.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
error: Undefined Behavior: atomic operations cannot be performed on read-only memory
2+
many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails (and is hence nominally read-only)
3+
some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; it is possible that we could have an exception permitting this for specific kinds of loads
4+
please report an issue at <https://github.com/rust-lang/miri/issues> if this is a problem for you
25
--> $DIR/read_only_atomic_cmpxchg.rs:LL:CC
36
|
47
LL | x.compare_exchange(1, 2, Ordering::Relaxed, Ordering::Relaxed).unwrap_err();
58
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ atomic operations cannot be performed on read-only memory
9+
many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails (and is hence nominally read-only)
10+
some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; it is possible that we could have an exception permitting this for specific kinds of loads
11+
please report an issue at <https://github.com/rust-lang/miri/issues> if this is a problem for you
612
|
713
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
814
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

tests/fail/concurrency/read_only_atomic_load.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
error: Undefined Behavior: atomic operations cannot be performed on read-only memory
2+
many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails (and is hence nominally read-only)
3+
some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; it is possible that we could have an exception permitting this for specific kinds of loads
4+
please report an issue at <https://github.com/rust-lang/miri/issues> if this is a problem for you
25
--> $DIR/read_only_atomic_load.rs:LL:CC
36
|
47
LL | x.load(Ordering::Relaxed);
58
| ^^^^^^^^^^^^^^^^^^^^^^^^^ atomic operations cannot be performed on read-only memory
9+
many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails (and is hence nominally read-only)
10+
some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; it is possible that we could have an exception permitting this for specific kinds of loads
11+
please report an issue at <https://github.com/rust-lang/miri/issues> if this is a problem for you
612
|
713
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
814
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

0 commit comments

Comments
 (0)