Skip to content

Commit 05cc3e4

Browse files
committed
always show the origin_span of the failing thread
1 parent 32b8da9 commit 05cc3e4

File tree

66 files changed

+729
-82
lines changed

Some content is hidden

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

66 files changed

+729
-82
lines changed

src/diagnostics.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -555,35 +555,24 @@ pub fn report_msg<'tcx>(
555555
thread: Option<ThreadId>,
556556
machine: &MiriMachine<'tcx>,
557557
) {
558-
let span = match stacktrace.first() {
559-
Some(fi) => fi.span,
560-
None =>
561-
match thread {
562-
Some(thread_id) => machine.threads.thread_ref(thread_id).origin_span,
563-
// This fallback is super rare, but can happen e.g. when `main` has the wrong ABI
564-
None => DUMMY_SP,
565-
},
566-
};
567-
let sess = machine.tcx.sess;
558+
let origin_span = thread.map(|t| machine.threads.thread_ref(t).origin_span).unwrap_or(DUMMY_SP);
559+
let span = stacktrace.first().map(|fi| fi.span).unwrap_or(origin_span);
560+
// The only time we do not have an origin span is for `main`, and there we check the signature
561+
// upfront. So we should always have a span here.
562+
assert!(!span.is_dummy());
563+
564+
let tcx = machine.tcx;
568565
let level = match diag_level {
569566
DiagLevel::Error => Level::Error,
570567
DiagLevel::Warning => Level::Warning,
571568
DiagLevel::Note => Level::Note,
572569
};
573-
let mut err = Diag::<()>::new(sess.dcx(), level, title);
570+
let mut err = Diag::<()>::new(tcx.sess.dcx(), level, title);
574571
err.span(span);
575572

576573
// Show main message.
577-
if !span.is_dummy() {
578-
for line in span_msg {
579-
err.span_label(span, line);
580-
}
581-
} else {
582-
// Make sure we show the message even when it is a dummy span.
583-
for line in span_msg {
584-
err.note(line);
585-
}
586-
err.note("(no span available)");
574+
for line in span_msg {
575+
err.span_label(span, line);
587576
}
588577

589578
// Show note and help messages.
@@ -621,7 +610,7 @@ pub fn report_msg<'tcx>(
621610
.unwrap();
622611
}
623612
// Only print function name if we show a backtrace
624-
if rest.len() > 0 {
613+
if rest.len() > 0 || !origin_span.is_dummy() {
625614
if !fn_and_thread.is_empty() {
626615
fn_and_thread.push_str(", ");
627616
}
@@ -632,7 +621,7 @@ pub fn report_msg<'tcx>(
632621
// Print a `span_note` as otherwise the backtrace looks attached to the last
633622
// `span_help`. We somewhat arbitrarily use the span of the surrounding function.
634623
err.span_note(
635-
machine.tcx.def_span(first.instance.def_id()),
624+
tcx.def_span(first.instance.def_id()),
636625
format!("{level} occurred {fn_and_thread}"),
637626
);
638627
} else {
@@ -646,11 +635,14 @@ pub fn report_msg<'tcx>(
646635
if is_local {
647636
err.span_note(frame_info.span, format!("which got called {frame_info}"));
648637
} else {
649-
let sm = sess.source_map();
638+
let sm = tcx.sess.source_map();
650639
let span = sm.span_to_embeddable_string(frame_info.span);
651640
err.note(format!("which got called {frame_info} (at {span})"));
652641
}
653642
}
643+
if !origin_span.is_dummy() {
644+
err.span_note(origin_span, format!("which got called indirectly due to this code"));
645+
}
654646
} else if !span.is_dummy() {
655647
err.note(format!("this {level} occurred while pushing a call frame onto an empty stack"));
656648
err.note("the span indicates which code caused the function to be called, but may not be the literal call site");

tests/fail-dep/concurrency/apple_os_unfair_lock_move_with_queue.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ LL | let _val = atomic_ref.load(Ordering::Relaxed);
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9-
= note: this is on thread `unnamed-ID`
9+
= note: this is on thread `unnamed-ID`, inside closure
10+
note: which got called indirectly due to this code
11+
--> tests/fail-dep/concurrency/apple_os_unfair_lock_move_with_queue.rs:LL:CC
12+
|
13+
LL | / ... s.spawn(|| {
14+
LL | | ... let atomic_ref = unsafe { &*lock.get().cast::<AtomicU32>() };
15+
LL | | ... let _val = atomic_ref.load(Ordering::Relaxed);
16+
LL | | ... });
17+
| |________^
1018

1119
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1220

tests/fail-dep/concurrency/libc_pthread_join_main.stderr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ LL | ... assert_eq!(libc::pthread_join(thread_id, ptr::null_mut()), 0);
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9-
= note: this is on thread `unnamed-ID`
9+
= note: this is on thread `unnamed-ID`, inside closure
10+
note: which got called indirectly due to this code
11+
--> tests/fail-dep/concurrency/libc_pthread_join_main.rs:LL:CC
12+
|
13+
LL | let handle = thread::spawn(move || {
14+
| __________________^
15+
LL | | unsafe {
16+
LL | | assert_eq!(libc::pthread_join(thread_id, ptr::null_mut()), 0);
17+
LL | | }
18+
LL | | });
19+
| |______^
1020

1121
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1222

tests/fail-dep/concurrency/libc_pthread_join_multiple.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ LL | ... assert_eq!(libc::pthread_join(native_copy, ptr::null_mut()), 0);
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9-
= note: this is on thread `unnamed-ID`
9+
= note: this is on thread `unnamed-ID`, inside closure
10+
note: which got called indirectly due to this code
11+
--> tests/fail-dep/concurrency/libc_pthread_join_multiple.rs:LL:CC
12+
|
13+
LL | ... let handle = thread::spawn(move || {
14+
| ____________________^
15+
LL | | ... assert_eq!(libc::pthread_join(native_copy, ptr::null_mut()), 0);
16+
LL | | ... });
17+
| |________^
1018

1119
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1220

tests/fail-dep/concurrency/libc_pthread_join_self.stderr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@ LL | assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9-
= note: this is on thread `unnamed-ID`
9+
= note: this is on thread `unnamed-ID`, inside closure
10+
note: which got called indirectly due to this code
11+
--> tests/fail-dep/concurrency/libc_pthread_join_self.rs:LL:CC
12+
|
13+
LL | let handle = thread::spawn(|| {
14+
| __________________^
15+
LL | | unsafe {
16+
LL | | let native: libc::pthread_t = libc::pthread_self();
17+
LL | | assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
18+
LL | | }
19+
LL | | });
20+
| |______^
1021

1122
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1223

tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.stderr

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ error: the evaluated program deadlocked
2222
LL | assert_eq!(libc::pthread_mutex_lock(lock_copy.0.get() as *mut _), 0);
2323
| ^ thread got stuck here
2424
|
25-
= note: this is on thread `unnamed-ID`
25+
= note: this is on thread `unnamed-ID`, inside closure
26+
note: which got called indirectly due to this code
27+
--> tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.rs:LL:CC
28+
|
29+
LL | / thread::spawn(move || {
30+
LL | | assert_eq!(libc::pthread_mutex_lock(lock_copy.0.get() as *mut _), 0);
31+
LL | | })
32+
| |__________^
2633

2734
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
2835

tests/fail-dep/concurrency/libc_pthread_mutex_free_while_queued.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ note: which got called inside closure
1414
|
1515
LL | drop(unsafe { Box::from_raw(m.get().cast::<Mutex>()) });
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
note: which got called indirectly due to this code
18+
--> tests/fail-dep/concurrency/libc_pthread_mutex_free_while_queued.rs:LL:CC
19+
|
20+
LL | / s.spawn(|| {
21+
LL | | // Ensure we happen-after the initialization write.
22+
LL | | assert!(initialized.load(Ordering::Acquire));
23+
... |
24+
LL | | });
25+
| |__________^
1726

1827
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1928

tests/fail-dep/concurrency/libc_pthread_mutex_read_while_queued.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ LL | ... let _val = atomic_ref.load(Ordering::Relaxed);
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9-
= note: this is on thread `unnamed-ID`
9+
= note: this is on thread `unnamed-ID`, inside closure
10+
note: which got called indirectly due to this code
11+
--> tests/fail-dep/concurrency/libc_pthread_mutex_read_while_queued.rs:LL:CC
12+
|
13+
LL | / ... s.spawn(|| {
14+
LL | | ... let atomic_ref = unsafe { &*m.get().byte_add(OFFSET).cast::<AtomicU32>() };
15+
LL | | ... let _val = atomic_ref.load(Ordering::Relaxed);
16+
LL | | ... });
17+
| |________^
1018

1119
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1220

tests/fail-dep/concurrency/libc_pthread_mutex_write_while_queued.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ LL | atomic_ref.store(0, Ordering::Relaxed);
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9-
= note: this is on thread `unnamed-ID`
9+
= note: this is on thread `unnamed-ID`, inside closure
10+
note: which got called indirectly due to this code
11+
--> tests/fail-dep/concurrency/libc_pthread_mutex_write_while_queued.rs:LL:CC
12+
|
13+
LL | / s.spawn(|| {
14+
LL | | let atomic_ref = unsafe { &*m.get().byte_add(OFFSET).cast::<AtomicU32>() };
15+
LL | | atomic_ref.store(0, Ordering::Relaxed);
16+
LL | | });
17+
| |__________^
1018

1119
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1220

tests/fail-dep/concurrency/libc_pthread_mutex_wrong_owner.stderr

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ LL | ... assert_eq!(libc::pthread_mutex_unlock(lock_copy.0.get() as *mut _), 0
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9-
= note: this is on thread `unnamed-ID`
9+
= note: this is on thread `unnamed-ID`, inside closure
10+
note: which got called indirectly due to this code
11+
--> tests/fail-dep/concurrency/libc_pthread_mutex_wrong_owner.rs:LL:CC
12+
|
13+
LL | / ... thread::spawn(move || {
14+
LL | | ... assert_eq!(libc::pthread_mutex_unlock(lock_copy.0.get() as *mut _), 0);
15+
LL | | ... })
16+
| |________^
1017

1118
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1219

0 commit comments

Comments
 (0)