about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2023-03-12 19:27:34 -0400
committerBen Kimock <kimockb@gmail.com>2023-03-17 18:29:12 -0400
commit4c2d1be2a06bb01e26666ac7e5efa6e6c88ca47f (patch)
tree716db3fe3375a404c98df9e21599cfcfa0e4e731
parent3831a254905873af4da996ab21c6f9f3d4050051 (diff)
downloadrust-4c2d1be2a06bb01e26666ac7e5efa6e6c88ca47f.tar.gz
rust-4c2d1be2a06bb01e26666ac7e5efa6e6c88ca47f.zip
Emit a warning when Miri is used with optimizations
-rwxr-xr-xsrc/tools/miri/ci.sh4
-rw-r--r--src/tools/miri/src/bin/miri.rs17
-rw-r--r--src/tools/miri/src/lib.rs1
3 files changed, 20 insertions, 2 deletions
diff --git a/src/tools/miri/ci.sh b/src/tools/miri/ci.sh
index ef52a37fe31..b5b3b211b05 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 6fe3fa7fb1b..0a23b355ce5 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 01d0f01d319..feb3f9c10a3 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",
 ];