[llvm] 63a222e - [APFloat] Fix out of scope usage of a pointer to local variable

Ehud Katz via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 01:24:40 PST 2020


Author: Ehud Katz
Date: 2020-01-07T11:24:18+02:00
New Revision: 63a222e504c2f6f1e4f60f8d2acfb5870cac9c66

URL: https://github.com/llvm/llvm-project/commit/63a222e504c2f6f1e4f60f8d2acfb5870cac9c66
DIFF: https://github.com/llvm/llvm-project/commit/63a222e504c2f6f1e4f60f8d2acfb5870cac9c66.diff

LOG: [APFloat] Fix out of scope usage of a pointer to local variable

Added: 
    

Modified: 
    llvm/lib/Support/APFloat.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 723bbbc176b3..f8a217d3535d 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/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)


        


More information about the llvm-commits mailing list