Skip to content

Commit a3301f0

Browse files
authored
Unrolled build for rust-lang#134073
Rollup merge of rust-lang#134073 - DianQK:fix-131227, r=oli-obk dataflow_const_prop: do not eval a ptr address in SwitchInt Fixes rust-lang#131227.
2 parents 974ccc1 + d0986f4 commit a3301f0

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,13 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
534534
// This allows the set of visited edges to grow monotonically with the lattice.
535535
FlatSet::Bottom => TerminatorEdges::None,
536536
FlatSet::Elem(scalar) => {
537-
let choice = scalar.assert_scalar_int().to_bits_unchecked();
538-
TerminatorEdges::Single(targets.target_for_value(choice))
537+
if let Ok(scalar_int) = scalar.try_to_scalar_int() {
538+
TerminatorEdges::Single(
539+
targets.target_for_value(scalar_int.to_bits_unchecked()),
540+
)
541+
} else {
542+
TerminatorEdges::SwitchInt { discr, targets }
543+
}
539544
}
540545
FlatSet::Top => TerminatorEdges::SwitchInt { discr, targets },
541546
}

tests/crashes/131227.rs

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Issue: <https://github.com/rust-lang/rust/issues/131227>
2+
//! Test that constant propagation in SwitchInt does not crash
3+
//! when encountering a ptr-to-int transmute.
4+
5+
//@ check-pass
6+
//@ compile-flags: -Zmir-enable-passes=+InstSimplify-before-inline,+DataflowConstProp
7+
8+
#![crate_type = "lib"]
9+
10+
static mut G: i32 = 0;
11+
12+
pub fn myfunc() -> i32 {
13+
let var = &raw mut G;
14+
let u: usize = unsafe { std::mem::transmute(var) };
15+
match u {
16+
0 => 0,
17+
_ => 1,
18+
}
19+
}

0 commit comments

Comments
 (0)