diff --git a/cargo-miri/src/phases.rs b/cargo-miri/src/phases.rs index 3c36f606d8..8d48b9c8ad 100644 --- a/cargo-miri/src/phases.rs +++ b/cargo-miri/src/phases.rs @@ -23,6 +23,12 @@ Subcommands: clean Clean the Miri cache & target directory The cargo options are exactly the same as for `cargo run` and `cargo test`, respectively. +Furthermore, the following extra flags and environment variables are recognized for `run` and `test`: + + --many-seeds[=from..to] Run the program/tests many times with different seeds in the given range. + The range defaults to `0..64`. + + MIRIFLAGS Extra flags to pass to the Miri driver. Use this to pass `-Zmiri-...` flags. Examples: cargo miri run diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 14e29aa423..47f0913acc 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -227,8 +227,8 @@ pub fn report_error<'tcx>( let helps = match info { UnsupportedInIsolation(_) => vec![ - (None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation;")), - (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")), + (None, format!("set `MIRIFLAGS=-Zmiri-disable-isolation` to disable isolation;")), + (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")), ], UnsupportedForeignItem(_) => { vec![ @@ -463,19 +463,22 @@ pub fn report_leaks<'tcx>( ) { let mut any_pruned = false; for (id, kind, mut alloc) in leaks { + let mut title = format!( + "memory leaked: {id:?} ({}, size: {:?}, align: {:?})", + kind, + alloc.size().bytes(), + alloc.align.bytes() + ); let Some(backtrace) = alloc.extra.backtrace.take() else { + ecx.tcx.dcx().err(title); continue; }; + title.push_str(", allocated here:"); let (backtrace, pruned) = prune_stacktrace(backtrace, &ecx.machine); any_pruned |= pruned; report_msg( DiagLevel::Error, - format!( - "memory leaked: {id:?} ({}, size: {:?}, align: {:?}), allocated here:", - kind, - alloc.size().bytes(), - alloc.align.bytes() - ), + title, vec![], vec![], vec![], @@ -642,13 +645,9 @@ impl<'tcx> MiriMachine<'tcx> { ( None, format!( - "This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`," + "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." ), ), - ( - None, - format!("which means that Miri might miss pointer bugs in this program."), - ), ( None, format!( @@ -664,13 +663,13 @@ impl<'tcx> MiriMachine<'tcx> { ( None, format!( - "You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics." + "You can then set `MIRIFLAGS=-Zmiri-strict-provenance` to ensure you are not relying on `with_exposed_provenance` semantics." ), ), ( None, format!( - "Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning." + "Alternatively, `MIRIFLAGS=-Zmiri-permissive-provenance` disables this warning." ), ), ], diff --git a/src/eval.rs b/src/eval.rs index 35f7f43f12..bd11439971 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -468,7 +468,7 @@ pub fn eval_entry<'tcx>( // Check for thread leaks. if !ecx.have_all_terminated() { tcx.dcx().err("the main thread terminated without waiting for all remaining threads"); - tcx.dcx().note("pass `-Zmiri-ignore-leaks` to disable this check"); + tcx.dcx().note("set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check"); return None; } // Check for memory leaks. @@ -476,14 +476,7 @@ pub fn eval_entry<'tcx>( let leaks = ecx.find_leaked_allocations(&ecx.machine.static_roots); if !leaks.is_empty() { report_leaks(&ecx, leaks); - let leak_message = "the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check"; - if ecx.machine.collect_leak_backtraces { - // If we are collecting leak backtraces, each leak is a distinct error diagnostic. - tcx.dcx().note(leak_message); - } else { - // If we do not have backtraces, we just report an error without any span. - tcx.dcx().err(leak_message); - }; + tcx.dcx().note("set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check"); // Ignore the provided return code - let the reported error // determine the return code. return None; diff --git a/tests/fail-dep/concurrency/libc_pthread_create_main_terminate.stderr b/tests/fail-dep/concurrency/libc_pthread_create_main_terminate.stderr index 078b7d2e0d..9d6be16b83 100644 --- a/tests/fail-dep/concurrency/libc_pthread_create_main_terminate.stderr +++ b/tests/fail-dep/concurrency/libc_pthread_create_main_terminate.stderr @@ -1,6 +1,6 @@ error: the main thread terminated without waiting for all remaining threads -note: pass `-Zmiri-ignore-leaks` to disable this check +note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check error: aborting due to 1 previous error diff --git a/tests/fail-dep/libc/aligned_alloc_size_zero_leak.stderr b/tests/fail-dep/libc/aligned_alloc_size_zero_leak.stderr index b0756d5721..91c6782332 100644 --- a/tests/fail-dep/libc/aligned_alloc_size_zero_leak.stderr +++ b/tests/fail-dep/libc/aligned_alloc_size_zero_leak.stderr @@ -9,7 +9,7 @@ LL | aligned_alloc(2, 0); note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace -note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check +note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check error: aborting due to 1 previous error diff --git a/tests/fail-dep/libc/fs/isolated_stdin.stderr b/tests/fail-dep/libc/fs/isolated_stdin.stderr index 1d6626dda7..9abe145ea9 100644 --- a/tests/fail-dep/libc/fs/isolated_stdin.stderr +++ b/tests/fail-dep/libc/fs/isolated_stdin.stderr @@ -4,8 +4,8 @@ error: unsupported operation: `read` from stdin not available when isolation is LL | libc::read(0, bytes.as_mut_ptr() as *mut libc::c_void, 512); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `read` from stdin not available when isolation is enabled | - = help: pass the flag `-Zmiri-disable-isolation` to disable isolation; - = 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 + = help: set `MIRIFLAGS=-Zmiri-disable-isolation` to disable isolation; + = 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 = note: BACKTRACE: = note: inside `main` at $DIR/isolated_stdin.rs:LL:CC diff --git a/tests/fail-dep/libc/malloc_zero_memory_leak.stderr b/tests/fail-dep/libc/malloc_zero_memory_leak.stderr index 65ce0dcdcd..657262b8d4 100644 --- a/tests/fail-dep/libc/malloc_zero_memory_leak.stderr +++ b/tests/fail-dep/libc/malloc_zero_memory_leak.stderr @@ -9,7 +9,7 @@ LL | let _ptr = libc::malloc(0); note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace -note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check +note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check error: aborting due to 1 previous error diff --git a/tests/fail-dep/libc/posix_memalign_size_zero_leak.stderr b/tests/fail-dep/libc/posix_memalign_size_zero_leak.stderr index 7ea0fa3146..2639031f1c 100644 --- a/tests/fail-dep/libc/posix_memalign_size_zero_leak.stderr +++ b/tests/fail-dep/libc/posix_memalign_size_zero_leak.stderr @@ -9,7 +9,7 @@ LL | let _ = unsafe { libc::posix_memalign(&mut ptr, align, size) }; note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace -note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check +note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check error: aborting due to 1 previous error diff --git a/tests/fail/intrinsics/ptr_metadata_uninit_slice_len.stderr b/tests/fail/intrinsics/ptr_metadata_uninit_slice_len.stderr index 4e2e721843..217bc82010 100644 --- a/tests/fail/intrinsics/ptr_metadata_uninit_slice_len.stderr +++ b/tests/fail/intrinsics/ptr_metadata_uninit_slice_len.stderr @@ -4,12 +4,11 @@ warning: integer-to-pointer cast LL | (*p.as_mut_ptr().cast::<[*const i32; 2]>())[0] = 4 as *const i32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast | - = help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`, - = help: which means that Miri might miss pointer bugs in this program. + = 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. = help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation. = 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. - = help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics. - = help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning. + = help: You can then set `MIRIFLAGS=-Zmiri-strict-provenance` to ensure you are not relying on `with_exposed_provenance` semantics. + = help: Alternatively, `MIRIFLAGS=-Zmiri-permissive-provenance` disables this warning. = note: BACKTRACE: = note: inside `main` at $DIR/ptr_metadata_uninit_slice_len.rs:LL:CC diff --git a/tests/fail/memleak.stderr b/tests/fail/memleak.stderr index 8ba78ef664..a9ee76fbe8 100644 --- a/tests/fail/memleak.stderr +++ b/tests/fail/memleak.stderr @@ -18,7 +18,7 @@ LL | std::mem::forget(Box::new(42)); note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace -note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check +note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check error: aborting due to 1 previous error diff --git a/tests/fail/memleak_no_backtrace.rs b/tests/fail/memleak_no_backtrace.rs index a1f8d9957f..1f8d8ba7a7 100644 --- a/tests/fail/memleak_no_backtrace.rs +++ b/tests/fail/memleak_no_backtrace.rs @@ -1,5 +1,5 @@ //@compile-flags: -Zmiri-disable-leak-backtraces -//@error-in-other-file: the evaluated program leaked memory +//@error-in-other-file: memory leaked //@normalize-stderr-test: ".*│.*" -> "$$stripped$$" fn main() { diff --git a/tests/fail/memleak_no_backtrace.stderr b/tests/fail/memleak_no_backtrace.stderr index 22e8c55806..6850928e15 100644 --- a/tests/fail/memleak_no_backtrace.stderr +++ b/tests/fail/memleak_no_backtrace.stderr @@ -1,4 +1,6 @@ -error: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check +error: memory leaked: ALLOC (Rust heap, size: 4, align: 4) + +note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check error: aborting due to 1 previous error diff --git a/tests/fail/memleak_rc.64bit.stderr b/tests/fail/memleak_rc.64bit.stderr deleted file mode 100644 index 1c85a0f9d9..0000000000 --- a/tests/fail/memleak_rc.64bit.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error: memory leaked: ALLOC (Rust heap, size: 32, align: 8), allocated here: - --> RUSTLIB/alloc/src/alloc.rs:LL:CC - | -LL | __rust_alloc(layout.size(), layout.align()) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: BACKTRACE: - = note: inside `std::alloc::alloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC - = note: inside `std::alloc::Global::alloc_impl` at RUSTLIB/alloc/src/alloc.rs:LL:CC - = note: inside `::allocate` at RUSTLIB/alloc/src/alloc.rs:LL:CC - = note: inside `alloc::alloc::exchange_malloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC - = note: inside `std::boxed::Box::>>>::new` at RUSTLIB/alloc/src/boxed.rs:LL:CC - = note: inside `std::rc::Rc::>>::new` at RUSTLIB/alloc/src/rc.rs:LL:CC -note: inside `main` - --> $DIR/memleak_rc.rs:LL:CC - | -LL | let x = Dummy(Rc::new(RefCell::new(None))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace - -note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check - -error: aborting due to 1 previous error - diff --git a/tests/fail/memleak_rc.rs b/tests/fail/memleak_rc.rs index 0927612d08..2d12c1223c 100644 --- a/tests/fail/memleak_rc.rs +++ b/tests/fail/memleak_rc.rs @@ -1,6 +1,6 @@ //@error-in-other-file: memory leaked -//@stderr-per-bitwidth //@normalize-stderr-test: ".*│.*" -> "$$stripped$$" +//@normalize-stderr-test: "Rust heap, size: [0-9]+, align: [0-9]+" -> "Rust heap, SIZE, ALIGN" use std::cell::RefCell; use std::rc::Rc; diff --git a/tests/fail/memleak_rc.32bit.stderr b/tests/fail/memleak_rc.stderr similarity index 86% rename from tests/fail/memleak_rc.32bit.stderr rename to tests/fail/memleak_rc.stderr index 781e1458db..dbf2daf818 100644 --- a/tests/fail/memleak_rc.32bit.stderr +++ b/tests/fail/memleak_rc.stderr @@ -1,4 +1,4 @@ -error: memory leaked: ALLOC (Rust heap, size: 16, align: 4), allocated here: +error: memory leaked: ALLOC (Rust heap, SIZE, ALIGN), allocated here: --> RUSTLIB/alloc/src/alloc.rs:LL:CC | LL | __rust_alloc(layout.size(), layout.align()) @@ -19,7 +19,7 @@ LL | let x = Dummy(Rc::new(RefCell::new(None))); note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace -note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check +note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check error: aborting due to 1 previous error diff --git a/tests/fail/shims/fs/isolated_file.stderr b/tests/fail/shims/fs/isolated_file.stderr index 1f08649428..ec956f8334 100644 --- a/tests/fail/shims/fs/isolated_file.stderr +++ b/tests/fail/shims/fs/isolated_file.stderr @@ -4,8 +4,8 @@ error: unsupported operation: `open` not available when isolation is enabled LL | let fd = cvt_r(|| unsafe { open64(path.as_ptr(), flags, opts.mode as c_int) })?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `open` not available when isolation is enabled | - = help: pass the flag `-Zmiri-disable-isolation` to disable isolation; - = 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 + = help: set `MIRIFLAGS=-Zmiri-disable-isolation` to disable isolation; + = 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 = note: BACKTRACE: = note: inside closure at RUSTLIB/std/src/sys/pal/PLATFORM/fs.rs:LL:CC = note: inside `std::sys::pal::PLATFORM::cvt_r::` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC diff --git a/tests/fail/tls_macro_leak.stderr b/tests/fail/tls_macro_leak.stderr index 40b21f8625..c7c641a30f 100644 --- a/tests/fail/tls_macro_leak.stderr +++ b/tests/fail/tls_macro_leak.stderr @@ -27,7 +27,7 @@ LL | | }); note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace -note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check +note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check error: aborting due to 1 previous error diff --git a/tests/fail/tls_static_leak.stderr b/tests/fail/tls_static_leak.stderr index 580b52c151..f7b90a1118 100644 --- a/tests/fail/tls_static_leak.stderr +++ b/tests/fail/tls_static_leak.stderr @@ -18,7 +18,7 @@ LL | TLS.set(Some(Box::leak(Box::new(123)))); note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace -note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check +note: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check error: aborting due to 1 previous error diff --git a/tests/pass/box.stack.stderr b/tests/pass/box.stack.stderr index 1a4d52ee31..341f84c899 100644 --- a/tests/pass/box.stack.stderr +++ b/tests/pass/box.stack.stderr @@ -4,12 +4,11 @@ warning: integer-to-pointer cast LL | let r2 = ((r as usize) + 0) as *mut i32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast | - = help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`, - = help: which means that Miri might miss pointer bugs in this program. + = 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. = help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation. = 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. - = help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics. - = help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning. + = help: You can then set `MIRIFLAGS=-Zmiri-strict-provenance` to ensure you are not relying on `with_exposed_provenance` semantics. + = help: Alternatively, `MIRIFLAGS=-Zmiri-permissive-provenance` disables this warning. = note: BACKTRACE: = note: inside `into_raw` at $DIR/box.rs:LL:CC note: inside `main` diff --git a/tests/pass/extern_types.stack.stderr b/tests/pass/extern_types.stack.stderr index 275d718129..03a9167abb 100644 --- a/tests/pass/extern_types.stack.stderr +++ b/tests/pass/extern_types.stack.stderr @@ -4,12 +4,11 @@ warning: integer-to-pointer cast LL | let x: &Foo = unsafe { &*(16 as *const Foo) }; | ^^^^^^^^^^^^^^^^^^ integer-to-pointer cast | - = help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`, - = help: which means that Miri might miss pointer bugs in this program. + = 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. = help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation. = 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. - = help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics. - = help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning. + = help: You can then set `MIRIFLAGS=-Zmiri-strict-provenance` to ensure you are not relying on `with_exposed_provenance` semantics. + = help: Alternatively, `MIRIFLAGS=-Zmiri-permissive-provenance` disables this warning. = note: BACKTRACE: = note: inside `main` at $DIR/extern_types.rs:LL:CC diff --git a/tests/pass/stacked-borrows/issue-miri-2389.stderr b/tests/pass/stacked-borrows/issue-miri-2389.stderr index 7cbfad3942..b0e1adf27d 100644 --- a/tests/pass/stacked-borrows/issue-miri-2389.stderr +++ b/tests/pass/stacked-borrows/issue-miri-2389.stderr @@ -4,12 +4,11 @@ warning: integer-to-pointer cast LL | let wildcard = &root0 as *const Cell as usize as *const Cell; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast | - = help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`, - = help: which means that Miri might miss pointer bugs in this program. + = 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. = help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation. = 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. - = help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics. - = help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning. + = help: You can then set `MIRIFLAGS=-Zmiri-strict-provenance` to ensure you are not relying on `with_exposed_provenance` semantics. + = help: Alternatively, `MIRIFLAGS=-Zmiri-permissive-provenance` disables this warning. = note: BACKTRACE: = note: inside `main` at $DIR/issue-miri-2389.rs:LL:CC