Skip to content

Commit aa408aa

Browse files
committed
don't talk about 'Data race' when both accesses are atomic
1 parent bcd7aa5 commit aa408aa

8 files changed

+22
-14
lines changed

src/concurrency/data_race.rs

+3
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ impl VClockAlloc {
845845
) -> InterpResult<'tcx> {
846846
let (current_index, current_clocks) = global.current_thread_state(thread_mgr);
847847
let mut action = Cow::Borrowed(action);
848+
let mut involves_non_atomic = true;
848849
let write_clock;
849850
#[rustfmt::skip]
850851
let (other_action, other_thread, other_clock) =
@@ -856,6 +857,7 @@ impl VClockAlloc {
856857
} else if is_atomic && let Some(atomic) = mem_clocks.atomic() && atomic.size != access_size {
857858
// This is only a race if we are not synchronized with all atomic accesses, so find
858859
// the one we are not synchronized with.
860+
involves_non_atomic = false;
859861
action = format!("{}-byte (different-size) {action}", access_size.bytes()).into();
860862
if let Some(idx) = Self::find_gt_index(&atomic.write_vector, &current_clocks.clock)
861863
{
@@ -898,6 +900,7 @@ impl VClockAlloc {
898900

899901
// Throw the data-race detection.
900902
Err(err_machine_stop!(TerminationInfo::DataRace {
903+
involves_non_atomic,
901904
ptr: ptr_dbg,
902905
op1: RacingOp {
903906
action: other_action.to_string(),

src/diagnostics.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ pub enum TerminationInfo {
4343
span: SpanData,
4444
},
4545
DataRace {
46+
involves_non_atomic: bool,
47+
ptr: Pointer,
4648
op1: RacingOp,
4749
op2: RacingOp,
48-
ptr: Pointer,
4950
},
5051
}
5152

@@ -74,11 +75,15 @@ impl fmt::Display for TerminationInfo {
7475
write!(f, "multiple definitions of symbol `{link_name}`"),
7576
SymbolShimClashing { link_name, .. } =>
7677
write!(f, "found `{link_name}` symbol definition that clashes with a built-in shim",),
77-
DataRace { ptr, op1, op2 } =>
78+
DataRace { involves_non_atomic, ptr, op1, op2 } =>
7879
write!(
7980
f,
80-
"Data race detected between (1) {} on {} and (2) {} on {} at {ptr:?}. (2) just happened here",
81-
op1.action, op1.thread_info, op2.action, op2.thread_info
81+
"{} detected between (1) {} on {} and (2) {} on {} at {ptr:?}. (2) just happened here",
82+
if *involves_non_atomic { "Data race" } else { "Race condition" },
83+
op1.action,
84+
op1.thread_info,
85+
op2.action,
86+
op2.thread_info
8287
),
8388
}
8489
}

tests/fail/data_race/mixed_size_read.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
});
2020
s.spawn(|| {
2121
a8[0].load(Ordering::SeqCst);
22-
//~^ ERROR: Data race detected between (1) 2-byte Atomic Load on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Load on thread `<unnamed>`
22+
//~^ ERROR: Race condition detected between (1) 2-byte Atomic Load on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Load on thread `<unnamed>`
2323
});
2424
});
2525
}

tests/fail/data_race/mixed_size_read.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: Data race detected between (1) 2-byte Atomic Load on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
1+
error: Undefined Behavior: Race condition detected between (1) 2-byte Atomic Load on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
22
--> $DIR/mixed_size_read.rs:LL:CC
33
|
44
LL | a8[0].load(Ordering::SeqCst);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) 2-byte Atomic Load on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte Atomic Load on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
66
|
77
help: and (1) occurred earlier here
88
--> $DIR/mixed_size_read.rs:LL:CC

tests/fail/data_race/mixed_size_write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
});
2020
s.spawn(|| {
2121
a8[0].store(1, Ordering::SeqCst);
22-
//~^ ERROR: Data race detected between (1) 2-byte Atomic Store on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Store on thread `<unnamed>`
22+
//~^ ERROR: Race condition detected between (1) 2-byte Atomic Store on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Store on thread `<unnamed>`
2323
});
2424
});
2525
}

tests/fail/data_race/mixed_size_write.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: Data race detected between (1) 2-byte Atomic Store on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Store on thread `<unnamed>` at ALLOC. (2) just happened here
1+
error: Undefined Behavior: Race condition detected between (1) 2-byte Atomic Store on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Store on thread `<unnamed>` at ALLOC. (2) just happened here
22
--> $DIR/mixed_size_write.rs:LL:CC
33
|
44
LL | a8[0].store(1, Ordering::SeqCst);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) 2-byte Atomic Store on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Store on thread `<unnamed>` at ALLOC. (2) just happened here
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte Atomic Store on thread `<unnamed>` and (2) 1-byte (different-size) Atomic Store on thread `<unnamed>` at ALLOC. (2) just happened here
66
|
77
help: and (1) occurred earlier here
88
--> $DIR/mixed_size_write.rs:LL:CC

tests/fail/weak_memory/racing_mixed_size.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: Data race detected between (1) 4-byte Atomic Store on thread `<unnamed>` and (2) 2-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
1+
error: Undefined Behavior: Race condition detected between (1) 4-byte Atomic Store on thread `<unnamed>` and (2) 2-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
22
--> $DIR/racing_mixed_size.rs:LL:CC
33
|
44
LL | std::intrinsics::atomic_load_relaxed(hi);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) 4-byte Atomic Store on thread `<unnamed>` and (2) 2-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte Atomic Store on thread `<unnamed>` and (2) 2-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
66
|
77
help: and (1) occurred earlier here
88
--> $DIR/racing_mixed_size.rs:LL:CC

tests/fail/weak_memory/racing_mixed_size_read.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: Data race detected between (1) 4-byte Atomic Load on thread `<unnamed>` and (2) 2-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
1+
error: Undefined Behavior: Race condition detected between (1) 4-byte Atomic Load on thread `<unnamed>` and (2) 2-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
22
--> $DIR/racing_mixed_size_read.rs:LL:CC
33
|
44
LL | (*hi).load(Relaxed);
5-
| ^^^^^^^^^^^^^^^^^^^ Data race detected between (1) 4-byte Atomic Load on thread `<unnamed>` and (2) 2-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
5+
| ^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte Atomic Load on thread `<unnamed>` and (2) 2-byte (different-size) Atomic Load on thread `<unnamed>` at ALLOC. (2) just happened here
66
|
77
help: and (1) occurred earlier here
88
--> $DIR/racing_mixed_size_read.rs:LL:CC

0 commit comments

Comments
 (0)