Propagate PlaceElem::Index.
This commit is contained in:
parent
8cc75b56a6
commit
a8988519d5
@ -806,6 +806,24 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn process_projection_elem(
|
||||||
|
&mut self,
|
||||||
|
elem: PlaceElem<'tcx>,
|
||||||
|
_: Location,
|
||||||
|
) -> Option<PlaceElem<'tcx>> {
|
||||||
|
if let PlaceElem::Index(local) = elem
|
||||||
|
&& let Some(value) = self.get_const(local.into())
|
||||||
|
&& self.should_const_prop(&value)
|
||||||
|
&& let interpret::Operand::Immediate(interpret::Immediate::Scalar(scalar)) = *value
|
||||||
|
&& let Ok(offset) = scalar.to_target_usize(&self.tcx)
|
||||||
|
&& let Some(min_length) = offset.checked_add(1)
|
||||||
|
{
|
||||||
|
Some(PlaceElem::ConstantIndex { offset, min_length, from_end: false })
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_assign(
|
fn visit_assign(
|
||||||
&mut self,
|
&mut self,
|
||||||
place: &mut Place<'tcx>,
|
place: &mut Place<'tcx>,
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
_5 = (*_1)[_6]; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:18: +3:25
|
- _5 = (*_1)[_6]; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:18: +3:25
|
||||||
|
+ _5 = (*_1)[3 of 4]; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:18: +3:25
|
||||||
StorageDead(_6); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:25: +3:26
|
StorageDead(_6); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:25: +3:26
|
||||||
_0 = const (); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+2:5: +4:6
|
_0 = const (); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+2:5: +4:6
|
||||||
StorageDead(_5); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+4:5: +4:6
|
StorageDead(_5); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+4:5: +4:6
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
_5 = (*_1)[_6]; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:18: +3:25
|
- _5 = (*_1)[_6]; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:18: +3:25
|
||||||
|
+ _5 = (*_1)[3 of 4]; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:18: +3:25
|
||||||
StorageDead(_6); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:25: +3:26
|
StorageDead(_6); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+3:25: +3:26
|
||||||
_0 = const (); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+2:5: +4:6
|
_0 = const (); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+2:5: +4:6
|
||||||
StorageDead(_5); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+4:5: +4:6
|
StorageDead(_5); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:+4:5: +4:6
|
||||||
|
@ -27,7 +27,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
_1 = _2[_3]; // scope 0 at $DIR/large_array_index.rs:+2:17: +2:32
|
- _1 = _2[_3]; // scope 0 at $DIR/large_array_index.rs:+2:17: +2:32
|
||||||
|
+ _1 = _2[2 of 3]; // scope 0 at $DIR/large_array_index.rs:+2:17: +2:32
|
||||||
StorageDead(_3); // scope 0 at $DIR/large_array_index.rs:+2:32: +2:33
|
StorageDead(_3); // scope 0 at $DIR/large_array_index.rs:+2:32: +2:33
|
||||||
StorageDead(_2); // scope 0 at $DIR/large_array_index.rs:+2:32: +2:33
|
StorageDead(_2); // scope 0 at $DIR/large_array_index.rs:+2:32: +2:33
|
||||||
_0 = const (); // scope 0 at $DIR/large_array_index.rs:+0:11: +3:2
|
_0 = const (); // scope 0 at $DIR/large_array_index.rs:+0:11: +3:2
|
||||||
|
@ -27,7 +27,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
_1 = _2[_3]; // scope 0 at $DIR/large_array_index.rs:+2:17: +2:32
|
- _1 = _2[_3]; // scope 0 at $DIR/large_array_index.rs:+2:17: +2:32
|
||||||
|
+ _1 = _2[2 of 3]; // scope 0 at $DIR/large_array_index.rs:+2:17: +2:32
|
||||||
StorageDead(_3); // scope 0 at $DIR/large_array_index.rs:+2:32: +2:33
|
StorageDead(_3); // scope 0 at $DIR/large_array_index.rs:+2:32: +2:33
|
||||||
StorageDead(_2); // scope 0 at $DIR/large_array_index.rs:+2:32: +2:33
|
StorageDead(_2); // scope 0 at $DIR/large_array_index.rs:+2:32: +2:33
|
||||||
_0 = const (); // scope 0 at $DIR/large_array_index.rs:+0:11: +3:2
|
_0 = const (); // scope 0 at $DIR/large_array_index.rs:+0:11: +3:2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user