diff options
author | Sanjay Patel <spatel@rotateright.com> | 2020-09-24 13:44:29 -0400 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2020-09-24 14:02:19 -0400 |
commit | e34bd1e0b03d20a506ada156d87e1b3a96d82fa2 (patch) | |
tree | 5a0cc3e1cc40484c575b65c9a31382b4aa401cc3 /llvm/unittests/ADT/APFloatTest.cpp | |
parent | 03f22b08e2a387a415dcbb3cf021e41e629c3d34 (diff) | |
download | llvm-e34bd1e0b03d20a506ada156d87e1b3a96d82fa2.zip llvm-e34bd1e0b03d20a506ada156d87e1b3a96d82fa2.tar.gz llvm-e34bd1e0b03d20a506ada156d87e1b3a96d82fa2.tar.bz2 |
[APFloat] prevent NaN morphing into Inf on conversion (PR43907)
We shift the significand right on a truncation, but that needs to be made NaN-safe:
always set at least 1 bit in the significand.
https://llvm.org/PR43907
See D88238 for the likely follow-up (but needs some plumbing fixes before it can proceed).
Differential Revision: https://reviews.llvm.org/D87835
Diffstat (limited to 'llvm/unittests/ADT/APFloatTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/APFloatTest.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/unittests/ADT/APFloatTest.cpp b/llvm/unittests/ADT/APFloatTest.cpp index e3b4e5c..4cd027d 100644 --- a/llvm/unittests/ADT/APFloatTest.cpp +++ b/llvm/unittests/ADT/APFloatTest.cpp @@ -1841,14 +1841,15 @@ TEST(APFloatTest, convert) { EXPECT_TRUE(test.bitwiseIsEqual(X87QNaN)); EXPECT_FALSE(losesInfo); - // FIXME: This is wrong - NaN becomes Inf. + // The payload is lost in truncation, but we must retain NaN, so we set the bit after the quiet bit. APInt payload(52, 1); test = APFloat::getSNaN(APFloat::IEEEdouble(), false, &payload); status = test.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &losesInfo); - EXPECT_EQ(0x7f800000, test.bitcastToAPInt()); + EXPECT_EQ(0x7fa00000, test.bitcastToAPInt()); EXPECT_TRUE(losesInfo); EXPECT_EQ(status, APFloat::opOK); + // The payload is lost in truncation. QNaN remains QNaN. test = APFloat::getQNaN(APFloat::IEEEdouble(), false, &payload); status = test.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &losesInfo); EXPECT_EQ(0x7fc00000, test.bitcastToAPInt()); |