@@ -30,6 +30,8 @@ use rustc_middle::{
30
30
} ,
31
31
ty:: { query:: ExternProviders , TyCtxt } ,
32
32
} ;
33
+ use rustc_session:: config:: OptLevel ;
34
+
33
35
use rustc_session:: { config:: CrateType , search_paths:: PathKind , CtfeBacktrace } ;
34
36
35
37
use miri:: { BacktraceStyle , BorrowTrackerMethod , ProvenanceMode , RetagFields } ;
@@ -82,6 +84,21 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
82
84
env:: set_current_dir ( cwd) . unwrap ( ) ;
83
85
}
84
86
87
+ if tcx. sess . opts . optimize != OptLevel :: No {
88
+ tcx. sess . warn ( "Miri does not support optimizations. If you have enabled optimizations \
89
+ by selecting a Cargo profile (such as --release) which changes other profile settings \
90
+ such as whether debug assertions and overflow checks are enabled, those settings are \
91
+ still applied.") ;
92
+ }
93
+ if tcx. sess . mir_opt_level ( ) > 0 {
94
+ tcx. sess . warn ( "You have explicitly enabled MIR optimizations, overriding Miri's default \
95
+ which is to completely disable them. Any optimizations may hide UB that Miri would \
96
+ otherwise detect, and it is not necessarily possible to predict what kind of UB will \
97
+ be missed. If you are enabling optimizations to make Miri run faster, we advise using \
98
+ cfg(miri) to shrink your workload instead. The impact of enabling MIR optimizations is \
99
+ usually marginal at best.") ;
100
+ }
101
+
85
102
if let Some ( return_code) = miri:: eval_entry ( tcx, entry_def_id, entry_type, config) {
86
103
std:: process:: exit (
87
104
i32:: try_from ( return_code) . expect ( "Return value was too large!" ) ,
0 commit comments