Skip to content

Commit 18997b5

Browse files
[ADT] Fix a bug in DoubleAPFloat::frexp (#161625)
Without this patch, we call APFloat::makeQuiet() in frexp like so: Quiet.getFirst().makeQuiet(); The problem is that makeQuiet returns a new value instead of modifying "*this" in place, so we end up discarding the newly returned value. This patch fixes the problem by assigning the result back to Quiet.getFirst(). We should put [[nodiscard]] on APFloat::makeQuiet, but I'll do that in another patch.
1 parent c2ef022 commit 18997b5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

llvm/lib/Support/APFloat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5857,7 +5857,7 @@ DoubleAPFloat frexp(const DoubleAPFloat &Arg, int &Exp,
58575857
// practice.
58585858
if (Exp == APFloat::IEK_NaN) {
58595859
DoubleAPFloat Quiet{Arg};
5860-
Quiet.getFirst().makeQuiet();
5860+
Quiet.getFirst() = Quiet.getFirst().makeQuiet();
58615861
return Quiet;
58625862
}
58635863

llvm/unittests/ADT/APFloatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10176,4 +10176,11 @@ TEST(APFloatTest, hasSignBitInMSB) {
1017610176
EXPECT_FALSE(APFloat::hasSignBitInMSB(APFloat::Float8E8M0FNU()));
1017710177
}
1017810178

10179+
TEST(APFloatTest, FrexpQuietSNaN) {
10180+
APFloat SNaN = APFloat::getSNaN(APFloat::PPCDoubleDouble());
10181+
int Exp;
10182+
APFloat Result = frexp(SNaN, Exp, APFloat::rmNearestTiesToEven);
10183+
EXPECT_FALSE(Result.isSignaling());
10184+
}
10185+
1017910186
} // namespace

0 commit comments

Comments
 (0)