Skip to content

Commit 9439f33

Browse files
committed
make better use of label for data-race and some other errors
1 parent bb53df1 commit 9439f33

File tree

120 files changed

+240
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+240
-388
lines changed

src/tools/miri/src/diagnostics.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl fmt::Display for TerminationInfo {
8585
DataRace { involves_non_atomic, ptr, op1, op2, .. } =>
8686
write!(
8787
f,
88-
"{} detected between (1) {} on {} and (2) {} on {} at {ptr:?}. (2) just happened here",
88+
"{} detected between (1) {} on {} and (2) {} on {} at {ptr:?}",
8989
if *involves_non_atomic { "Data race" } else { "Race condition" },
9090
op1.action,
9191
op1.thread_info,
@@ -224,7 +224,7 @@ pub fn report_error<'tcx>(
224224
use InterpErrorKind::*;
225225
use UndefinedBehaviorInfo::*;
226226

227-
let mut msg = vec![];
227+
let mut labels = vec![];
228228

229229
let (title, helps) = if let MachineStop(info) = e.kind() {
230230
let info = info.downcast_ref::<TerminationInfo>().expect("invalid MachineStop payload");
@@ -237,7 +237,10 @@ pub fn report_error<'tcx>(
237237
Some("unsupported operation"),
238238
StackedBorrowsUb { .. } | TreeBorrowsUb { .. } | DataRace { .. } =>
239239
Some("Undefined Behavior"),
240-
Deadlock => Some("deadlock"),
240+
Deadlock => {
241+
labels.push(format!("this thread got stuck here"));
242+
None
243+
}
241244
GenmcStuckExecution => {
242245
// This case should only happen in GenMC mode. We treat it like a normal program exit.
243246
assert!(ecx.machine.data_race.as_genmc_ref().is_some());
@@ -259,7 +262,7 @@ pub fn report_error<'tcx>(
259262
]
260263
}
261264
StackedBorrowsUb { help, history, .. } => {
262-
msg.extend(help.clone());
265+
labels.extend(help.clone());
263266
let mut helps = vec![
264267
note!("this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental"),
265268
note!("see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information"),
@@ -297,6 +300,7 @@ pub fn report_error<'tcx>(
297300
Int2PtrWithStrictProvenance =>
298301
vec![note!("use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead")],
299302
DataRace { op1, extra, retag_explain, .. } => {
303+
labels.push(format!("(2) just happened here"));
300304
let mut helps = vec![note_span!(op1.span, "and (1) occurred earlier here")];
301305
if let Some(extra) = extra {
302306
helps.push(note!("{extra}"));
@@ -432,12 +436,14 @@ pub fn report_error<'tcx>(
432436
}
433437
write!(primary_msg, "{}", format_interp_error(ecx.tcx.dcx(), e)).unwrap();
434438

435-
msg.insert(0, format!("{} occurred here", title.unwrap_or("error")));
439+
if labels.is_empty() {
440+
labels.push(format!("{} occurred here", title.unwrap_or("error")));
441+
}
436442

437443
report_msg(
438444
DiagLevel::Error,
439445
primary_msg,
440-
msg,
446+
labels,
441447
vec![],
442448
helps,
443449
&stacktrace,
@@ -455,8 +461,8 @@ pub fn report_error<'tcx>(
455461
any_pruned |= was_pruned;
456462
report_msg(
457463
DiagLevel::Error,
458-
format!("deadlock: the evaluated program deadlocked"),
459-
vec![format!("the evaluated program deadlocked")],
464+
format!("the evaluated program deadlocked"),
465+
vec![format!("this thread got stuck here")],
460466
vec![],
461467
vec![],
462468
&stacktrace,
@@ -617,7 +623,7 @@ impl<'tcx> MiriMachine<'tcx> {
617623
let stacktrace = Frame::generate_stacktrace_from_stack(self.threads.active_thread_stack());
618624
let (stacktrace, _was_pruned) = prune_stacktrace(stacktrace, self);
619625

620-
let (title, diag_level) = match &e {
626+
let (label, diag_level) = match &e {
621627
RejectedIsolatedOp(_) =>
622628
("operation rejected by isolation".to_string(), DiagLevel::Warning),
623629
Int2Ptr { .. } => ("integer-to-pointer cast".to_string(), DiagLevel::Warning),
@@ -632,10 +638,10 @@ impl<'tcx> MiriMachine<'tcx> {
632638
| FreedAlloc(..)
633639
| ProgressReport { .. }
634640
| WeakMemoryOutdatedLoad { .. } =>
635-
("tracking was triggered".to_string(), DiagLevel::Note),
641+
("tracking was triggered here".to_string(), DiagLevel::Note),
636642
};
637643

638-
let msg = match &e {
644+
let title = match &e {
639645
CreatedPointerTag(tag, None, _) => format!("created base tag {tag:?}"),
640646
CreatedPointerTag(tag, Some(perm), None) =>
641647
format!("created {tag:?} with {perm} derived from unknown tag"),
@@ -738,7 +744,7 @@ impl<'tcx> MiriMachine<'tcx> {
738744
report_msg(
739745
diag_level,
740746
title,
741-
vec![msg],
747+
vec![label],
742748
notes,
743749
helps,
744750
&stacktrace,

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
--> tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.rs:LL:CC
33
|
44
LL | assert_eq!(libc::pthread_mutex_lock(lock_copy.0.get() as *mut _), 0);
5-
| ^ deadlock occurred here
5+
| ^ this thread got stuck here
66
|
77
= note: BACKTRACE on thread `unnamed-ID`:
88
= note: inside closure at tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.rs:LL:CC
99

10-
error: deadlock: the evaluated program deadlocked
10+
error: the evaluated program deadlocked
1111
--> RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC
1212
|
1313
LL | let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) };
14-
| ^ the evaluated program deadlocked
14+
| ^ this thread got stuck here
1515
|
1616
= note: BACKTRACE:
1717
= note: inside `std::sys::pal::PLATFORM::thread::Thread::join` at RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_normal_reentrant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ fn main() {
1212
assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0);
1313
// A "normal" mutex properly tries to acquire the lock even if its is already held
1414
// by the current thread -- and then we deadlock.
15-
libc::pthread_mutex_lock(&mut mutex as *mut _); //~ ERROR: deadlock: the evaluated program deadlocked
15+
libc::pthread_mutex_lock(&mut mutex as *mut _); //~ ERROR: the evaluated program deadlocked
1616
}
1717
}

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_normal_reentrant.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
--> tests/fail-dep/concurrency/libc_pthread_mutex_normal_reentrant.rs:LL:CC
33
|
44
LL | libc::pthread_mutex_lock(&mut mutex as *mut _);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deadlock occurred here
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this thread got stuck here
66
|
77
= note: BACKTRACE:
88
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_mutex_normal_reentrant.rs:LL:CC

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_read_write_deadlock_single_thread.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
--> tests/fail-dep/concurrency/libc_pthread_rwlock_read_write_deadlock_single_thread.rs:LL:CC
33
|
44
LL | libc::pthread_rwlock_wrlock(rw.get());
5-
| ^ deadlock occurred here
5+
| ^ this thread got stuck here
66
|
77
= note: BACKTRACE:
88
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_rwlock_read_write_deadlock_single_thread.rs:LL:CC

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
--> tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock.rs:LL:CC
33
|
44
LL | assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mut _), 0);
5-
| ^ deadlock occurred here
5+
| ^ this thread got stuck here
66
|
77
= note: BACKTRACE on thread `unnamed-ID`:
88
= note: inside closure at tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock.rs:LL:CC
99

10-
error: deadlock: the evaluated program deadlocked
10+
error: the evaluated program deadlocked
1111
--> RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC
1212
|
1313
LL | let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) };
14-
| ^ the evaluated program deadlocked
14+
| ^ this thread got stuck here
1515
|
1616
= note: BACKTRACE:
1717
= note: inside `std::sys::pal::PLATFORM::thread::Thread::join` at RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock_single_thread.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
--> tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock_single_thread.rs:LL:CC
33
|
44
LL | libc::pthread_rwlock_rdlock(rw.get());
5-
| ^ deadlock occurred here
5+
| ^ this thread got stuck here
66
|
77
= note: BACKTRACE:
88
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock_single_thread.rs:LL:CC

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
--> tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock.rs:LL:CC
33
|
44
LL | assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mut _), 0);
5-
| ^ deadlock occurred here
5+
| ^ this thread got stuck here
66
|
77
= note: BACKTRACE on thread `unnamed-ID`:
88
= note: inside closure at tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock.rs:LL:CC
99

10-
error: deadlock: the evaluated program deadlocked
10+
error: the evaluated program deadlocked
1111
--> RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC
1212
|
1313
LL | let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) };
14-
| ^ the evaluated program deadlocked
14+
| ^ this thread got stuck here
1515
|
1616
= note: BACKTRACE:
1717
= note: inside `std::sys::pal::PLATFORM::thread::Thread::join` at RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock_single_thread.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
--> tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock_single_thread.rs:LL:CC
33
|
44
LL | libc::pthread_rwlock_wrlock(rw.get());
5-
| ^ deadlock occurred here
5+
| ^ this thread got stuck here
66
|
77
= note: BACKTRACE:
88
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock_single_thread.rs:LL:CC

src/tools/miri/tests/fail-dep/libc/env-set_var-data-race.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `main` and (2) non-atomic read on thread `unnamed-ID` at ALLOC. (2) just happened here
1+
error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `main` and (2) non-atomic read on thread `unnamed-ID` at ALLOC
22
--> tests/fail-dep/libc/env-set_var-data-race.rs:LL:CC
33
|
44
LL | libc::getenv(b"TZ/0".as_ptr().cast());
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (2) just happened here
66
|
77
help: and (1) occurred earlier here
88
--> tests/fail-dep/libc/env-set_var-data-race.rs:LL:CC

src/tools/miri/tests/fail-dep/libc/eventfd_block_read_twice.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
--> RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC
33
|
44
LL | let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) };
5-
| ^ deadlock occurred here
5+
| ^ this thread got stuck here
66
|
77
= note: BACKTRACE:
88
= note: inside `std::sys::pal::PLATFORM::thread::Thread::join` at RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC
@@ -14,24 +14,24 @@ note: inside `main`
1414
LL | thread2.join().unwrap();
1515
| ^^^^^^^^^^^^^^
1616

17-
error: deadlock: the evaluated program deadlocked
17+
error: the evaluated program deadlocked
1818
|
19-
= note: the evaluated program deadlocked
19+
= note: this thread got stuck here
2020
= note: (no span available)
2121
= note: BACKTRACE on thread `unnamed-ID`:
2222

23-
error: deadlock: the evaluated program deadlocked
23+
error: the evaluated program deadlocked
2424
--> tests/fail-dep/libc/eventfd_block_read_twice.rs:LL:CC
2525
|
2626
LL | let res: i64 = unsafe { libc::read(fd, buf.as_mut_ptr().cast(), 8).try_into().unwrap() };
27-
| ^ the evaluated program deadlocked
27+
| ^ this thread got stuck here
2828
|
2929
= note: BACKTRACE on thread `unnamed-ID`:
3030
= note: inside closure at tests/fail-dep/libc/eventfd_block_read_twice.rs:LL:CC
3131

32-
error: deadlock: the evaluated program deadlocked
32+
error: the evaluated program deadlocked
3333
|
34-
= note: the evaluated program deadlocked
34+
= note: this thread got stuck here
3535
= note: (no span available)
3636
= note: BACKTRACE on thread `unnamed-ID`:
3737

src/tools/miri/tests/fail-dep/libc/eventfd_block_write_twice.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
--> RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC
33
|
44
LL | let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) };
5-
| ^ deadlock occurred here
5+
| ^ this thread got stuck here
66
|
77
= note: BACKTRACE:
88
= note: inside `std::sys::pal::PLATFORM::thread::Thread::join` at RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC
@@ -14,24 +14,24 @@ note: inside `main`
1414
LL | thread2.join().unwrap();
1515
| ^^^^^^^^^^^^^^
1616

17-
error: deadlock: the evaluated program deadlocked
17+
error: the evaluated program deadlocked
1818
|
19-
= note: the evaluated program deadlocked
19+
= note: this thread got stuck here
2020
= note: (no span available)
2121
= note: BACKTRACE on thread `unnamed-ID`:
2222

23-
error: deadlock: the evaluated program deadlocked
23+
error: the evaluated program deadlocked
2424
--> tests/fail-dep/libc/eventfd_block_write_twice.rs:LL:CC
2525
|
2626
LL | libc::write(fd, sized_8_data.as_ptr() as *const libc::c_void, 8).try_into().unwrap()
27-
| ^ the evaluated program deadlocked
27+
| ^ this thread got stuck here
2828
|
2929
= note: BACKTRACE on thread `unnamed-ID`:
3030
= note: inside closure at tests/fail-dep/libc/eventfd_block_write_twice.rs:LL:CC
3131

32-
error: deadlock: the evaluated program deadlocked
32+
error: the evaluated program deadlocked
3333
|
34-
= note: the evaluated program deadlocked
34+
= note: this thread got stuck here
3535
= note: (no span available)
3636
= note: BACKTRACE on thread `unnamed-ID`:
3737

src/tools/miri/tests/fail-dep/libc/fcntl_fsetfl_while_blocking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ignore-target: windows # Sockets/pipes are not implemented yet
2-
//~^ ERROR: deadlock: the evaluated program deadlocked
2+
//~^ ERROR: the evaluated program deadlocked
33
//@compile-flags: -Zmiri-deterministic-concurrency
44
use std::thread;
55

@@ -16,5 +16,5 @@ fn main() {
1616
});
1717
// Main thread will block on read.
1818
let _res = unsafe { libc::read(fds[0], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) };
19-
//~^ ERROR: deadlock: the evaluated program deadlocked
19+
//~^ ERROR: the evaluated program deadlocked
2020
}

src/tools/miri/tests/fail-dep/libc/fcntl_fsetfl_while_blocking.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error: deadlock: the evaluated program deadlocked
1+
error: the evaluated program deadlocked
22
|
3-
= note: deadlock occurred here
3+
= note: this thread got stuck here
44
= note: (no span available)
55
= note: BACKTRACE on thread `unnamed-ID`:
66

7-
error: deadlock: the evaluated program deadlocked
7+
error: the evaluated program deadlocked
88
--> tests/fail-dep/libc/fcntl_fsetfl_while_blocking.rs:LL:CC
99
|
1010
LL | let _res = unsafe { libc::read(fds[0], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) };
11-
| ^ the evaluated program deadlocked
11+
| ^ this thread got stuck here
1212
|
1313
= note: BACKTRACE:
1414
= note: inside `main` at tests/fail-dep/libc/fcntl_fsetfl_while_blocking.rs:LL:CC

src/tools/miri/tests/fail-dep/libc/libc-epoll-data-race.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `unnamed-ID` and (2) non-atomic read on thread `main` at ALLOC. (2) just happened here
1+
error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `unnamed-ID` and (2) non-atomic read on thread `main` at ALLOC
22
--> tests/fail-dep/libc/libc-epoll-data-race.rs:LL:CC
33
|
44
LL | assert_eq!({ VAL_TWO }, 51)
5-
| ^^^^^^^ Undefined Behavior occurred here
5+
| ^^^^^^^ (2) just happened here
66
|
77
help: and (1) occurred earlier here
88
--> tests/fail-dep/libc/libc-epoll-data-race.rs:LL:CC

0 commit comments

Comments
 (0)