Skip to content

Commit 80cf436

Browse files
authored
[libc] Fix undefined behavior in BitsFxTest.h (#152347)
1 parent 3404c0b commit 80cf436

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

libc/test/src/stdfix/BitsFxTest.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BitsFxTest : public LIBC_NAMESPACE::testing::Test {
5454

5555
if (max >= 11 && FXRep::FRACTION_LEN >= kMinFbits) {
5656
// (10.71875)_10 = (1010.1011100)_2
57-
constexpr long long kExpected = 1372;
57+
constexpr int64_t kExpected = 1372;
5858
EXPECT_EQ(
5959
static_cast<XType>(kExpected << (FXRep::FRACTION_LEN - kMinFbits)),
6060
func(special_num_t));
@@ -63,9 +63,11 @@ class BitsFxTest : public LIBC_NAMESPACE::testing::Test {
6363
if constexpr (FXRep::SIGN_LEN > 0) {
6464
if (min <= -11 && FXRep::FRACTION_LEN >= kMinFbits) {
6565
// (-10.71875)_10 = (-1010.1011100)_2
66-
constexpr long long kExpected = -1372;
67-
EXPECT_EQ(static_cast<XType>(kExpected
68-
<< (FXRep::FRACTION_LEN - kMinFbits)),
66+
constexpr int64_t kExpected =
67+
static_cast<int64_t>(static_cast<uint64_t>(-1372)
68+
<< (FXRep::FRACTION_LEN - kMinFbits));
69+
70+
EXPECT_EQ(static_cast<XType>(kExpected),
6971
func(negative_special_num_t));
7072
}
7173
}

0 commit comments

Comments
 (0)