Emit a warning when Miri is used with optimizations

This commit is contained in:
Ben Kimock 2023-03-12 19:27:34 -04:00
parent 3831a25490
commit 4c2d1be2a0
3 changed files with 20 additions and 2 deletions

View file

@ -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

View file

@ -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!"),

View file

@ -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",
];