Skip to content

Commit

Permalink
Auto merge of rust-lang#116533 - cjgillot:skip-trivial-mir, r=oli-obk
Browse files Browse the repository at this point in the history
Do not run optimizations on trivial MIR.

Fixes rust-lang#116513

The bug was introduced in rust-lang#110728, which put the check too early in the query chain.

cc `@oli-obk` `@ouz-a`
  • Loading branch information
bors committed Oct 9, 2023
2 parents 1f48cbc + 005ec2e commit 093b9d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,15 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
return body;
}

// If `mir_drops_elaborated_and_const_checked` found that the current body has unsatisfiable
// predicates, it will shrink the MIR to a single `unreachable` terminator.
// More generally, if MIR is a lone `unreachable`, there is nothing to optimize.
if let TerminatorKind::Unreachable = body.basic_blocks[START_BLOCK].terminator().kind
&& body.basic_blocks[START_BLOCK].statements.is_empty()
{
return body;
}

run_optimization_passes(tcx, &mut body);

body
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/issue-67696-const-prop-ice.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: --emit=mir,link
// compile-flags: --emit=mir,link -Zmir-opt-level=4
// Checks that we don't ICE due to attempting to run const prop
// on a function with unsatisifable 'where' clauses

Expand Down

0 comments on commit 093b9d5

Please sign in to comment.