Skip to content

Commit ea7d813

Browse files
authored
[libc] Fix some warnings in tests. (#150500)
1 parent 1ff6d9d commit ea7d813

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

libc/src/__support/FPUtil/generic/add_sub.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ add_or_sub(InType x, InType y) {
153153

154154
result_mant <<= GUARD_BITS_LEN;
155155
} else {
156-
InStorageType max_mant = max_bits.get_explicit_mantissa() << GUARD_BITS_LEN;
157-
InStorageType min_mant = min_bits.get_explicit_mantissa() << GUARD_BITS_LEN;
156+
InStorageType max_mant = static_cast<InStorageType>(
157+
max_bits.get_explicit_mantissa() << GUARD_BITS_LEN);
158+
InStorageType min_mant = static_cast<InStorageType>(
159+
min_bits.get_explicit_mantissa() << GUARD_BITS_LEN);
158160

159161
int alignment = (max_bits.get_biased_exponent() - max_bits.is_normal()) -
160162
(min_bits.get_biased_exponent() - min_bits.is_normal());
@@ -172,7 +174,8 @@ add_or_sub(InType x, InType y) {
172174
(static_cast<InStorageType>(
173175
min_mant << (InFPBits::STORAGE_LEN - alignment))) != 0;
174176

175-
InStorageType min_mant_sticky(static_cast<int>(aligned_min_mant_sticky));
177+
InStorageType min_mant_sticky =
178+
static_cast<InStorageType>(static_cast<int>(aligned_min_mant_sticky));
176179

177180
if (is_effectively_add)
178181
result_mant = max_mant + (aligned_min_mant | min_mant_sticky);

libc/test/src/math/FmaTest.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
4848
InStorageType get_random_bit_pattern() {
4949
InStorageType bits{0};
5050
for (InStorageType i = 0; i < sizeof(InStorageType) / 2; ++i) {
51-
bits = (bits << 2) + static_cast<uint16_t>(LIBC_NAMESPACE::rand());
51+
bits = static_cast<InStorageType>(
52+
(bits << 2) + static_cast<uint16_t>(LIBC_NAMESPACE::rand()));
5253
}
5354
return bits;
5455
}
@@ -57,7 +58,7 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
5758
using FmaFunc = OutType (*)(InType, InType, InType);
5859

5960
void test_subnormal_range(FmaFunc func) {
60-
constexpr InStorageType COUNT = 100'001;
61+
constexpr InStorageType COUNT = 10'001;
6162
constexpr InStorageType RAW_STEP =
6263
(IN_MAX_SUBNORMAL_U - IN_MIN_SUBNORMAL_U) / COUNT;
6364
constexpr InStorageType STEP = (RAW_STEP == 0 ? 1 : RAW_STEP);
@@ -75,7 +76,7 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
7576
}
7677

7778
void test_normal_range(FmaFunc func) {
78-
constexpr InStorageType COUNT = 100'001;
79+
constexpr InStorageType COUNT = 10'001;
7980
constexpr InStorageType RAW_STEP =
8081
(IN_MAX_NORMAL_U - IN_MIN_NORMAL_U) / COUNT;
8182
constexpr InStorageType STEP = (RAW_STEP == 0 ? 1 : RAW_STEP);

libc/test/src/math/HypotTest.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ class HypotTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
7171

7272
void test_subnormal_range(Func func) {
7373
constexpr StorageType COUNT = 10'001;
74-
for (unsigned scale = 0; scale < 4; ++scale) {
75-
StorageType max_value = MAX_SUBNORMAL << scale;
74+
constexpr unsigned SCALE = (sizeof(T) < 4) ? 1 : 4;
75+
for (unsigned scale = 0; scale < SCALE; ++scale) {
76+
StorageType max_value = static_cast<StorageType>(MAX_SUBNORMAL << scale);
7677
StorageType step = (max_value - MIN_SUBNORMAL) / COUNT + 1;
7778
for (int signs = 0; signs < 4; ++signs) {
7879
for (StorageType v = MIN_SUBNORMAL, w = max_value;

libc/test/src/wchar/wcstol_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
#include "WcstolTest.h"
1414

15-
WCSTOL_TEST(Wcstol, LIBC_NAMESPACE::wcstol)
15+
WCSTOL_TEST(Wcstol, LIBC_NAMESPACE::wcstol)

libc/test/src/wchar/wcstoll_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
#include "WcstolTest.h"
1414

15-
WCSTOL_TEST(Wcstoll, LIBC_NAMESPACE::wcstoll)
15+
WCSTOL_TEST(Wcstoll, LIBC_NAMESPACE::wcstoll)

libc/test/src/wchar/wcstoul_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
#include "WcstolTest.h"
1414

15-
WCSTOL_TEST(Wcstoul, LIBC_NAMESPACE::wcstoul)
15+
WCSTOL_TEST(Wcstoul, LIBC_NAMESPACE::wcstoul)

libc/test/src/wchar/wcstoull_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
#include "WcstolTest.h"
1414

15-
WCSTOL_TEST(Wcstoull, LIBC_NAMESPACE::wcstoull)
15+
WCSTOL_TEST(Wcstoull, LIBC_NAMESPACE::wcstoull)

0 commit comments

Comments
 (0)