Skip to content

Commit 38f5151

Browse files
authored
Rollup merge of #74102 - oli-obk:const_prop_icde, r=wesleywiser
Fix const prop ICE we used to erase the local just before we tried to read it for diagnostics fixes #73993 r? @wesleywiser
2 parents 50e22bd + ee8dd4e commit 38f5151

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/librustc_mir/transform/const_prop.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -1004,14 +1004,6 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
10041004
let expected = ScalarMaybeUninit::from(Scalar::from_bool(*expected));
10051005
let value_const = self.ecx.read_scalar(value).unwrap();
10061006
if expected != value_const {
1007-
// Poison all places this operand references so that further code
1008-
// doesn't use the invalid value
1009-
match cond {
1010-
Operand::Move(ref place) | Operand::Copy(ref place) => {
1011-
Self::remove_const(&mut self.ecx, place.local);
1012-
}
1013-
Operand::Constant(_) => {}
1014-
}
10151007
let mut eval_to_int = |op| {
10161008
let op = self
10171009
.eval_operand(op, source_info)
@@ -1020,27 +1012,37 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
10201012
};
10211013
let msg = match msg {
10221014
AssertKind::DivisionByZero(op) => {
1023-
AssertKind::DivisionByZero(eval_to_int(op))
1015+
Some(AssertKind::DivisionByZero(eval_to_int(op)))
10241016
}
10251017
AssertKind::RemainderByZero(op) => {
1026-
AssertKind::RemainderByZero(eval_to_int(op))
1018+
Some(AssertKind::RemainderByZero(eval_to_int(op)))
10271019
}
10281020
AssertKind::BoundsCheck { ref len, ref index } => {
10291021
let len = eval_to_int(len);
10301022
let index = eval_to_int(index);
1031-
AssertKind::BoundsCheck { len, index }
1023+
Some(AssertKind::BoundsCheck { len, index })
10321024
}
10331025
// Overflow is are already covered by checks on the binary operators.
1034-
AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => return,
1026+
AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => None,
10351027
// Need proper const propagator for these.
1036-
_ => return,
1028+
_ => None,
10371029
};
1038-
self.report_assert_as_lint(
1039-
lint::builtin::UNCONDITIONAL_PANIC,
1040-
source_info,
1041-
"this operation will panic at runtime",
1042-
msg,
1043-
);
1030+
// Poison all places this operand references so that further code
1031+
// doesn't use the invalid value
1032+
match cond {
1033+
Operand::Move(ref place) | Operand::Copy(ref place) => {
1034+
Self::remove_const(&mut self.ecx, place.local);
1035+
}
1036+
Operand::Constant(_) => {}
1037+
}
1038+
if let Some(msg) = msg {
1039+
self.report_assert_as_lint(
1040+
lint::builtin::UNCONDITIONAL_PANIC,
1041+
source_info,
1042+
"this operation will panic at runtime",
1043+
msg,
1044+
);
1045+
}
10441046
} else {
10451047
if self.should_const_prop(value) {
10461048
if let ScalarMaybeUninit::Scalar(scalar) = value_const {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
3+
pub struct Fixed64(i64);
4+
5+
pub fn div(f: Fixed64) {
6+
f.0 / 0;
7+
}
8+
9+
fn main() {}

0 commit comments

Comments
 (0)