[libc-commits] [libc] [libc] Fix undefined behavior in BitsFxTest.h (PR #152347)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed Aug 6 10:50:11 PDT 2025


================
@@ -63,9 +63,11 @@ class BitsFxTest : public LIBC_NAMESPACE::testing::Test {
       if constexpr (FXRep::SIGN_LEN > 0) {
         if (min <= -11 && FXRep::FRACTION_LEN >= kMinFbits) {
           // (-10.71875)_10 = (-1010.1011100)_2
-          constexpr long long kExpected = -1372;
-          EXPECT_EQ(static_cast<XType>(kExpected
-                                       << (FXRep::FRACTION_LEN - kMinFbits)),
+          constexpr long long kExpected =
+              static_cast<long long>(static_cast<unsigned long long>(-1372)
----------------
michaelrj-google wrote:

are these intended to be specifically 64 bits? If so it might be best to use `uint64_t` and `int64_t` instead of `unsigned long long` and `long long`

https://github.com/llvm/llvm-project/pull/152347


More information about the libc-commits mailing list