Skip to content

[libc] Fix implicit conversion warnings in tests. #131362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libc/src/__support/big_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ struct BigInt {
LIBC_INLINE constexpr BigInt operator~() const {
BigInt result;
for (size_t i = 0; i < WORD_COUNT; ++i)
result[i] = ~val[i];
result[i] = static_cast<WordType>(~val[i]);
return result;
}

Expand Down Expand Up @@ -967,7 +967,7 @@ struct BigInt {

LIBC_INLINE constexpr void bitwise_not() {
for (auto &part : val)
part = ~part;
part = static_cast<WordType>(~part);
}

LIBC_INLINE constexpr void negate() {
Expand Down
4 changes: 2 additions & 2 deletions libc/test/integration/src/pthread/pthread_rwlock_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ struct ThreadGuard {
~ThreadGuard() {
if (!LIBC_NAMESPACE::getenv("LIBC_PTHREAD_RWLOCK_TEST_VERBOSE"))
return;
pid_t pid = LIBC_NAMESPACE::syscall_impl(SYS_getpid);
pid_t tid = LIBC_NAMESPACE::syscall_impl(SYS_gettid);
pid_t pid = static_cast<pid_t>(LIBC_NAMESPACE::syscall_impl(SYS_getpid));
pid_t tid = static_cast<pid_t>(LIBC_NAMESPACE::syscall_impl(SYS_gettid));
io_mutex->lock(LIBC_NAMESPACE::cpp::nullopt, true);
LIBC_NAMESPACE::printf("process %d thread %d: ", pid, tid);
for (size_t i = 0; i < cursor; ++i)
Expand Down
2 changes: 1 addition & 1 deletion libc/test/integration/startup/gpu/rpc_stream_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void test_divergent() {
LIBC_NAMESPACE::rpc::Client::Port port =
LIBC_NAMESPACE::rpc::client.open<RPC_TEST_STREAM>();
port.send_n(buffer, offset);
inline_memset(buffer, offset, 0);
inline_memset(buffer, 0, offset);
port.recv_n(&recv_ptr, &recv_size, [&](uint64_t) { return buffer; });
port.close();

Expand Down
2 changes: 1 addition & 1 deletion libc/test/integration/startup/gpu/rpc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using namespace LIBC_NAMESPACE;

static void test_add_simple() {
uint32_t num_additions =
uint64_t num_additions =
10 + 10 * gpu::get_thread_id() + 10 * gpu::get_block_id();
uint64_t cnt = 0;
for (uint32_t i = 0; i < num_additions; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/__support/HashTable/table_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ TEST(LlvmLibcTableTest, Iteration) {
counter[i] = 0;
if (i >= 256) {
keys[i].bytes[0] = 2;
keys[i].bytes[1] = i % 256;
keys[i].bytes[1] = static_cast<uint8_t>(i % 256);
keys[i].bytes[2] = 0;
} else {
keys[i].bytes[0] = 1;
keys[i].bytes[1] = i;
keys[i].bytes[1] = static_cast<uint8_t>(i);
keys[i].bytes[2] = 0;
}
HashTable::insert(table, {reinterpret_cast<char *>(keys[i].bytes),
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/__support/arg_list_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ long int check_struct_type(int first, ...) {

S s = args.next_var<S>();
int last = args.next_var<int>();
return static_cast<long int>(s.c + s.s + s.i + static_cast<long>(s.l) + s.f +
s.d + last);
return s.c + s.s + s.i + s.l + static_cast<long>(s.f + s.d) + last;
}

TEST(LlvmLibcArgListTest, TestStructTypes) {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/__support/fixed_point/fx_bits_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LlvmLibcFxBitsTest : public LIBC_NAMESPACE::testing::Test {
EXPECT_EQ(LIBC_NAMESPACE::fixed_point::bit_or(T(0.75), T(0.375)), T(0.875));
using StorageType = typename FXRep<T>::StorageType;
StorageType a = LIBC_NAMESPACE::cpp::bit_cast<StorageType>(T(0.75));
a = ~a;
a = static_cast<StorageType>(~a);
EXPECT_EQ(LIBC_NAMESPACE::fixed_point::bit_not(T(0.75)),
FXBits<T>(a).get_val());
}
Expand Down
16 changes: 8 additions & 8 deletions libc/test/src/complex/CImagTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class CImagTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
neg_min_denormal);
EXPECT_FP_EQ(func(CFPT(1241.112 + max_denormal * 1.0i)), max_denormal);
EXPECT_FP_EQ(func(CFPT(121.121 + zero * 1.0i)), zero);
EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), 0.0);
EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), 0.0);
EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), -0.0);
EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), -0.0);
EXPECT_FP_EQ(func(CFPT(0.0)), 0.0);
EXPECT_FP_EQ(func(CFPT(-0.0)), 0.0);
EXPECT_FP_EQ(func(CFPT(0.0i)), 0.0);
EXPECT_FP_EQ(func(CFPT(-0.0i)), -0.0);
EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), zero);
EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), zero);
EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), neg_zero);
EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), neg_zero);
EXPECT_FP_EQ(func(CFPT(0.0)), zero);
EXPECT_FP_EQ(func(CFPT(-0.0)), zero);
EXPECT_FP_EQ(func(CFPT(0.0i)), zero);
EXPECT_FP_EQ(func(CFPT(-0.0i)), neg_zero);
}

void testRoundedNumbers(CImagFunc func) {
Expand Down
16 changes: 8 additions & 8 deletions libc/test/src/complex/CRealTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class CRealTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_FP_EQ(func(CFPT(neg_min_denormal + 781.134i)), neg_min_denormal);
EXPECT_FP_EQ(func(CFPT(max_denormal + 1241.112i)), max_denormal);
EXPECT_FP_EQ(func(CFPT(zero + 121.121i)), zero);
EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), 0.0);
EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), 0.0);
EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), 0.0);
EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), -0.0);
EXPECT_FP_EQ(func(CFPT(0.0)), 0.0);
EXPECT_FP_EQ(func(CFPT(-0.0)), -0.0);
EXPECT_FP_EQ(func(CFPT(0.0i)), 0.0);
EXPECT_FP_EQ(func(CFPT(-0.0i)), -0.0);
EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), zero);
EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), zero);
EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), zero);
EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), neg_zero);
EXPECT_FP_EQ(func(CFPT(0.0)), zero);
EXPECT_FP_EQ(func(CFPT(-0.0)), neg_zero);
EXPECT_FP_EQ(func(CFPT(0.0i)), zero);
EXPECT_FP_EQ(func(CFPT(-0.0i)), neg_zero);
}

void testRoundedNumbers(CRealFunc func) {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/fcntl/openat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST(LlvmLibcUniStd, OpenAndReadTest) {
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(dir_fd, 0);
constexpr const char TEST_MSG[] = "openat test";
constexpr int TEST_MSG_SIZE = sizeof(TEST_MSG) - 1;
constexpr ssize_t TEST_MSG_SIZE = sizeof(TEST_MSG) - 1;

int read_fd = LIBC_NAMESPACE::openat(dir_fd, TEST_FILE, O_RDONLY);
ASSERT_ERRNO_SUCCESS();
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/math/CopySignTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class CopySignTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
if (FPBits(v).is_nan() || FPBits(v).is_inf())
continue;

double res1 = func(x, -x);
T res1 = func(x, -x);
ASSERT_FP_EQ(res1, -x);

double res2 = func(x, x);
T res2 = func(x, x);
ASSERT_FP_EQ(res2, x);
}
}
Expand Down
20 changes: 10 additions & 10 deletions libc/test/src/math/FMaxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ class FMaxTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
void testNaN(FMaxFunc func) {
EXPECT_FP_EQ(inf, func(aNaN, inf));
EXPECT_FP_EQ(neg_inf, func(neg_inf, aNaN));
EXPECT_FP_EQ(0.0, func(aNaN, 0.0));
EXPECT_FP_EQ(-0.0, func(-0.0, aNaN));
EXPECT_FP_EQ(zero, func(aNaN, zero));
EXPECT_FP_EQ(neg_zero, func(neg_zero, aNaN));
EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345)));
EXPECT_FP_EQ(T(1.2345), func(T(1.2345), aNaN));
EXPECT_FP_EQ(aNaN, func(aNaN, aNaN));
}

void testInfArg(FMaxFunc func) {
EXPECT_FP_EQ(inf, func(neg_inf, inf));
EXPECT_FP_EQ(inf, func(inf, 0.0));
EXPECT_FP_EQ(inf, func(-0.0, inf));
EXPECT_FP_EQ(inf, func(inf, zero));
EXPECT_FP_EQ(inf, func(neg_zero, inf));
EXPECT_FP_EQ(inf, func(inf, T(1.2345)));
EXPECT_FP_EQ(inf, func(T(-1.2345), inf));
}

void testNegInfArg(FMaxFunc func) {
EXPECT_FP_EQ(inf, func(inf, neg_inf));
EXPECT_FP_EQ(0.0, func(neg_inf, 0.0));
EXPECT_FP_EQ(-0.0, func(-0.0, neg_inf));
EXPECT_FP_EQ(zero, func(neg_inf, zero));
EXPECT_FP_EQ(neg_zero, func(neg_zero, neg_inf));
EXPECT_FP_EQ(T(-1.2345), func(neg_inf, T(-1.2345)));
EXPECT_FP_EQ(T(1.2345), func(T(1.2345), neg_inf));
}

void testBothZero(FMaxFunc func) {
EXPECT_FP_EQ(0.0, func(0.0, 0.0));
EXPECT_FP_EQ(0.0, func(-0.0, 0.0));
EXPECT_FP_EQ(0.0, func(0.0, -0.0));
EXPECT_FP_EQ(-0.0, func(-0.0, -0.0));
EXPECT_FP_EQ(zero, func(zero, zero));
EXPECT_FP_EQ(zero, func(neg_zero, zero));
EXPECT_FP_EQ(zero, func(zero, neg_zero));
EXPECT_FP_EQ(neg_zero, func(neg_zero, neg_zero));
}

void testRange(FMaxFunc func) {
Expand Down
20 changes: 10 additions & 10 deletions libc/test/src/math/FMinTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ class FMinTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
void testNaN(FMinFunc func) {
EXPECT_FP_EQ(inf, func(aNaN, inf));
EXPECT_FP_EQ(neg_inf, func(neg_inf, aNaN));
EXPECT_FP_EQ(0.0, func(aNaN, 0.0));
EXPECT_FP_EQ(-0.0, func(-0.0, aNaN));
EXPECT_FP_EQ(zero, func(aNaN, zero));
EXPECT_FP_EQ(neg_zero, func(neg_zero, aNaN));
EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345)));
EXPECT_FP_EQ(T(1.2345), func(T(1.2345), aNaN));
EXPECT_FP_EQ(aNaN, func(aNaN, aNaN));
}

void testInfArg(FMinFunc func) {
EXPECT_FP_EQ(neg_inf, func(neg_inf, inf));
EXPECT_FP_EQ(0.0, func(inf, 0.0));
EXPECT_FP_EQ(-0.0, func(-0.0, inf));
EXPECT_FP_EQ(zero, func(inf, zero));
EXPECT_FP_EQ(neg_zero, func(neg_zero, inf));
EXPECT_FP_EQ(T(1.2345), func(inf, T(1.2345)));
EXPECT_FP_EQ(T(-1.2345), func(T(-1.2345), inf));
}

void testNegInfArg(FMinFunc func) {
EXPECT_FP_EQ(neg_inf, func(inf, neg_inf));
EXPECT_FP_EQ(neg_inf, func(neg_inf, 0.0));
EXPECT_FP_EQ(neg_inf, func(-0.0, neg_inf));
EXPECT_FP_EQ(neg_inf, func(neg_inf, zero));
EXPECT_FP_EQ(neg_inf, func(neg_zero, neg_inf));
EXPECT_FP_EQ(neg_inf, func(neg_inf, T(-1.2345)));
EXPECT_FP_EQ(neg_inf, func(T(1.2345), neg_inf));
}

void testBothZero(FMinFunc func) {
EXPECT_FP_EQ(0.0, func(0.0, 0.0));
EXPECT_FP_EQ(-0.0, func(-0.0, 0.0));
EXPECT_FP_EQ(-0.0, func(0.0, -0.0));
EXPECT_FP_EQ(-0.0, func(-0.0, -0.0));
EXPECT_FP_EQ(zero, func(zero, zero));
EXPECT_FP_EQ(neg_zero, func(neg_zero, zero));
EXPECT_FP_EQ(neg_zero, func(zero, neg_zero));
EXPECT_FP_EQ(neg_zero, func(neg_zero, neg_zero));
}

void testRange(FMinFunc func) {
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/math/FrexpTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class FrexpTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
ASSERT_FP_EQ(inf, func(inf, &exponent));
ASSERT_FP_EQ(neg_inf, func(neg_inf, &exponent));

ASSERT_FP_EQ(0.0, func(0.0, &exponent));
ASSERT_FP_EQ(zero, func(zero, &exponent));
ASSERT_EQ(exponent, 0);

ASSERT_FP_EQ(-0.0, func(-0.0, &exponent));
ASSERT_FP_EQ(neg_zero, func(neg_zero, &exponent));
ASSERT_EQ(exponent, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/NextAfterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
expected_bits = min_subnormal + 1;
expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
ASSERT_FP_EQ(result, expected);
ASSERT_FP_EQ(func(x, 0), 0);
ASSERT_FP_EQ(func(x, 0), zero);

x = -x;
result = func(x, -1);
Expand Down
3 changes: 2 additions & 1 deletion libc/test/src/math/exhaustive/exhaustive_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ struct LlvmLibcExhaustiveMathTest
range_end = stop;
}
current_value = range_end;
int pc = 100.0 * (range_end - start) / (stop - start);
int pc =
static_cast<int>(100.0 * (range_end - start) / (stop - start));
if (current_percent != pc) {
new_percent = pc;
current_percent = pc;
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class LlvmLibcFModTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
int max2 = 3 + FPBits::MAX_BIASED_EXPONENT / 2;
for (T by : TEST_BASES) {
for (int iy = min2; iy < max2; iy++) {
T y = by * LIBC_NAMESPACE::fputil::ldexp(2.0, iy);
T y = by * LIBC_NAMESPACE::fputil::ldexp(T(2.0), iy);
FPBits y_bits(y);
if (y_bits.is_zero() || !y_bits.is_finite())
continue;
for (T bx : TEST_BASES) {
for (int ix = min2; ix < max2; ix++) {
T x = bx * LIBC_NAMESPACE::fputil::ldexp(2.0, ix);
T x = bx * LIBC_NAMESPACE::fputil::ldexp(T(2.0), ix);
if (!FPBits(x).is_finite())
continue;
T result = FMod::eval(x, y);
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/NextAfterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
expected_bits = min_subnormal + 1;
expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected);
ASSERT_FP_EQ_WITH_UNDERFLOW(func(x, 0), 0);
ASSERT_FP_EQ_WITH_UNDERFLOW(func(x, 0), zero);

x = -x;
result = func(x, -1);
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/NextTowardTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class NextTowardTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
expected_bits = min_subnormal + 1;
expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected);
ASSERT_FP_EQ_WITH_UNDERFLOW(func(x, 0), 0);
ASSERT_FP_EQ_WITH_UNDERFLOW(func(x, 0), zero);

x = -x;
result = func(x, -1);
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/stdio/fileop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST(LlvmLibcFILETest, SimpleFileOperations) {

LIBC_NAMESPACE::libc_errno = 0;
ASSERT_THAT(LIBC_NAMESPACE::fwrite("nothing", 1, 1, file),
returns(EQ(0)).with_errno(NE(0)));
returns(EQ(size_t(0))).with_errno(NE(0)));
LIBC_NAMESPACE::libc_errno = 0;

ASSERT_EQ(LIBC_NAMESPACE::fclose(file), 0);
Expand Down
Loading
Loading