Skip to content

Commit 16f34f2

Browse files
committed
Emit a warning when Miri is used with optimizations
1 parent f115296 commit 16f34f2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/bin/miri.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use rustc_middle::{
3030
},
3131
ty::{query::ExternProviders, TyCtxt},
3232
};
33+
use rustc_session::config::OptLevel;
34+
3335
use rustc_session::{config::CrateType, search_paths::PathKind, CtfeBacktrace};
3436

3537
use miri::{BacktraceStyle, ProvenanceMode, RetagFields};
@@ -82,6 +84,15 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
8284
env::set_current_dir(cwd).unwrap();
8385
}
8486

87+
if tcx.sess.opts.optimize != OptLevel::No {
88+
tcx.sess.warn("Miri does not support optimizations.");
89+
} else if tcx.sess.mir_opt_level() > 0 {
90+
tcx.sess.warn("You have explicitly enabled MIR optimizations, overriding Miri's default \
91+
which is to completely disable them. Any optimizations may hide UB that Miri would \
92+
otherwise detect, and it is not necessarily possible to predict what kind of UB will \
93+
be missed.");
94+
}
95+
8596
if let Some(return_code) = miri::eval_entry(tcx, entry_def_id, entry_type, config) {
8697
std::process::exit(
8798
i32::try_from(return_code).expect("Return value was too large!"),

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,5 @@ pub const MIRI_DEFAULT_ARGS: &[&str] = &[
129129
"-Zmir-emit-retag",
130130
"-Zmir-opt-level=0",
131131
"--cfg=miri",
132-
"-Cdebug-assertions=on",
133132
"-Zextra-const-ub-checks",
134133
];

0 commit comments

Comments
 (0)