about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-09-29 10:11:14 +0200
committerGitHub <noreply@github.com>2023-09-29 10:11:14 +0200
commit4f09f80bcf31bac53bd1abf106bdbea6ee39a29c (patch)
tree1a974483263eb32f9e8815f41402c83f70777506
parent1ed00fe491ae2ae55ee6db4d7eb61f3fee0e2d9c (diff)
parent3816c15b88651db3c1f1b56bbd78edec11045fb0 (diff)
downloadrust-4f09f80bcf31bac53bd1abf106bdbea6ee39a29c.tar.gz
rust-4f09f80bcf31bac53bd1abf106bdbea6ee39a29c.zip
Rollup merge of #116239 - cjgillot:issue-116212, r=WaffleLapkin
Only visit reachable nodes in SsaLocals.

Fixes https://github.com/rust-lang/rust/issues/116212
-rw-r--r--compiler/rustc_mir_transform/src/ssa.rs12
-rw-r--r--tests/mir-opt/ssa_unreachable_116212.rs14
2 files changed, 18 insertions, 8 deletions
diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs
index 3a675752fba..af9514ed6bb 100644
--- a/compiler/rustc_mir_transform/src/ssa.rs
+++ b/compiler/rustc_mir_transform/src/ssa.rs
@@ -78,14 +78,10 @@ impl SsaLocals {
             visitor.assignments[local] = Set1::One(LocationExtended::Arg);
         }
 
-        if body.basic_blocks.len() > 2 {
-            for (bb, data) in traversal::reverse_postorder(body) {
-                visitor.visit_basic_block_data(bb, data);
-            }
-        } else {
-            for (bb, data) in body.basic_blocks.iter_enumerated() {
-                visitor.visit_basic_block_data(bb, data);
-            }
+        // For SSA assignments, a RPO visit will see the assignment before it sees any use.
+        // We only visit reachable nodes: computing `dominates` on an unreachable node ICEs.
+        for (bb, data) in traversal::reverse_postorder(body) {
+            visitor.visit_basic_block_data(bb, data);
         }
 
         for var_debug_info in &body.var_debug_info {
diff --git a/tests/mir-opt/ssa_unreachable_116212.rs b/tests/mir-opt/ssa_unreachable_116212.rs
new file mode 100644
index 00000000000..f588665876c
--- /dev/null
+++ b/tests/mir-opt/ssa_unreachable_116212.rs
@@ -0,0 +1,14 @@
+// Regression test for issue #116212.
+
+#![feature(never_type)]
+
+use std::mem::MaybeUninit;
+
+struct Foo {
+    x: u8,
+    y: !,
+}
+
+fn main() {
+    let foo = unsafe { MaybeUninit::<Foo>::uninit().assume_init() };
+}