diff --git a/compiler/rustc_mir/src/transform/add_call_guards.rs b/compiler/rustc_mir/src/transform/add_call_guards.rs index 1dddaeb89e684..12ee6bb4c67fa 100644 --- a/compiler/rustc_mir/src/transform/add_call_guards.rs +++ b/compiler/rustc_mir/src/transform/add_call_guards.rs @@ -38,7 +38,9 @@ impl<'tcx> MirPass<'tcx> for AddCallGuards { impl AddCallGuards { pub fn add_call_guards(&self, body: &mut Body<'_>) { - let pred_count: IndexVec<_, _> = body.predecessors().iter().map(|ps| ps.len()).collect(); + let mut pred_count: IndexVec<_, _> = + body.predecessors().iter().map(|ps| ps.len()).collect(); + pred_count[START_BLOCK] += 1; // We need a place to store the new blocks generated let mut new_blocks = Vec::new(); diff --git a/src/test/ui/codegen/issue-88043-bb-does-not-have-terminator.rs b/src/test/ui/codegen/issue-88043-bb-does-not-have-terminator.rs index 1a6aadc662bbd..38dfca347c8cd 100644 --- a/src/test/ui/codegen/issue-88043-bb-does-not-have-terminator.rs +++ b/src/test/ui/codegen/issue-88043-bb-does-not-have-terminator.rs @@ -22,4 +22,14 @@ fn take_until(terminate: impl Fn() -> bool) { // CHECK-LABEL: @main fn main() { take_until(|| true); + f(None); } + +fn f(_a: Option) -> Option { + loop { + g(); + () + } +} + +fn g() -> Option { None }