Skip to content

Commit 2152ca7

Browse files
committed
Use the upstream exact_div implementation
1 parent 2e17933 commit 2152ca7

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

src/shims/intrinsics.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -306,23 +306,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
306306
this.write_scalar(Scalar::from_f64(res), dest)?;
307307
}
308308

309-
"exact_div" => {
310-
// Performs an exact division, resulting in undefined behavior where
311-
// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
312-
let a = this.read_immediate(args[0])?;
313-
let b = this.read_immediate(args[1])?;
314-
// check x % y != 0
315-
if this.overflowing_binary_op(mir::BinOp::Rem, a, b)?.0.to_bits(dest.layout.size)? != 0 {
316-
// Check if `b` is -1, which is the "min_value / -1" case.
317-
let minus1 = Scalar::from_int(-1, dest.layout.size);
318-
return Err(if b.to_scalar().unwrap() == minus1 {
319-
err_ub_format!("exact_div: result of dividing MIN by -1 cannot be represented")
320-
} else {
321-
err_ub_format!("exact_div: {:?} cannot be divided by {:?} without remainder", *a, *b)
322-
}.into());
323-
}
324-
this.binop_ignore_overflow(mir::BinOp::Div, a, b, dest)?;
325-
},
309+
"exact_div" => this.exact_div(
310+
this.read_immediate(args[0])?,
311+
this.read_immediate(args[1])?,
312+
dest,
313+
)?,
326314

327315
"forget" => {}
328316

0 commit comments

Comments
 (0)