Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix const prop ICE #74102

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,14 +1004,6 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
let expected = ScalarMaybeUninit::from(Scalar::from_bool(*expected));
let value_const = self.ecx.read_scalar(value).unwrap();
if expected != value_const {
// Poison all places this operand references so that further code
// doesn't use the invalid value
match cond {
Operand::Move(ref place) | Operand::Copy(ref place) => {
Self::remove_const(&mut self.ecx, place.local);
}
Operand::Constant(_) => {}
}
let mut eval_to_int = |op| {
let op = self
.eval_operand(op, source_info)
Expand All @@ -1020,27 +1012,37 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
};
let msg = match msg {
AssertKind::DivisionByZero(op) => {
AssertKind::DivisionByZero(eval_to_int(op))
Some(AssertKind::DivisionByZero(eval_to_int(op)))
}
AssertKind::RemainderByZero(op) => {
AssertKind::RemainderByZero(eval_to_int(op))
Some(AssertKind::RemainderByZero(eval_to_int(op)))
}
AssertKind::BoundsCheck { ref len, ref index } => {
let len = eval_to_int(len);
let index = eval_to_int(index);
AssertKind::BoundsCheck { len, index }
Some(AssertKind::BoundsCheck { len, index })
}
// Overflow is are already covered by checks on the binary operators.
AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => return,
AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => None,
// Need proper const propagator for these.
_ => return,
_ => None,
};
self.report_assert_as_lint(
lint::builtin::UNCONDITIONAL_PANIC,
source_info,
"this operation will panic at runtime",
msg,
);
// Poison all places this operand references so that further code
// doesn't use the invalid value
match cond {
Operand::Move(ref place) | Operand::Copy(ref place) => {
Self::remove_const(&mut self.ecx, place.local);
}
Operand::Constant(_) => {}
}
if let Some(msg) = msg {
self.report_assert_as_lint(
lint::builtin::UNCONDITIONAL_PANIC,
source_info,
"this operation will panic at runtime",
msg,
);
}
} else {
if self.should_const_prop(value) {
if let ScalarMaybeUninit::Scalar(scalar) = value_const {
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// check-pass

pub struct Fixed64(i64);

pub fn div(f: Fixed64) {
f.0 / 0;
}

fn main() {}