1
Fork 0

Move unsigned_max etc into Size again

This commit is contained in:
Andreas Liljeqvist 2021-09-06 20:11:29 +02:00
parent 459c9108e4
commit 9129f4306f
6 changed files with 37 additions and 37 deletions

View file

@ -234,7 +234,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
&r,
)?;
let val = if overflowed {
let num_bits = l.layout.size.bits();
let size = l.layout.size;
let num_bits = size.bits();
if l.layout.abi.is_signed() {
// For signed ints the saturated value depends on the sign of the first
// term since the sign of the second term can be inferred from this and
@ -259,10 +260,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// unsigned
if is_add {
// max unsigned
Scalar::from_uint(
u128::MAX >> (128 - num_bits),
Size::from_bits(num_bits),
)
Scalar::from_uint(size.unsigned_max(), Size::from_bits(num_bits))
} else {
// underflow to 0
Scalar::from_uint(0u128, Size::from_bits(num_bits))

View file

@ -627,7 +627,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
// At least one value is excluded.
let valid_range = scalar_layout.valid_range;
let WrappingRange { start, end } = valid_range;
let max_value = u128::MAX >> (128 - op.layout.size.bits());
let max_value = op.layout.size.unsigned_max();
assert!(end <= max_value);
// Determine the allowed range
let value = self.read_scalar(op)?;