Skip to content

Commit ac84498

Browse files
committed
use singed_int_max/min helper methods
1 parent 956659e commit ac84498

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -493,23 +493,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
493493
// Negative overflow not possible since the positive first term
494494
// can only increase an (in range) negative term for addition
495495
// or corresponding negated positive term for subtraction
496-
Scalar::from_uint(
497-
(1u128 << (num_bits - 1)) - 1, // max positive
498-
Size::from_bits(num_bits),
499-
)
496+
Scalar::from_int(size.signed_int_max(), size)
500497
} else {
501498
// Positive overflow not possible for similar reason
502499
// max negative
503-
Scalar::from_uint(1u128 << (num_bits - 1), Size::from_bits(num_bits))
500+
Scalar::from_int(size.signed_int_min(), size)
504501
}
505502
} else {
506503
// unsigned
507504
if matches!(mir_op, BinOp::Add) {
508505
// max unsigned
509-
Scalar::from_uint(size.unsigned_int_max(), Size::from_bits(num_bits))
506+
Scalar::from_uint(size.unsigned_int_max(), size)
510507
} else {
511508
// underflow to 0
512-
Scalar::from_uint(0u128, Size::from_bits(num_bits))
509+
Scalar::from_uint(0u128, size)
513510
}
514511
}
515512
} else {

0 commit comments

Comments
 (0)