Skip to content

Commit 093b9d5

Browse files
committed
Auto merge of #116533 - cjgillot:skip-trivial-mir, r=oli-obk
Do not run optimizations on trivial MIR. Fixes #116513 The bug was introduced in #110728, which put the check too early in the query chain. cc `@oli-obk` `@ouz-a`
2 parents 1f48cbc + 005ec2e commit 093b9d5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

compiler/rustc_mir_transform/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,15 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
613613
return body;
614614
}
615615

616+
// If `mir_drops_elaborated_and_const_checked` found that the current body has unsatisfiable
617+
// predicates, it will shrink the MIR to a single `unreachable` terminator.
618+
// More generally, if MIR is a lone `unreachable`, there is nothing to optimize.
619+
if let TerminatorKind::Unreachable = body.basic_blocks[START_BLOCK].terminator().kind
620+
&& body.basic_blocks[START_BLOCK].statements.is_empty()
621+
{
622+
return body;
623+
}
624+
616625
run_optimization_passes(tcx, &mut body);
617626

618627
body

tests/ui/consts/issue-67696-const-prop-ice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: --emit=mir,link
2+
// compile-flags: --emit=mir,link -Zmir-opt-level=4
33
// Checks that we don't ICE due to attempting to run const prop
44
// on a function with unsatisifable 'where' clauses
55

0 commit comments

Comments
 (0)