Skip to content

Commit b8fed2f

Browse files
committed
Make dataflow const-prop handle_switch_int monotonic.
1 parent e9990ce commit b8fed2f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,17 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
257257
ValueOrPlace::Value(value) => value,
258258
ValueOrPlace::Place(place) => state.get_idx(place, self.map()),
259259
};
260-
let FlatSet::Elem(ScalarTy(scalar, _)) = value else {
261-
// Do nothing if we don't know which branch will be taken.
262-
return TerminatorEdges::SwitchInt { discr, targets };
263-
};
264-
265-
let int = scalar.assert_int();
266-
let choice = int.assert_bits(int.size());
267-
TerminatorEdges::Single(targets.target_for_value(choice))
260+
match value {
261+
// We are branching on uninitialized data, this is UB, treat it as unreachable.
262+
// This allows the set of visited edges to grow monotonically with the lattice.
263+
FlatSet::Bottom => TerminatorEdges::None,
264+
FlatSet::Elem(ScalarTy(scalar, _)) => {
265+
let int = scalar.assert_int();
266+
let choice = int.assert_bits(int.size());
267+
TerminatorEdges::Single(targets.target_for_value(choice))
268+
}
269+
FlatSet::Top => TerminatorEdges::SwitchInt { discr, targets },
270+
}
268271
}
269272
}
270273

0 commit comments

Comments
 (0)