about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_mir/src/transform/add_call_guards.rs4
-rw-r--r--src/test/ui/codegen/issue-88043-bb-does-not-have-terminator.rs10
2 files changed, 13 insertions, 1 deletions
diff --git a/compiler/rustc_mir/src/transform/add_call_guards.rs b/compiler/rustc_mir/src/transform/add_call_guards.rs
index 1dddaeb89e6..12ee6bb4c67 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 1a6aadc662b..38dfca347c8 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<String>) -> Option<u32> {
+    loop {
+        g();
+        ()
+    }
+}
+
+fn g() -> Option<u32> { None }