about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-05-29 10:29:54 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2023-08-16 18:12:18 +0000
commitb8fed2f21c505ed73e238c4c47fdad6d47283475 (patch)
tree7bd7102a494312615e1962927f11bc8c07b358c1
parente9990ce89ca62e9c9b62bcde89eb11314ec1dc22 (diff)
downloadrust-b8fed2f21c505ed73e238c4c47fdad6d47283475.tar.gz
rust-b8fed2f21c505ed73e238c4c47fdad6d47283475.zip
Make dataflow const-prop handle_switch_int monotonic.
-rw-r--r--compiler/rustc_mir_transform/src/dataflow_const_prop.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs
index 60501165176..8f4dc9f69e9 100644
--- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs
+++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs
@@ -257,14 +257,17 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
             ValueOrPlace::Value(value) => value,
             ValueOrPlace::Place(place) => state.get_idx(place, self.map()),
         };
-        let FlatSet::Elem(ScalarTy(scalar, _)) = value else {
-            // Do nothing if we don't know which branch will be taken.
-            return TerminatorEdges::SwitchInt { discr, targets };
-        };
-
-        let int = scalar.assert_int();
-        let choice = int.assert_bits(int.size());
-        TerminatorEdges::Single(targets.target_for_value(choice))
+        match value {
+            // We are branching on uninitialized data, this is UB, treat it as unreachable.
+            // This allows the set of visited edges to grow monotonically with the lattice.
+            FlatSet::Bottom => TerminatorEdges::None,
+            FlatSet::Elem(ScalarTy(scalar, _)) => {
+                let int = scalar.assert_int();
+                let choice = int.assert_bits(int.size());
+                TerminatorEdges::Single(targets.target_for_value(choice))
+            }
+            FlatSet::Top => TerminatorEdges::SwitchInt { discr, targets },
+        }
     }
 }