Skip to content

Commit d0a0de5

Browse files
authored
[libc] Fix implicit conversion warnings in tests. (#131362)
1 parent 51c706c commit d0a0de5

34 files changed

+195
-195
lines changed

libc/src/__support/big_int.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ struct BigInt {
866866
LIBC_INLINE constexpr BigInt operator~() const {
867867
BigInt result;
868868
for (size_t i = 0; i < WORD_COUNT; ++i)
869-
result[i] = ~val[i];
869+
result[i] = static_cast<WordType>(~val[i]);
870870
return result;
871871
}
872872

@@ -967,7 +967,7 @@ struct BigInt {
967967

968968
LIBC_INLINE constexpr void bitwise_not() {
969969
for (auto &part : val)
970-
part = ~part;
970+
part = static_cast<WordType>(~part);
971971
}
972972

973973
LIBC_INLINE constexpr void negate() {

libc/test/integration/src/pthread/pthread_rwlock_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ struct ThreadGuard {
324324
~ThreadGuard() {
325325
if (!LIBC_NAMESPACE::getenv("LIBC_PTHREAD_RWLOCK_TEST_VERBOSE"))
326326
return;
327-
pid_t pid = LIBC_NAMESPACE::syscall_impl(SYS_getpid);
328-
pid_t tid = LIBC_NAMESPACE::syscall_impl(SYS_gettid);
327+
pid_t pid = static_cast<pid_t>(LIBC_NAMESPACE::syscall_impl(SYS_getpid));
328+
pid_t tid = static_cast<pid_t>(LIBC_NAMESPACE::syscall_impl(SYS_gettid));
329329
io_mutex->lock(LIBC_NAMESPACE::cpp::nullopt, true);
330330
LIBC_NAMESPACE::printf("process %d thread %d: ", pid, tid);
331331
for (size_t i = 0; i < cursor; ++i)

libc/test/integration/startup/gpu/rpc_stream_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void test_divergent() {
8181
LIBC_NAMESPACE::rpc::Client::Port port =
8282
LIBC_NAMESPACE::rpc::client.open<RPC_TEST_STREAM>();
8383
port.send_n(buffer, offset);
84-
inline_memset(buffer, offset, 0);
84+
inline_memset(buffer, 0, offset);
8585
port.recv_n(&recv_ptr, &recv_size, [&](uint64_t) { return buffer; });
8686
port.close();
8787

libc/test/integration/startup/gpu/rpc_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using namespace LIBC_NAMESPACE;
1515

1616
static void test_add_simple() {
17-
uint32_t num_additions =
17+
uint64_t num_additions =
1818
10 + 10 * gpu::get_thread_id() + 10 * gpu::get_block_id();
1919
uint64_t cnt = 0;
2020
for (uint32_t i = 0; i < num_additions; ++i) {

libc/test/src/__support/HashTable/table_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ TEST(LlvmLibcTableTest, Iteration) {
4343
counter[i] = 0;
4444
if (i >= 256) {
4545
keys[i].bytes[0] = 2;
46-
keys[i].bytes[1] = i % 256;
46+
keys[i].bytes[1] = static_cast<uint8_t>(i % 256);
4747
keys[i].bytes[2] = 0;
4848
} else {
4949
keys[i].bytes[0] = 1;
50-
keys[i].bytes[1] = i;
50+
keys[i].bytes[1] = static_cast<uint8_t>(i);
5151
keys[i].bytes[2] = 0;
5252
}
5353
HashTable::insert(table, {reinterpret_cast<char *>(keys[i].bytes),

libc/test/src/__support/arg_list_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ long int check_struct_type(int first, ...) {
112112

113113
S s = args.next_var<S>();
114114
int last = args.next_var<int>();
115-
return static_cast<long int>(s.c + s.s + s.i + static_cast<long>(s.l) + s.f +
116-
s.d + last);
115+
return s.c + s.s + s.i + s.l + static_cast<long>(s.f + s.d) + last;
117116
}
118117

119118
TEST(LlvmLibcArgListTest, TestStructTypes) {

libc/test/src/__support/fixed_point/fx_bits_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LlvmLibcFxBitsTest : public LIBC_NAMESPACE::testing::Test {
2727
EXPECT_EQ(LIBC_NAMESPACE::fixed_point::bit_or(T(0.75), T(0.375)), T(0.875));
2828
using StorageType = typename FXRep<T>::StorageType;
2929
StorageType a = LIBC_NAMESPACE::cpp::bit_cast<StorageType>(T(0.75));
30-
a = ~a;
30+
a = static_cast<StorageType>(~a);
3131
EXPECT_EQ(LIBC_NAMESPACE::fixed_point::bit_not(T(0.75)),
3232
FXBits<T>(a).get_val());
3333
}

libc/test/src/complex/CImagTest.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ class CImagTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
3838
neg_min_denormal);
3939
EXPECT_FP_EQ(func(CFPT(1241.112 + max_denormal * 1.0i)), max_denormal);
4040
EXPECT_FP_EQ(func(CFPT(121.121 + zero * 1.0i)), zero);
41-
EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), 0.0);
42-
EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), 0.0);
43-
EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), -0.0);
44-
EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), -0.0);
45-
EXPECT_FP_EQ(func(CFPT(0.0)), 0.0);
46-
EXPECT_FP_EQ(func(CFPT(-0.0)), 0.0);
47-
EXPECT_FP_EQ(func(CFPT(0.0i)), 0.0);
48-
EXPECT_FP_EQ(func(CFPT(-0.0i)), -0.0);
41+
EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), zero);
42+
EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), zero);
43+
EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), neg_zero);
44+
EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), neg_zero);
45+
EXPECT_FP_EQ(func(CFPT(0.0)), zero);
46+
EXPECT_FP_EQ(func(CFPT(-0.0)), zero);
47+
EXPECT_FP_EQ(func(CFPT(0.0i)), zero);
48+
EXPECT_FP_EQ(func(CFPT(-0.0i)), neg_zero);
4949
}
5050

5151
void testRoundedNumbers(CImagFunc func) {

libc/test/src/complex/CRealTest.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class CRealTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
3737
EXPECT_FP_EQ(func(CFPT(neg_min_denormal + 781.134i)), neg_min_denormal);
3838
EXPECT_FP_EQ(func(CFPT(max_denormal + 1241.112i)), max_denormal);
3939
EXPECT_FP_EQ(func(CFPT(zero + 121.121i)), zero);
40-
EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), 0.0);
41-
EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), 0.0);
42-
EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), 0.0);
43-
EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), -0.0);
44-
EXPECT_FP_EQ(func(CFPT(0.0)), 0.0);
45-
EXPECT_FP_EQ(func(CFPT(-0.0)), -0.0);
46-
EXPECT_FP_EQ(func(CFPT(0.0i)), 0.0);
47-
EXPECT_FP_EQ(func(CFPT(-0.0i)), -0.0);
40+
EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), zero);
41+
EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), zero);
42+
EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), zero);
43+
EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), neg_zero);
44+
EXPECT_FP_EQ(func(CFPT(0.0)), zero);
45+
EXPECT_FP_EQ(func(CFPT(-0.0)), neg_zero);
46+
EXPECT_FP_EQ(func(CFPT(0.0i)), zero);
47+
EXPECT_FP_EQ(func(CFPT(-0.0i)), neg_zero);
4848
}
4949

5050
void testRoundedNumbers(CRealFunc func) {

libc/test/src/fcntl/openat_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TEST(LlvmLibcUniStd, OpenAndReadTest) {
2424
ASSERT_ERRNO_SUCCESS();
2525
ASSERT_GT(dir_fd, 0);
2626
constexpr const char TEST_MSG[] = "openat test";
27-
constexpr int TEST_MSG_SIZE = sizeof(TEST_MSG) - 1;
27+
constexpr ssize_t TEST_MSG_SIZE = sizeof(TEST_MSG) - 1;
2828

2929
int read_fd = LIBC_NAMESPACE::openat(dir_fd, TEST_FILE, O_RDONLY);
3030
ASSERT_ERRNO_SUCCESS();

0 commit comments

Comments
 (0)