bring back extra check for int_min%-1
This commit is contained in:
parent
202d401c25
commit
28f85c6ffa
1 changed files with 11 additions and 0 deletions
|
@ -195,6 +195,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
if let Some(op) = op {
|
||||
let l128 = self.sign_extend(l, left_layout) as i128;
|
||||
let r = self.sign_extend(r, right_layout) as i128;
|
||||
// We need a special check for overflowing remainder:
|
||||
// "int_min % -1" overflows and returns 0, but after casting things to a larger int
|
||||
// type it does *not* overflow nor give an unrepresentable result!
|
||||
match bin_op {
|
||||
Rem => {
|
||||
if r == -1 && l == (1 << (size.bits() - 1)) {
|
||||
return Ok((Scalar::from_int(0, size), true, left_layout.ty));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let (result, oflo) = op(l128, r);
|
||||
// This may be out-of-bounds for the result type, so we have to truncate ourselves.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue