From de2e16cf715572b19b0c980af2f834c1e9e0e958 Mon Sep 17 00:00:00 2001
From: 823984418 <823984418@qq.com>
Date: Sat, 4 Mar 2023 22:51:23 +0800
Subject: [PATCH 1/2] Prevent the `start_bx` basic block in codegen from having
 two `Builder`s at the same time

---
 compiler/rustc_codegen_ssa/src/mir/mod.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs
index 2ec9fdbf44f11..8db81b793eab6 100644
--- a/compiler/rustc_codegen_ssa/src/mir/mod.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs
@@ -258,6 +258,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
     // Apply debuginfo to the newly allocated locals.
     fx.debug_introduce_locals(&mut start_bx);
 
+    drop(start_bx);
+
     // Codegen the body of each block using reverse postorder
     for (bb, _) in traversal::reverse_postorder(&mir) {
         fx.codegen_block(bb);

From 871b4feba648981f7451d2c65c60771a2af19618 Mon Sep 17 00:00:00 2001
From: 823984418 <823984418@qq.com>
Date: Wed, 8 Mar 2023 11:19:12 +0800
Subject: [PATCH 2/2] Add a comment about drop(start_bx)

---
 compiler/rustc_codegen_ssa/src/mir/mod.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs
index 8db81b793eab6..5cffca5230a8f 100644
--- a/compiler/rustc_codegen_ssa/src/mir/mod.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs
@@ -258,6 +258,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
     // Apply debuginfo to the newly allocated locals.
     fx.debug_introduce_locals(&mut start_bx);
 
+    // The builders will be created separately for each basic block at `codegen_block`.
+    // So drop the builder of `start_llbb` to avoid having two at the same time.
     drop(start_bx);
 
     // Codegen the body of each block using reverse postorder