From 2152ca75a62a05319d8ecd2c38e9ba8169bd632a Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 25 Sep 2019 01:19:41 +0200 Subject: [PATCH] Use the upstream `exact_div` implementation --- src/shims/intrinsics.rs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index 06af6db76a..b63fb8d776 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -306,23 +306,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_scalar(Scalar::from_f64(res), dest)?; } - "exact_div" => { - // Performs an exact division, resulting in undefined behavior where - // `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1` - let a = this.read_immediate(args[0])?; - let b = this.read_immediate(args[1])?; - // check x % y != 0 - if this.overflowing_binary_op(mir::BinOp::Rem, a, b)?.0.to_bits(dest.layout.size)? != 0 { - // Check if `b` is -1, which is the "min_value / -1" case. - let minus1 = Scalar::from_int(-1, dest.layout.size); - return Err(if b.to_scalar().unwrap() == minus1 { - err_ub_format!("exact_div: result of dividing MIN by -1 cannot be represented") - } else { - err_ub_format!("exact_div: {:?} cannot be divided by {:?} without remainder", *a, *b) - }.into()); - } - this.binop_ignore_overflow(mir::BinOp::Div, a, b, dest)?; - }, + "exact_div" => this.exact_div( + this.read_immediate(args[0])?, + this.read_immediate(args[1])?, + dest, + )?, "forget" => {}