@@ -5536,7 +5536,7 @@ APFloat::opStatus DoubleAPFloat::convertToSignExtendedInteger(
5536
5536
DoubleAPFloat Integral = *this ;
5537
5537
const opStatus RoundStatus = Integral.roundToIntegral (RM);
5538
5538
if (RoundStatus == opInvalidOp)
5539
- return RoundStatus ;
5539
+ return opInvalidOp ;
5540
5540
const APFloat &IntegralHi = Integral.getFirst ();
5541
5541
const APFloat &IntegralLo = Integral.getSecond ();
5542
5542
@@ -5548,7 +5548,7 @@ APFloat::opStatus DoubleAPFloat::convertToSignExtendedInteger(
5548
5548
IntegralHi.convertToInteger (Input, Width, IsSigned, RM, &HiIsExact);
5549
5549
// The conversion from an integer-valued float to an APInt may fail if the
5550
5550
// result would be out of range. Regardless, taking this path is only
5551
- // possible if rounding occured during the initial `roundToIntegral`.
5551
+ // possible if rounding occurred during the initial `roundToIntegral`.
5552
5552
return HiStatus == opOK ? opInexact : HiStatus;
5553
5553
}
5554
5554
@@ -5575,9 +5575,10 @@ APFloat::opStatus DoubleAPFloat::convertToSignExtendedInteger(
5575
5575
// If the signs differ, the sum will fit. We can compute the result using
5576
5576
// properties of two's complement arithmetic without a wide intermediate
5577
5577
// integer. E.g., for uint128_t, (2^128, -1) should be 2^128 - 1.
5578
- [[maybe_unused]] opStatus LoStatus = IntegralLo.convertToInteger (
5578
+ const opStatus LoStatus = IntegralLo.convertToInteger (
5579
5579
Input, Width, /* IsSigned=*/ true , RM, &LoIsExact);
5580
- assert (LoStatus == opOK && " Unexpected failure" );
5580
+ if (LoStatus == opInvalidOp)
5581
+ return opInvalidOp;
5581
5582
5582
5583
// Adjust the bit pattern of Lo to account for Hi's value:
5583
5584
// - For unsigned (Hi=2^Width): `2^Width + Lo` in `Width`-bit
@@ -5592,18 +5593,19 @@ APFloat::opStatus DoubleAPFloat::convertToSignExtendedInteger(
5592
5593
return RoundStatus;
5593
5594
}
5594
5595
5595
- // General case: Hi is not a power-of-two boundary, so we know it fits.
5596
- // Since we already rounded the full value, we now just need to convert the
5597
- // components to integers. The rounding mode should not matter.
5598
- [[maybe_unused]] opStatus HiStatus = IntegralHi.convertToInteger (
5596
+ // Convert Hi into an integer. This may not fit but that is OK: we know that
5597
+ // Hi + Lo would not fit either in this situation.
5598
+ const opStatus HiStatus = IntegralHi.convertToInteger (
5599
5599
Input, Width, IsSigned, rmTowardZero, &HiIsExact);
5600
- assert (HiStatus == opOK && " Unexpected failure" );
5600
+ if (HiStatus == opInvalidOp)
5601
+ return HiStatus;
5601
5602
5602
5603
// Convert Lo into a temporary integer of the same width.
5603
5604
APSInt LoResult{Width, /* isUnsigned=*/ !IsSigned};
5604
- [[maybe_unused]] opStatus LoStatus =
5605
+ const opStatus LoStatus =
5605
5606
IntegralLo.convertToInteger (LoResult, rmTowardZero, &LoIsExact);
5606
- assert (LoStatus == opOK && " Unexpected failure" );
5607
+ if (LoStatus == opInvalidOp)
5608
+ return LoStatus;
5607
5609
5608
5610
// Add Lo to Hi. This addition is guaranteed not to overflow because of the
5609
5611
// double-double canonicalization rule (`|Lo| <= ulp(Hi)/2`). The only case
0 commit comments