diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 8b55eb4c099..c5ddcb597cb 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1025,6 +1025,8 @@ fn parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) -> "the directory the MIR is dumped into"), dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED], "if set, exclude the pass number when dumping MIR (used in tests)"), + mir_emit_validate: bool = (false, parse_bool, [TRACKED], + "emit Validate MIR statements, interpreted e.g. by miri"), perf_stats: bool = (false, parse_bool, [UNTRACKED], "print some performance-related statistics"), hir_stats: bool = (false, parse_bool, [UNTRACKED], diff --git a/src/librustc_mir/transform/add_validation.rs b/src/librustc_mir/transform/add_validation.rs index 005d793cd8b..e400683e8b4 100644 --- a/src/librustc_mir/transform/add_validation.rs +++ b/src/librustc_mir/transform/add_validation.rs @@ -85,6 +85,10 @@ fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _: MirSource, mir: &mut Mir<'tcx>) { + if !tcx.sess.opts.debugging_opts.mir_emit_validate { + return; + } + let local_decls = mir.local_decls.clone(); // TODO: Find a way to get rid of this clone. /// Convert an lvalue to a validation operand. diff --git a/src/librustc_mir/transform/erase_regions.rs b/src/librustc_mir/transform/erase_regions.rs index 12b1c549ffe..05376ff3d52 100644 --- a/src/librustc_mir/transform/erase_regions.rs +++ b/src/librustc_mir/transform/erase_regions.rs @@ -77,6 +77,12 @@ fn visit_statement(&mut self, block: BasicBlock, statement: &mut Statement<'tcx>, location: Location) { + if !self.tcx.sess.opts.debugging_opts.mir_emit_validate { + if let StatementKind::EndRegion(_) = statement.kind { + statement.kind = StatementKind::Nop; + } + } + self.in_validation_statement = match statement.kind { StatementKind::Validate(..) => true, _ => false,