From 9e236592f9c78204b44aea14c54857bda12d6613 Mon Sep 17 00:00:00 2001 From: Ehud Katz Date: Tue, 7 Jan 2020 11:24:11 +0200 Subject: [PATCH] [APFloat] Fix out of scope usage of a pointer to local variable --- lib/Support/APFloat.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp index 723bbbc176b..f8a217d3535 100644 --- a/lib/Support/APFloat.cpp +++ b/lib/Support/APFloat.cpp @@ -1065,18 +1065,22 @@ lostFraction IEEEFloat::multiplySignificand(const IEEEFloat &rhs, significand.parts = fullSignificand; semantics = &extendedSemantics; - status = addend.convert(extendedSemantics, rmTowardZero, &ignored); + // Make a copy so we can convert it to the extended semantics. + // Note that we cannot convert the addend directly, as the extendedSemantics + // is a local variable (which we take a reference to). + IEEEFloat extendedAddend(addend); + status = extendedAddend.convert(extendedSemantics, rmTowardZero, &ignored); assert(status == opOK); (void)status; // Shift the significand of the addend right by one bit. This guarantees // that the high bit of the significand is zero (same as fullSignificand), // so the addition will overflow (if it does overflow at all) into the top bit. - lost_fraction = addend.shiftSignificandRight(1); + lost_fraction = extendedAddend.shiftSignificandRight(1); assert(lost_fraction == lfExactlyZero && "Lost precision while shifting addend for fused-multiply-add."); - lost_fraction = addOrSubtractSignificand(addend, false); + lost_fraction = addOrSubtractSignificand(extendedAddend, false); /* Restore our state. */ if (newPartsCount == 1)