diff --git a/src/tools/miri/ci.sh b/src/tools/miri/ci.sh index ef52a37fe319..b5b3b211b05f 100755 --- a/src/tools/miri/ci.sh +++ b/src/tools/miri/ci.sh @@ -43,7 +43,9 @@ function run_tests { # optimizations up all the way, too). # Optimizations change diagnostics (mostly backtraces), so we don't check # them. Also error locations change so we don't run the failing tests. - MIRIFLAGS="${MIRIFLAGS:-} -O -Zmir-opt-level=4" MIRI_SKIP_UI_CHECKS=1 ./miri test -- tests/{pass,panic} + # We explicitly enable debug-assertions here, they are disabled by -O but we have tests + # which exist to check that we panic on debug assertion failures. + MIRIFLAGS="${MIRIFLAGS:-} -O -Zmir-opt-level=4 -Cdebug-assertions=yes" MIRI_SKIP_UI_CHECKS=1 ./miri test -- tests/{pass,panic} # Also run some many-seeds tests. 64 seeds means this takes around a minute per test. for FILE in tests/many-seeds/*.rs; do diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 6fe3fa7fb1b6..0a23b355ce5f 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -30,6 +30,8 @@ use rustc_middle::{ }, ty::{query::ExternProviders, TyCtxt}, }; +use rustc_session::config::OptLevel; + use rustc_session::{config::CrateType, search_paths::PathKind, CtfeBacktrace}; use miri::{BacktraceStyle, BorrowTrackerMethod, ProvenanceMode, RetagFields}; @@ -82,6 +84,21 @@ impl rustc_driver::Callbacks for MiriCompilerCalls { env::set_current_dir(cwd).unwrap(); } + if tcx.sess.opts.optimize != OptLevel::No { + tcx.sess.warn("Miri does not support optimizations. If you have enabled optimizations \ + by selecting a Cargo profile (such as --release) which changes other profile settings \ + such as whether debug assertions and overflow checks are enabled, those settings are \ + still applied."); + } + if tcx.sess.mir_opt_level() > 0 { + tcx.sess.warn("You have explicitly enabled MIR optimizations, overriding Miri's default \ + which is to completely disable them. Any optimizations may hide UB that Miri would \ + otherwise detect, and it is not necessarily possible to predict what kind of UB will \ + be missed. If you are enabling optimizations to make Miri run faster, we advise using \ + cfg(miri) to shrink your workload instead. The impact of enabling MIR optimizations is \ + usually marginal at best."); + } + if let Some(return_code) = miri::eval_entry(tcx, entry_def_id, entry_type, config) { std::process::exit( i32::try_from(return_code).expect("Return value was too large!"), diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 01d0f01d319d..feb3f9c10a3c 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -130,6 +130,5 @@ pub const MIRI_DEFAULT_ARGS: &[&str] = &[ "-Zmir-emit-retag", "-Zmir-opt-level=0", "--cfg=miri", - "-Cdebug-assertions=on", "-Zextra-const-ub-checks", ];