From 7567f1f31d5e968380b1e1c5088b00a0606ea1a0 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 11 Feb 2023 16:41:37 +0000 Subject: [PATCH] Adapt interpreter. --- compiler/rustc_codegen_ssa/src/mir/block.rs | 16 ++++++---------- .../rustc_const_eval/src/interpret/terminator.rs | 8 +++++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index a7e74279a13..35f12ac9dbd 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -569,16 +569,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // checked operation, just a comparison with the minimum // value, so we have to check for the assert message. if !bx.cx().check_overflow() { - if let AssertKind::OverflowNeg(_) - | AssertKind::Overflow( - mir::BinOp::Add - | mir::BinOp::Sub - | mir::BinOp::Mul - | mir::BinOp::Shl - | mir::BinOp::Shr, - .., - ) = *msg - { + let unchecked_overflow = match msg { + AssertKind::OverflowNeg(..) => true, + AssertKind::Overflow(op, ..) => op.is_checkable(), + _ => false, + }; + if unchecked_overflow { const_cond = Some(expected); } } diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index da320cd1cd5..919eaca90ce 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -137,8 +137,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } Assert { ref cond, expected, ref msg, target, cleanup } => { + let ignored = !self.tcx.sess.overflow_checks() + && match msg { + mir::AssertKind::OverflowNeg(..) => true, + mir::AssertKind::Overflow(op, ..) => op.is_checkable(), + _ => false, + }; let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?; - if expected == cond_val { + if ignored || expected == cond_val { self.go_to_block(target); } else { M::assert_panic(self, msg, cleanup)?;