Skip to content

Commit fcd6309

Browse files
committed
Auto merge of rust-lang#150565 - RalfJung:miri, r=RalfJung
miri subtree update Subtree update of `miri` to rust-lang/miri@cb3bfe8. Created using https://github.com/rust-lang/josh-sync. r? `@ghost`
2 parents cc08b55 + facf7ad commit fcd6309

File tree

257 files changed

+2127
-1770
lines changed

Some content is hidden

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

257 files changed

+2127
-1770
lines changed

src/tools/miri/ci/ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ case $HOST_TARGET in
152152
# Partially supported targets (tier 2)
153153
BASIC="empty_main integer heap_alloc libc-mem vec string btreemap" # ensures we have the basics: pre-main code, system allocator
154154
UNIX="hello panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
155-
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random thread sync concurrency epoll eventfd
155+
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random thread sync concurrency epoll eventfd prctl
156156
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std
157157
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
158158
;;

src/tools/miri/src/diagnostics.rs

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub fn report_result<'tcx>(
250250
StackedBorrowsUb { .. } | TreeBorrowsUb { .. } | DataRace { .. } =>
251251
Some("Undefined Behavior"),
252252
LocalDeadlock => {
253-
labels.push(format!("this thread got stuck here"));
253+
labels.push(format!("thread got stuck here"));
254254
None
255255
}
256256
GlobalDeadlock => {
@@ -264,10 +264,7 @@ pub fn report_result<'tcx>(
264264
report_msg(
265265
DiagLevel::Error,
266266
format!("the evaluated program deadlocked"),
267-
vec![format!(
268-
"thread `{}` got stuck here",
269-
ecx.machine.threads.get_thread_display_name(thread)
270-
)],
267+
vec![format!("thread got stuck here")],
271268
vec![],
272269
vec![],
273270
&stacktrace,
@@ -558,86 +555,75 @@ fn report_msg<'tcx>(
558555
thread: Option<ThreadId>,
559556
machine: &MiriMachine<'tcx>,
560557
) {
561-
let span = match stacktrace.first() {
562-
Some(fi) => fi.span,
563-
None =>
564-
match thread {
565-
Some(thread_id) => machine.threads.thread_ref(thread_id).origin_span,
566-
None => DUMMY_SP,
567-
},
568-
};
569-
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;
570565
let level = match diag_level {
571566
DiagLevel::Error => Level::Error,
572567
DiagLevel::Warning => Level::Warning,
573568
DiagLevel::Note => Level::Note,
574569
};
575-
let mut err = Diag::<()>::new(sess.dcx(), level, title);
570+
let mut err = Diag::<()>::new(tcx.sess.dcx(), level, title);
576571
err.span(span);
577572

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

591578
// Show note and help messages.
592-
let mut extra_span = false;
593579
for (span_data, note) in notes {
594580
if let Some(span_data) = span_data {
595581
err.span_note(span_data.span(), note);
596-
extra_span = true;
597582
} else {
598583
err.note(note);
599584
}
600585
}
601586
for (span_data, help) in helps {
602587
if let Some(span_data) = span_data {
603588
err.span_help(span_data.span(), help);
604-
extra_span = true;
605589
} else {
606590
err.help(help);
607591
}
608592
}
593+
// Only print thread name if there are multiple threads.
594+
if let Some(thread) = thread
595+
&& machine.threads.get_total_thread_count() > 1
596+
{
597+
err.note(format!(
598+
"this is on thread `{}`",
599+
machine.threads.get_thread_display_name(thread)
600+
));
601+
}
609602

610603
// Add backtrace
611-
if stacktrace.len() > 1 {
612-
let mut backtrace_title = String::from("BACKTRACE");
613-
if extra_span {
614-
write!(backtrace_title, " (of the first span)").unwrap();
615-
}
616-
if let Some(thread) = thread {
617-
let thread_name = machine.threads.get_thread_display_name(thread);
618-
if thread_name != "main" {
619-
// Only print thread name if it is not `main`.
620-
write!(backtrace_title, " on thread `{thread_name}`").unwrap();
621-
};
622-
}
623-
write!(backtrace_title, ":").unwrap();
624-
err.note(backtrace_title);
625-
for (idx, frame_info) in stacktrace.iter().enumerate() {
626-
let is_local = machine.is_local(frame_info.instance);
627-
// No span for non-local frames and the first frame (which is the error site).
628-
if is_local && idx > 0 {
629-
err.subdiagnostic(frame_info.as_note(machine.tcx));
630-
} else {
631-
let sm = sess.source_map();
604+
if stacktrace.len() > 0 {
605+
// Skip it if we'd only shpw the span we have already shown
606+
if stacktrace.len() > 1 {
607+
let sm = tcx.sess.source_map();
608+
let mut out = format!("stack backtrace:");
609+
for (idx, frame_info) in stacktrace.iter().enumerate() {
632610
let span = sm.span_to_diagnostic_string(frame_info.span);
633-
err.note(format!("{frame_info} at {span}"));
611+
write!(out, "\n{idx}: {}", frame_info.instance).unwrap();
612+
write!(out, "\n at {span}").unwrap();
634613
}
614+
err.note(out);
635615
}
636-
} else if stacktrace.len() == 0 && !span.is_dummy() {
637-
err.note(format!(
638-
"this {} occurred while pushing a call frame onto an empty stack",
639-
level.to_str()
640-
));
616+
// For TLS dtors and non-main threads, show the "origin"
617+
if !origin_span.is_dummy() {
618+
let what = if stacktrace.len() > 1 {
619+
"the last function in that backtrace"
620+
} else {
621+
"the current function"
622+
};
623+
err.span_note(origin_span, format!("{what} got called indirectly due to this code"));
624+
}
625+
} else if !span.is_dummy() {
626+
err.note(format!("this {level} occurred while pushing a call frame onto an empty stack"));
641627
err.note("the span indicates which code caused the function to be called, but may not be the literal call site");
642628
}
643629

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@only-target: darwin
2+
//@compile-flags: -Zmiri-fixed-schedule
23
#![feature(sync_unsafe_cell)]
34

45
use std::cell::SyncUnsafeCell;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +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`
10+
note: the current function 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+
| |________^
918

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

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_cond_move.init.stderr

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ LL | libc::pthread_cond_destroy(cond2.as_mut_ptr());
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: BACKTRACE:
10-
= note: inside `check` at tests/fail-dep/concurrency/libc_pthread_cond_move.rs:LL:CC
11-
note: inside `main`
12-
--> tests/fail-dep/concurrency/libc_pthread_cond_move.rs:LL:CC
13-
|
14-
LL | check()
15-
| ^^^^^^^
9+
= note: stack backtrace:
10+
0: check
11+
at tests/fail-dep/concurrency/libc_pthread_cond_move.rs:LL:CC
12+
1: main
13+
at tests/fail-dep/concurrency/libc_pthread_cond_move.rs:LL:CC
1614

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

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_cond_move.static_initializer.stderr

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ LL | libc::pthread_cond_destroy(&mut cond2 as *mut _);
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: BACKTRACE:
10-
= note: inside `check` at tests/fail-dep/concurrency/libc_pthread_cond_move.rs:LL:CC
11-
note: inside `main`
12-
--> tests/fail-dep/concurrency/libc_pthread_cond_move.rs:LL:CC
13-
|
14-
LL | check()
15-
| ^^^^^^^
9+
= note: stack backtrace:
10+
0: check
11+
at tests/fail-dep/concurrency/libc_pthread_cond_move.rs:LL:CC
12+
1: main
13+
at tests/fail-dep/concurrency/libc_pthread_cond_move.rs:LL:CC
1614

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | libc::pthread_create(&mut native, ptr::null(), thread_start, pt
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`
910
= note: this error occurred while pushing a call frame onto an empty stack
1011
= note: the span indicates which code caused the function to be called, but may not be the literal call site
1112

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | libc::pthread_create(&mut native, ptr::null(), thread_start, pt
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`
910
= note: this error occurred while pushing a call frame onto an empty stack
1011
= note: the span indicates which code caused the function to be called, but may not be the literal call site
1112

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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 `main`
910

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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 `main`
910

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

0 commit comments

Comments
 (0)