about summary refs log tree commit diff
path: root/src/base.rs
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-04-11 10:42:48 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-04-11 10:42:48 +0000
commite243f8d0e3af98e3689e7e38b6ac0a83100d000f (patch)
treea1f5b3807fce2fdc9f01f4cb8f21403d68607834 /src/base.rs
parentda09eadbabb4a76304fa6af01a6bdea9b4ede446 (diff)
Merge commit '89f54caacf90e99fc8ba0d60a28bdadea3cfdf1e' into sync_cg_clif-2024-04-11
Diffstat (limited to 'src/base.rs')
-rw-r--r--src/base.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/base.rs b/src/base.rs
index 771e5b21958..f07421431da 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -267,10 +267,19 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
         .generic_activity("codegen prelude")
         .run(|| crate::abi::codegen_fn_prelude(fx, start_block));
 
-    for (bb, bb_data) in traversal::mono_reachable(fx.mir, fx.tcx, fx.instance) {
+    let reachable_blocks = traversal::mono_reachable_as_bitset(fx.mir, fx.tcx, fx.instance);
+
+    for (bb, bb_data) in fx.mir.basic_blocks.iter_enumerated() {
         let block = fx.get_block(bb);
         fx.bcx.switch_to_block(block);
 
+        if !reachable_blocks.contains(bb) {
+            // We want to skip this block, because it's not reachable. But we still create
+            // the block so terminators in other blocks can reference it.
+            fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
+            continue;
+        }
+
         if bb_data.is_cleanup {
             // Unwinding after panicking is not supported
             continue;