Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit af55a4a

Browse files
committed
Auto merge of rust-lang#3683 - RalfJung:MIRIFLAGS, r=RalfJung
tell people how to set miri flags fixes rust-lang/miri#3677
2 parents c84fa48 + 54594d6 commit af55a4a

21 files changed

+52
-81
lines changed

src/tools/miri/cargo-miri/src/phases.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Subcommands:
2323
clean Clean the Miri cache & target directory
2424
2525
The cargo options are exactly the same as for `cargo run` and `cargo test`, respectively.
26+
Furthermore, the following extra flags and environment variables are recognized for `run` and `test`:
27+
28+
--many-seeds[=from..to] Run the program/tests many times with different seeds in the given range.
29+
The range defaults to `0..64`.
30+
31+
MIRIFLAGS Extra flags to pass to the Miri driver. Use this to pass `-Zmiri-...` flags.
2632
2733
Examples:
2834
cargo miri run

src/tools/miri/src/diagnostics.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ pub fn report_error<'tcx>(
227227
let helps = match info {
228228
UnsupportedInIsolation(_) =>
229229
vec![
230-
(None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation;")),
231-
(None, format!("or pass `-Zmiri-isolation-error=warn` to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning")),
230+
(None, format!("set `MIRIFLAGS=-Zmiri-disable-isolation` to disable isolation;")),
231+
(None, format!("or set `MIRIFLAGS=-Zmiri-isolation-error=warn` to make Miri return an error code from isolated operations (if supported for that operation) and continue with a warning")),
232232
],
233233
UnsupportedForeignItem(_) => {
234234
vec![
@@ -463,19 +463,22 @@ pub fn report_leaks<'tcx>(
463463
) {
464464
let mut any_pruned = false;
465465
for (id, kind, mut alloc) in leaks {
466+
let mut title = format!(
467+
"memory leaked: {id:?} ({}, size: {:?}, align: {:?})",
468+
kind,
469+
alloc.size().bytes(),
470+
alloc.align.bytes()
471+
);
466472
let Some(backtrace) = alloc.extra.backtrace.take() else {
473+
ecx.tcx.dcx().err(title);
467474
continue;
468475
};
476+
title.push_str(", allocated here:");
469477
let (backtrace, pruned) = prune_stacktrace(backtrace, &ecx.machine);
470478
any_pruned |= pruned;
471479
report_msg(
472480
DiagLevel::Error,
473-
format!(
474-
"memory leaked: {id:?} ({}, size: {:?}, align: {:?}), allocated here:",
475-
kind,
476-
alloc.size().bytes(),
477-
alloc.align.bytes()
478-
),
481+
title,
479482
vec![],
480483
vec![],
481484
vec![],
@@ -642,13 +645,9 @@ impl<'tcx> MiriMachine<'tcx> {
642645
(
643646
None,
644647
format!(
645-
"This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,"
648+
"This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`, which means that Miri might miss pointer bugs in this program."
646649
),
647650
),
648-
(
649-
None,
650-
format!("which means that Miri might miss pointer bugs in this program."),
651-
),
652651
(
653652
None,
654653
format!(
@@ -664,13 +663,13 @@ impl<'tcx> MiriMachine<'tcx> {
664663
(
665664
None,
666665
format!(
667-
"You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics."
666+
"You can then set `MIRIFLAGS=-Zmiri-strict-provenance` to ensure you are not relying on `with_exposed_provenance` semantics."
668667
),
669668
),
670669
(
671670
None,
672671
format!(
673-
"Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning."
672+
"Alternatively, `MIRIFLAGS=-Zmiri-permissive-provenance` disables this warning."
674673
),
675674
),
676675
],

src/tools/miri/src/eval.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,22 +468,15 @@ pub fn eval_entry<'tcx>(
468468
// Check for thread leaks.
469469
if !ecx.have_all_terminated() {
470470
tcx.dcx().err("the main thread terminated without waiting for all remaining threads");
471-
tcx.dcx().note("pass `-Zmiri-ignore-leaks` to disable this check");
471+
tcx.dcx().note("set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check");
472472
return None;
473473
}
474474
// Check for memory leaks.
475475
info!("Additional static roots: {:?}", ecx.machine.static_roots);
476476
let leaks = ecx.find_leaked_allocations(&ecx.machine.static_roots);
477477
if !leaks.is_empty() {
478478
report_leaks(&ecx, leaks);
479-
let leak_message = "the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check";
480-
if ecx.machine.collect_leak_backtraces {
481-
// If we are collecting leak backtraces, each leak is a distinct error diagnostic.
482-
tcx.dcx().note(leak_message);
483-
} else {
484-
// If we do not have backtraces, we just report an error without any span.
485-
tcx.dcx().err(leak_message);
486-
};
479+
tcx.dcx().note("set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check");
487480
// Ignore the provided return code - let the reported error
488481
// determine the return code.
489482
return None;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
error: the main thread terminated without waiting for all remaining threads
22

3-
note: pass `-Zmiri-ignore-leaks` to disable this check
3+
note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check
44

55
error: aborting due to 1 previous error
66

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | aligned_alloc(2, 0);
99

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

12-
note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check
12+
note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check
1313

1414
error: aborting due to 1 previous error
1515

src/tools/miri/tests/fail-dep/libc/fs/isolated_stdin.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: unsupported operation: `read` from stdin not available when isolation is
44
LL | libc::read(0, bytes.as_mut_ptr() as *mut libc::c_void, 512);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `read` from stdin not available when isolation is enabled
66
|
7-
= help: pass the flag `-Zmiri-disable-isolation` to disable isolation;
8-
= help: or pass `-Zmiri-isolation-error=warn` to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning
7+
= help: set `MIRIFLAGS=-Zmiri-disable-isolation` to disable isolation;
8+
= help: or set `MIRIFLAGS=-Zmiri-isolation-error=warn` to make Miri return an error code from isolated operations (if supported for that operation) and continue with a warning
99
= note: BACKTRACE:
1010
= note: inside `main` at $DIR/isolated_stdin.rs:LL:CC
1111

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | let _ptr = libc::malloc(0);
99

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

12-
note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check
12+
note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check
1313

1414
error: aborting due to 1 previous error
1515

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | let _ = unsafe { libc::posix_memalign(&mut ptr, align, size) };
99

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

12-
note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check
12+
note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check
1313

1414
error: aborting due to 1 previous error
1515

src/tools/miri/tests/fail/intrinsics/ptr_metadata_uninit_slice_len.stderr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ warning: integer-to-pointer cast
44
LL | (*p.as_mut_ptr().cast::<[*const i32; 2]>())[0] = 4 as *const i32;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
66
|
7-
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,
8-
= help: which means that Miri might miss pointer bugs in this program.
7+
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`, which means that Miri might miss pointer bugs in this program.
98
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation.
109
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
11-
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics.
12-
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
10+
= help: You can then set `MIRIFLAGS=-Zmiri-strict-provenance` to ensure you are not relying on `with_exposed_provenance` semantics.
11+
= help: Alternatively, `MIRIFLAGS=-Zmiri-permissive-provenance` disables this warning.
1312
= note: BACKTRACE:
1413
= note: inside `main` at $DIR/ptr_metadata_uninit_slice_len.rs:LL:CC
1514

src/tools/miri/tests/fail/memleak.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | std::mem::forget(Box::new(42));
1818

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

21-
note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check
21+
note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check
2222

2323
error: aborting due to 1 previous error
2424

0 commit comments

Comments
 (0)