use singed_int_max/min helper methods
This commit is contained in:
parent
956659e5ce
commit
ac844986d8
1 changed files with 4 additions and 7 deletions
|
@ -493,23 +493,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
// Negative overflow not possible since the positive first term
|
// Negative overflow not possible since the positive first term
|
||||||
// can only increase an (in range) negative term for addition
|
// can only increase an (in range) negative term for addition
|
||||||
// or corresponding negated positive term for subtraction
|
// or corresponding negated positive term for subtraction
|
||||||
Scalar::from_uint(
|
Scalar::from_int(size.signed_int_max(), size)
|
||||||
(1u128 << (num_bits - 1)) - 1, // max positive
|
|
||||||
Size::from_bits(num_bits),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
// Positive overflow not possible for similar reason
|
// Positive overflow not possible for similar reason
|
||||||
// max negative
|
// max negative
|
||||||
Scalar::from_uint(1u128 << (num_bits - 1), Size::from_bits(num_bits))
|
Scalar::from_int(size.signed_int_min(), size)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// unsigned
|
// unsigned
|
||||||
if matches!(mir_op, BinOp::Add) {
|
if matches!(mir_op, BinOp::Add) {
|
||||||
// max unsigned
|
// max unsigned
|
||||||
Scalar::from_uint(size.unsigned_int_max(), Size::from_bits(num_bits))
|
Scalar::from_uint(size.unsigned_int_max(), size)
|
||||||
} else {
|
} else {
|
||||||
// underflow to 0
|
// underflow to 0
|
||||||
Scalar::from_uint(0u128, Size::from_bits(num_bits))
|
Scalar::from_uint(0u128, size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue