Skip to content

Commit 7567f1f

Browse files
committed
Adapt interpreter.
1 parent 1480b1c commit 7567f1f

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,16 +569,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
569569
// checked operation, just a comparison with the minimum
570570
// value, so we have to check for the assert message.
571571
if !bx.cx().check_overflow() {
572-
if let AssertKind::OverflowNeg(_)
573-
| AssertKind::Overflow(
574-
mir::BinOp::Add
575-
| mir::BinOp::Sub
576-
| mir::BinOp::Mul
577-
| mir::BinOp::Shl
578-
| mir::BinOp::Shr,
579-
..,
580-
) = *msg
581-
{
572+
let unchecked_overflow = match msg {
573+
AssertKind::OverflowNeg(..) => true,
574+
AssertKind::Overflow(op, ..) => op.is_checkable(),
575+
_ => false,
576+
};
577+
if unchecked_overflow {
582578
const_cond = Some(expected);
583579
}
584580
}

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
137137
}
138138

139139
Assert { ref cond, expected, ref msg, target, cleanup } => {
140+
let ignored = !self.tcx.sess.overflow_checks()
141+
&& match msg {
142+
mir::AssertKind::OverflowNeg(..) => true,
143+
mir::AssertKind::Overflow(op, ..) => op.is_checkable(),
144+
_ => false,
145+
};
140146
let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?;
141-
if expected == cond_val {
147+
if ignored || expected == cond_val {
142148
self.go_to_block(target);
143149
} else {
144150
M::assert_panic(self, msg, cleanup)?;

0 commit comments

Comments
 (0)