Skip to content

Commit d2e1c37

Browse files
committed
Fix span management
1 parent d1184ae commit d2e1c37

15 files changed

+42
-53
lines changed

src/tools/miri/src/concurrency/data_race.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5151
use rustc_index::vec::{Idx, IndexVec};
5252
use rustc_middle::mir;
5353
use rustc_span::Span;
54-
use rustc_span::DUMMY_SP;
5554
use rustc_target::abi::{Align, Size};
5655

5756
use crate::diagnostics::RacingOp;
@@ -398,7 +397,10 @@ impl MemoryCellClocks {
398397
current_span: Span,
399398
) -> Result<(), DataRace> {
400399
log::trace!("Unsynchronized read with vectors: {:#?} :: {:#?}", self, clocks);
401-
let res = if self.write <= clocks.clock[self.write_index] {
400+
if !current_span.is_dummy() {
401+
clocks.clock[index].span = current_span;
402+
}
403+
if self.write <= clocks.clock[self.write_index] {
402404
let race_free = if let Some(atomic) = self.atomic() {
403405
atomic.write_vector <= clocks.clock
404406
} else {
@@ -408,11 +410,7 @@ impl MemoryCellClocks {
408410
if race_free { Ok(()) } else { Err(DataRace) }
409411
} else {
410412
Err(DataRace)
411-
};
412-
if res.is_ok() && current_span != DUMMY_SP {
413-
clocks.clock[index].span = current_span;
414413
}
415-
res
416414
}
417415

418416
/// Detect races for non-atomic write operations at the current memory cell
@@ -425,7 +423,7 @@ impl MemoryCellClocks {
425423
current_span: Span,
426424
) -> Result<(), DataRace> {
427425
log::trace!("Unsynchronized write with vectors: {:#?} :: {:#?}", self, clocks);
428-
if current_span != DUMMY_SP {
426+
if !current_span.is_dummy() {
429427
clocks.clock[index].span = current_span;
430428
}
431429
if self.write <= clocks.clock[self.write_index] && self.read <= clocks.clock {
@@ -712,9 +710,7 @@ impl VClockAlloc {
712710
| MemoryKind::Stack => {
713711
let (alloc_index, clocks) = global.current_thread_state(thread_mgr);
714712
let mut alloc_timestamp = clocks.clock[alloc_index];
715-
if current_span != DUMMY_SP {
716-
alloc_timestamp.span = current_span;
717-
}
713+
alloc_timestamp.span = current_span;
718714
(alloc_timestamp, alloc_index)
719715
}
720716
// Other global memory should trace races but be allocated at the 0 timestamp.

src/tools/miri/src/concurrency/vector_clock.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ impl From<u32> for VectorIdx {
4545
/// clock vectors larger than this will be stored on the heap
4646
const SMALL_VECTOR: usize = 4;
4747

48-
/// The type of the time-stamps recorded in the data-race detector
49-
/// set to a type of unsigned integer
48+
/// The time-stamps recorded in the data-race detector consist of both
49+
/// a 32-bit unsigned integer which is the actual timestamp, and a `Span`
50+
/// so that diagnostics can report what code was responsible for an operation.
5051
#[derive(Clone, Copy, Debug, Eq)]
5152
pub struct VTimestamp {
5253
time: u32,
@@ -128,7 +129,7 @@ impl VClock {
128129
let mut_slice = self.get_mut_with_min_len(idx + 1);
129130
let idx_ref = &mut mut_slice[idx];
130131
idx_ref.time = idx_ref.time.checked_add(1).expect("Vector clock overflow");
131-
if current_span != DUMMY_SP {
132+
if !current_span.is_dummy() {
132133
idx_ref.span = current_span;
133134
}
134135
}
@@ -143,14 +144,7 @@ impl VClock {
143144
let l_span = l.span;
144145
let r_span = r.span;
145146
*l = r.max(*l);
146-
if l.span == DUMMY_SP {
147-
if r_span != DUMMY_SP {
148-
l.span = r_span;
149-
}
150-
if l_span != DUMMY_SP {
151-
l.span = l_span;
152-
}
153-
}
147+
l.span = l.span.substitute_dummy(r_span).substitute_dummy(l_span);
154148
}
155149
}
156150

@@ -162,9 +156,8 @@ impl VClock {
162156

163157
mut_slice[idx.index()] = other[idx];
164158

165-
if other[idx].span == DUMMY_SP {
166-
mut_slice[idx.index()].span = prev_span;
167-
}
159+
let span = &mut mut_slice[idx.index()].span;
160+
*span = span.substitute_dummy(prev_span);
168161
}
169162

170163
/// Set the vector to the all-zero vector

src/tools/miri/tests/fail/data_race/alloc_read_race.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ help: The Read on thread `<unnamed>` is here
88
--> $DIR/alloc_read_race.rs:LL:CC
99
|
1010
LL | ... *pointer.load(Ordering::Relaxed)
11-
| ^
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
help: The Allocate on thread `<unnamed>` is here
1313
--> $DIR/alloc_read_race.rs:LL:CC
1414
|

src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | *atomic_ref.get_mut()
55
| ^^^^^^^^^^^^^^^^^^^^^ Data race detected between Read on thread `<unnamed>` and Atomic Store on thread `<unnamed>` at ALLOC
66
|
77
help: The Read on thread `<unnamed>` is here
8-
--> RUSTLIB/core/src/ptr/mod.rs:LL:CC
8+
--> $DIR/atomic_write_na_read_race1.rs:LL:CC
99
|
10-
LL | }
11-
| ^
10+
LL | *atomic_ref.get_mut()
11+
| ^^^^^^^^^^^^^^^^^^^^^
1212
help: The Atomic Store on thread `<unnamed>` is here
1313
--> $DIR/atomic_write_na_read_race1.rs:LL:CC
1414
|

src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ help: The Atomic Store on thread `<unnamed>` is here
1010
LL | ... (&*c.0).store(32, Ordering::SeqCst);
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
help: The Read on thread `<unnamed>` is here
13-
--> RUSTLIB/core/src/ptr/mod.rs:LL:CC
13+
--> $DIR/atomic_write_na_read_race2.rs:LL:CC
1414
|
15-
LL | }
16-
| ^
15+
LL | let _val = *(c.0 as *mut usize);
16+
| ^^^^^^^^^^^^^^^^^^^^
1717
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
1818
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
1919
= note: BACKTRACE:

src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ LL | | std::mem::align_of::<usize>(),
2020
LL | | );
2121
| |_____________^
2222
help: The Read on thread `<unnamed>` is here
23-
--> RUSTLIB/core/src/ptr/mod.rs:LL:CC
23+
--> $DIR/dealloc_read_race1.rs:LL:CC
2424
|
25-
LL | }
26-
| ^
25+
LL | let _val = *ptr.0;
26+
| ^^^^^^
2727
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
2828
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
2929
= note: BACKTRACE:

src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ help: The Read on thread `<unnamed>` is here
1313
--> $DIR/dealloc_read_race_stack.rs:LL:CC
1414
|
1515
LL | *pointer.load(Ordering::Acquire)
16-
| ^
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
1818
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
1919
= note: BACKTRACE:

src/tools/miri/tests/fail/data_race/read_write_race.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ help: The Write on thread `<unnamed>` is here
1010
LL | *c.0 = 64;
1111
| ^^^^^^^^^
1212
help: The Read on thread `<unnamed>` is here
13-
--> RUSTLIB/core/src/ptr/mod.rs:LL:CC
13+
--> $DIR/read_write_race.rs:LL:CC
1414
|
15-
LL | }
16-
| ^
15+
LL | let _val = *c.0;
16+
| ^^^^
1717
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
1818
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
1919
= note: BACKTRACE:

src/tools/miri/tests/fail/data_race/read_write_race_stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | stack_var
77
help: The Read on thread `<unnamed>` is here
88
--> $DIR/read_write_race_stack.rs:LL:CC
99
|
10-
LL | sleep(Duration::from_millis(200));
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | stack_var
11+
| ^^^^^^^^^
1212
help: The Write on thread `<unnamed>` is here
1313
--> $DIR/read_write_race_stack.rs:LL:CC
1414
|

src/tools/miri/tests/fail/data_race/relax_acquire_race.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | *c.0
77
help: The Read on thread `<unnamed>` is here
88
--> $DIR/relax_acquire_race.rs:LL:CC
99
|
10-
LL | if SYNC.load(Ordering::Acquire) == 2 {
11-
| ^
10+
LL | *c.0
11+
| ^^^^
1212
help: The Write on thread `<unnamed>` is here
1313
--> $DIR/relax_acquire_race.rs:LL:CC
1414
|

src/tools/miri/tests/fail/data_race/release_seq_race.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | *c.0
77
help: The Read on thread `<unnamed>` is here
88
--> $DIR/release_seq_race.rs:LL:CC
99
|
10-
LL | if SYNC.load(Ordering::Acquire) == 3 {
11-
| ^
10+
LL | *c.0
11+
| ^^^^
1212
help: The Write on thread `<unnamed>` is here
1313
--> $DIR/release_seq_race.rs:LL:CC
1414
|

src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | *c.0
77
help: The Read on thread `<unnamed>` is here
88
--> $DIR/release_seq_race_same_thread.rs:LL:CC
99
|
10-
LL | if SYNC.load(Ordering::Acquire) == 2 {
11-
| ^
10+
LL | *c.0
11+
| ^^^^
1212
help: The Write on thread `<unnamed>` is here
1313
--> $DIR/release_seq_race_same_thread.rs:LL:CC
1414
|

src/tools/miri/tests/fail/data_race/rmw_race.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | *c.0
77
help: The Read on thread `<unnamed>` is here
88
--> $DIR/rmw_race.rs:LL:CC
99
|
10-
LL | if SYNC.load(Ordering::Acquire) == 3 {
11-
| ^
10+
LL | *c.0
11+
| ^^^^
1212
help: The Write on thread `<unnamed>` is here
1313
--> $DIR/rmw_race.rs:LL:CC
1414
|

src/tools/miri/tests/fail/data_race/stack_pop_race.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ help: The Deallocate on thread `main` is here
1010
LL | }
1111
| ^
1212
help: The Read on thread `<unnamed>` is here
13-
--> RUSTLIB/core/src/ptr/mod.rs:LL:CC
13+
--> $DIR/stack_pop_race.rs:LL:CC
1414
|
15-
LL | }
16-
| ^
15+
LL | let _val = unsafe { *ptr.0 };
16+
| ^^^^^^
1717
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
1818
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
1919
= note: BACKTRACE:

src/tools/miri/tests/fail/stacked_borrows/retag_data_race_read.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ LL | *p = 5;
1212
help: The Read on thread `<unnamed>` is here
1313
--> $DIR/retag_data_race_read.rs:LL:CC
1414
|
15-
LL | let t1 = std::thread::spawn(move || thread_1(p));
16-
| ^
15+
LL | let _r = &*p;
16+
| ^^^
1717
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
1818
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
1919
= note: BACKTRACE:

0 commit comments

Comments
 (0)