Skip to content

Commit 7a39460

Browse files
oli-obkRalfJung
authored andcommitted
Use the upstream exact_div implementation
1 parent d4e4fe7 commit 7a39460

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
@@ -313,23 +313,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
313313
this.write_scalar(Scalar::from_f64(res), dest)?;
314314
}
315315

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

334322
"forget" => {}
335323

0 commit comments

Comments
 (0)