diff --git a/src/tools/miri/README.md b/src/tools/miri/README.md index 5eb8c0fa7c99..63756624677e 100644 --- a/src/tools/miri/README.md +++ b/src/tools/miri/README.md @@ -318,8 +318,8 @@ environment variable. We first document the most relevant and most commonly used and `warn-nobacktrace` are the supported actions. The default is to `abort`, which halts the machine. Some (but not all) operations also support continuing execution with a "permission denied" error being returned to the program. - `warn` prints a full backtrace when that happens; `warn-nobacktrace` is less - verbose. `hide` hides the warning entirely. + `warn` prints a full backtrace each time that happens; `warn-nobacktrace` is less + verbose and shown at most once per operation. `hide` hides the warning entirely. * `-Zmiri-num-cpus` states the number of available CPUs to be reported by miri. By default, the number of available CPUs is `1`. Note that this flag does not affect how miri handles threads in any way. diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 65260254ae25..c3f4deb7c2ee 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -1,6 +1,8 @@ use std::cmp; +use std::collections::BTreeSet; use std::iter; use std::num::NonZero; +use std::sync::Mutex; use std::time::Duration; use rustc_apfloat::ieee::{Double, Single}; @@ -603,9 +605,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { match reject_with { RejectOpWith::Abort => isolation_abort_error(op_name), RejectOpWith::WarningWithoutBacktrace => { - this.tcx - .dcx() - .warn(format!("{op_name} was made to return an error due to isolation")); + // This exists to reduce verbosity; make sure we emit the warning at most once per + // operation. + static EMITTED_WARNINGS: Mutex> = Mutex::new(BTreeSet::new()); + + let mut emitted_warnings = EMITTED_WARNINGS.lock().unwrap(); + if !emitted_warnings.contains(op_name) { + // First time we are seeing this. + emitted_warnings.insert(op_name.to_owned()); + this.tcx + .dcx() + .warn(format!("{op_name} was made to return an error due to isolation")); + } Ok(()) } RejectOpWith::Warning => {