dataflow_const_prop: do not eval a ptr address in SwitchInt
This commit is contained in:
parent
1b3fb31675
commit
d0986f45e0
3 changed files with 26 additions and 18 deletions
|
@ -534,8 +534,13 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
|
||||||
// This allows the set of visited edges to grow monotonically with the lattice.
|
// This allows the set of visited edges to grow monotonically with the lattice.
|
||||||
FlatSet::Bottom => TerminatorEdges::None,
|
FlatSet::Bottom => TerminatorEdges::None,
|
||||||
FlatSet::Elem(scalar) => {
|
FlatSet::Elem(scalar) => {
|
||||||
let choice = scalar.assert_scalar_int().to_bits_unchecked();
|
if let Ok(scalar_int) = scalar.try_to_scalar_int() {
|
||||||
TerminatorEdges::Single(targets.target_for_value(choice))
|
TerminatorEdges::Single(
|
||||||
|
targets.target_for_value(scalar_int.to_bits_unchecked()),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
TerminatorEdges::SwitchInt { discr, targets }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FlatSet::Top => TerminatorEdges::SwitchInt { discr, targets },
|
FlatSet::Top => TerminatorEdges::SwitchInt { discr, targets },
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
//@ known-bug: #131227
|
|
||||||
//@ compile-flags: -Zmir-opt-level=3
|
|
||||||
|
|
||||||
static mut G: () = ();
|
|
||||||
|
|
||||||
fn myfunc() -> i32 {
|
|
||||||
let var = &raw mut G;
|
|
||||||
if var.is_null() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
myfunc();
|
|
||||||
}
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
//! Issue: <https://github.com/rust-lang/rust/issues/131227>
|
||||||
|
//! Test that constant propagation in SwitchInt does not crash
|
||||||
|
//! when encountering a ptr-to-int transmute.
|
||||||
|
|
||||||
|
//@ check-pass
|
||||||
|
//@ compile-flags: -Zmir-enable-passes=+InstSimplify-before-inline,+DataflowConstProp
|
||||||
|
|
||||||
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
static mut G: i32 = 0;
|
||||||
|
|
||||||
|
pub fn myfunc() -> i32 {
|
||||||
|
let var = &raw mut G;
|
||||||
|
let u: usize = unsafe { std::mem::transmute(var) };
|
||||||
|
match u {
|
||||||
|
0 => 0,
|
||||||
|
_ => 1,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue