diff options
34 files changed, 195 insertions, 195 deletions
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h index fa06bb4..85db31d 100644 --- a/libc/src/__support/big_int.h +++ b/libc/src/__support/big_int.h @@ -866,7 +866,7 @@ public: 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; } @@ -967,7 +967,7 @@ private: LIBC_INLINE constexpr void bitwise_not() { for (auto &part : val) - part = ~part; + part = static_cast<WordType>(~part); } LIBC_INLINE constexpr void negate() { diff --git a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp index 4cd4255..205e9f7 100644 --- a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp +++ b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp @@ -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) diff --git a/libc/test/integration/startup/gpu/rpc_stream_test.cpp b/libc/test/integration/startup/gpu/rpc_stream_test.cpp index 208130b..aba5b0b 100644 --- a/libc/test/integration/startup/gpu/rpc_stream_test.cpp +++ b/libc/test/integration/startup/gpu/rpc_stream_test.cpp @@ -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(); diff --git a/libc/test/integration/startup/gpu/rpc_test.cpp b/libc/test/integration/startup/gpu/rpc_test.cpp index 6dce6cd..d20f396 100644 --- a/libc/test/integration/startup/gpu/rpc_test.cpp +++ b/libc/test/integration/startup/gpu/rpc_test.cpp @@ -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) { diff --git a/libc/test/src/__support/HashTable/table_test.cpp b/libc/test/src/__support/HashTable/table_test.cpp index c3b8697..a579bfa 100644 --- a/libc/test/src/__support/HashTable/table_test.cpp +++ b/libc/test/src/__support/HashTable/table_test.cpp @@ -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), diff --git a/libc/test/src/__support/arg_list_test.cpp b/libc/test/src/__support/arg_list_test.cpp index 70db0aa..645de26 100644 --- a/libc/test/src/__support/arg_list_test.cpp +++ b/libc/test/src/__support/arg_list_test.cpp @@ -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) { diff --git a/libc/test/src/__support/fixed_point/fx_bits_test.cpp b/libc/test/src/__support/fixed_point/fx_bits_test.cpp index 3cbd800..804cfd3 100644 --- a/libc/test/src/__support/fixed_point/fx_bits_test.cpp +++ b/libc/test/src/__support/fixed_point/fx_bits_test.cpp @@ -27,7 +27,7 @@ public: 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()); } diff --git a/libc/test/src/complex/CImagTest.h b/libc/test/src/complex/CImagTest.h index 408460d..e7c1bf4 100644 --- a/libc/test/src/complex/CImagTest.h +++ b/libc/test/src/complex/CImagTest.h @@ -38,14 +38,14 @@ public: 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) { diff --git a/libc/test/src/complex/CRealTest.h b/libc/test/src/complex/CRealTest.h index 80eafc9..a1efe75 100644 --- a/libc/test/src/complex/CRealTest.h +++ b/libc/test/src/complex/CRealTest.h @@ -37,14 +37,14 @@ public: 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) { diff --git a/libc/test/src/fcntl/openat_test.cpp b/libc/test/src/fcntl/openat_test.cpp index 547359e..213b074 100644 --- a/libc/test/src/fcntl/openat_test.cpp +++ b/libc/test/src/fcntl/openat_test.cpp @@ -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(); diff --git a/libc/test/src/math/CopySignTest.h b/libc/test/src/math/CopySignTest.h index 8db4f69..7c46d1b 100644 --- a/libc/test/src/math/CopySignTest.h +++ b/libc/test/src/math/CopySignTest.h @@ -42,10 +42,10 @@ public: 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); } } diff --git a/libc/test/src/math/FMaxTest.h b/libc/test/src/math/FMaxTest.h index 43904a4..77240906 100644 --- a/libc/test/src/math/FMaxTest.h +++ b/libc/test/src/math/FMaxTest.h @@ -29,8 +29,8 @@ public: 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)); @@ -38,25 +38,25 @@ public: 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) { diff --git a/libc/test/src/math/FMinTest.h b/libc/test/src/math/FMinTest.h index 51c21ae5..3822d7c 100644 --- a/libc/test/src/math/FMinTest.h +++ b/libc/test/src/math/FMinTest.h @@ -30,8 +30,8 @@ public: 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)); @@ -39,25 +39,25 @@ public: 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) { diff --git a/libc/test/src/math/FrexpTest.h b/libc/test/src/math/FrexpTest.h index 74a2d60..d1151c8 100644 --- a/libc/test/src/math/FrexpTest.h +++ b/libc/test/src/math/FrexpTest.h @@ -33,10 +33,10 @@ public: 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); } diff --git a/libc/test/src/math/NextAfterTest.h b/libc/test/src/math/NextAfterTest.h index d97c264..82d5378 100644 --- a/libc/test/src/math/NextAfterTest.h +++ b/libc/test/src/math/NextAfterTest.h @@ -100,7 +100,7 @@ public: 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); diff --git a/libc/test/src/math/exhaustive/exhaustive_test.h b/libc/test/src/math/exhaustive/exhaustive_test.h index 5912f7a..cdf459c 100644 --- a/libc/test/src/math/exhaustive/exhaustive_test.h +++ b/libc/test/src/math/exhaustive/exhaustive_test.h @@ -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; diff --git a/libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp b/libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp index b064b7e..fc3156d 100644 --- a/libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp +++ b/libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp @@ -48,13 +48,13 @@ public: 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); diff --git a/libc/test/src/math/smoke/NextAfterTest.h b/libc/test/src/math/smoke/NextAfterTest.h index e62832e..be27c9f 100644 --- a/libc/test/src/math/smoke/NextAfterTest.h +++ b/libc/test/src/math/smoke/NextAfterTest.h @@ -115,7 +115,7 @@ public: 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); diff --git a/libc/test/src/math/smoke/NextTowardTest.h b/libc/test/src/math/smoke/NextTowardTest.h index a4cd5d0..d2f352c 100644 --- a/libc/test/src/math/smoke/NextTowardTest.h +++ b/libc/test/src/math/smoke/NextTowardTest.h @@ -122,7 +122,7 @@ public: 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); diff --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp index c662a9f..a0368d7 100644 --- a/libc/test/src/stdio/fileop_test.cpp +++ b/libc/test/src/stdio/fileop_test.cpp @@ -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); diff --git a/libc/test/src/stdio/sscanf_test.cpp b/libc/test/src/stdio/sscanf_test.cpp index 18addb6..cb302df 100644 --- a/libc/test/src/stdio/sscanf_test.cpp +++ b/libc/test/src/stdio/sscanf_test.cpp @@ -246,27 +246,27 @@ TEST(LlvmLibcSScanfTest, FloatConvSimple) { ret_val = LIBC_NAMESPACE::sscanf("123", "%f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 123.0); + EXPECT_FP_EQ(result, 123.0f); ret_val = LIBC_NAMESPACE::sscanf("456.1", "%a", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 456.1); + EXPECT_FP_EQ(result, 456.1f); ret_val = LIBC_NAMESPACE::sscanf("0x789.ap0", "%e", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0x789.ap0); + EXPECT_FP_EQ(result, 0x789.ap0f); ret_val = LIBC_NAMESPACE::sscanf("0x.8", "%e", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0x0.8p0); + EXPECT_FP_EQ(result, 0x0.8p0f); ret_val = LIBC_NAMESPACE::sscanf("0x8.", "%e", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0x8.0p0); + EXPECT_FP_EQ(result, 0x8.0p0f); ret_val = LIBC_NAMESPACE::sscanf("+12.0e1", "%g", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 12.0e1); + EXPECT_FP_EQ(result, 12.0e1f); ret_val = LIBC_NAMESPACE::sscanf("inf", "%F", &result); EXPECT_EQ(ret_val, 1); @@ -282,19 +282,19 @@ TEST(LlvmLibcSScanfTest, FloatConvSimple) { ret_val = LIBC_NAMESPACE::sscanf("1e10", "%G", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 1e10); + EXPECT_FP_EQ(result, 1e10f); ret_val = LIBC_NAMESPACE::sscanf(".1", "%G", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.1); + EXPECT_FP_EQ(result, 0.1f); ret_val = LIBC_NAMESPACE::sscanf("1.", "%G", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 1.0); + EXPECT_FP_EQ(result, 1.0f); ret_val = LIBC_NAMESPACE::sscanf("0", "%f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("Not a float", "%f", &result); EXPECT_EQ(ret_val, 0); @@ -407,7 +407,7 @@ TEST(LlvmLibcSScanfTest, FloatConvComplexParsing) { ret_val = LIBC_NAMESPACE::sscanf("0x1.0e3", "%f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0x1.0e3p0); + EXPECT_FP_EQ(result, 0x1.0e3p0f); ret_val = LIBC_NAMESPACE::sscanf("", "%a", &result); EXPECT_EQ(ret_val, 0); @@ -463,11 +463,11 @@ TEST(LlvmLibcSScanfTest, FloatConvComplexParsing) { ret_val = LIBC_NAMESPACE::sscanf("-.1e1", "%f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, -.1e1); + EXPECT_FP_EQ(result, -.1e1f); ret_val = LIBC_NAMESPACE::sscanf("1.2.e1", "%f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 1.2); + EXPECT_FP_EQ(result, 1.2f); } TEST(LlvmLibcSScanfTest, FloatConvMaxWidth) { @@ -478,22 +478,22 @@ TEST(LlvmLibcSScanfTest, FloatConvMaxWidth) { ret_val = LIBC_NAMESPACE::sscanf("123", "%3f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 123.0); + EXPECT_FP_EQ(result, 123.0f); ret_val = LIBC_NAMESPACE::sscanf("123", "%5f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 123.0); + EXPECT_FP_EQ(result, 123.0f); ret_val = LIBC_NAMESPACE::sscanf("456", "%1f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 4.0); + EXPECT_FP_EQ(result, 4.0f); ret_val = LIBC_NAMESPACE::sscanf("-789", "%1f", &result); EXPECT_EQ(ret_val, 0); ret_val = LIBC_NAMESPACE::sscanf("-123", "%2f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, -1.0); + EXPECT_FP_EQ(result, -1.0f); ret_val = LIBC_NAMESPACE::sscanf("inf", "%2f", &result); EXPECT_EQ(ret_val, 0); @@ -519,11 +519,11 @@ TEST(LlvmLibcSScanfTest, FloatConvMaxWidth) { ret_val = LIBC_NAMESPACE::sscanf("01", "%1f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("0x1", "%2f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("100e", "%4f", &result); EXPECT_EQ(ret_val, 0); @@ -533,7 +533,7 @@ TEST(LlvmLibcSScanfTest, FloatConvMaxWidth) { ret_val = LIBC_NAMESPACE::sscanf("100e10", "%5f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 100e1); + EXPECT_FP_EQ(result, 100e1f); } TEST(LlvmLibcSScanfTest, FloatConvNoWrite) { @@ -542,51 +542,51 @@ TEST(LlvmLibcSScanfTest, FloatConvNoWrite) { ret_val = LIBC_NAMESPACE::sscanf("123", "%*f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("456.1", "%*a", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("0x789.ap0", "%*e", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("+12.0e1", "%*g", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("inf", "%*F", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("NaN", "%*A", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("-InFiNiTy", "%*E", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("1e10", "%*G", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf(".1", "%*G", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("123", "%*3f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("123", "%*5f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("456", "%*1f", &result); EXPECT_EQ(ret_val, 1); - EXPECT_FP_EQ(result, 0.0); + EXPECT_FP_EQ(result, 0.0f); ret_val = LIBC_NAMESPACE::sscanf("Not a float", "%*f", &result); EXPECT_EQ(ret_val, 0); diff --git a/libc/test/src/stdlib/StrfromTest.h b/libc/test/src/stdlib/StrfromTest.h index 52094728..197165c 100644 --- a/libc/test/src/stdlib/StrfromTest.h +++ b/libc/test/src/stdlib/StrfromTest.h @@ -17,45 +17,45 @@ template <typename InputT> class StrfromTest : public LIBC_NAMESPACE::testing::Test { - static const bool is_single_prec = + static constexpr bool is_single_prec = LIBC_NAMESPACE::cpp::is_same<InputT, float>::value; - static const bool is_double_prec = + static constexpr bool is_double_prec = LIBC_NAMESPACE::cpp::is_same<InputT, double>::value; using FunctionT = int (*)(char *, size_t, const char *, InputT fp); public: void floatDecimalFormat(FunctionT func) { - if (is_single_prec) + if constexpr (is_single_prec) floatDecimalSinglePrec(func); - else if (is_double_prec) + else if constexpr (is_double_prec) floatDecimalDoublePrec(func); else floatDecimalLongDoublePrec(func); } void floatHexExpFormat(FunctionT func) { - if (is_single_prec) + if constexpr (is_single_prec) floatHexExpSinglePrec(func); - else if (is_double_prec) + else if constexpr (is_double_prec) floatHexExpDoublePrec(func); else floatHexExpLongDoublePrec(func); } void floatDecimalExpFormat(FunctionT func) { - if (is_single_prec) + if constexpr (is_single_prec) floatDecimalExpSinglePrec(func); - else if (is_double_prec) + else if constexpr (is_double_prec) floatDecimalExpDoublePrec(func); else floatDecimalExpLongDoublePrec(func); } void floatDecimalAutoFormat(FunctionT func) { - if (is_single_prec) + if constexpr (is_single_prec) floatDecimalAutoSinglePrec(func); - else if (is_double_prec) + else if constexpr (is_double_prec) floatDecimalAutoDoublePrec(func); else floatDecimalAutoLongDoublePrec(func); @@ -95,7 +95,7 @@ public: written = func(buff, 36, "A simple string with one conversion", 1.0); ASSERT_STREQ_LEN(written, buff, "A simple string with one conversion"); - written = func(buff, 20, "%1f", 1234567890.0); + written = func(buff, 20, "%1f", static_cast<InputT>(1234567890.0)); ASSERT_STREQ_LEN(written, buff, "%1f"); } @@ -103,23 +103,23 @@ public: char buff[20]; int written; - written = func(buff, 5, "%f", 1234567890.0); + written = func(buff, 5, "%f", static_cast<InputT>(1234567890.0)); EXPECT_EQ(written, 17); ASSERT_STREQ(buff, "1234"); - written = func(buff, 5, "%.5f", 1.05); + written = func(buff, 5, "%.5f", static_cast<InputT>(1.05)); EXPECT_EQ(written, 7); ASSERT_STREQ(buff, "1.05"); - written = func(buff, 0, "%g", 1.0); + written = func(buff, 0, "%g", static_cast<InputT>(1.0)); EXPECT_EQ(written, 1); ASSERT_STREQ(buff, "1.05"); // Make sure that buff has not changed } void infNanValues(FunctionT func) { - if (is_double_prec) + if constexpr (is_double_prec) doublePrecInfNan(func); - else if (!is_single_prec) + else if constexpr (!is_single_prec) longDoublePrecInfNan(func); } @@ -127,13 +127,13 @@ public: char buff[70]; int written; - written = func(buff, 16, "%f", 1.0); + written = func(buff, 16, "%f", 1.0f); ASSERT_STREQ_LEN(written, buff, "1.000000"); - written = func(buff, 20, "%f", 1234567890.0); + written = func(buff, 20, "%f", 1234567890.0f); ASSERT_STREQ_LEN(written, buff, "1234567936.000000"); - written = func(buff, 67, "%.3f", 1.0); + written = func(buff, 67, "%.3f", 1.0f); ASSERT_STREQ_LEN(written, buff, "1.000"); } @@ -222,14 +222,14 @@ public: char buff[25]; int written; - written = func(buff, 0, "%a", 1234567890.0); + written = func(buff, 0, "%a", 1234567890.0f); EXPECT_EQ(written, 14); - written = func(buff, 20, "%a", 1234567890.0); + written = func(buff, 20, "%a", 1234567890.0f); EXPECT_EQ(written, 14); ASSERT_STREQ(buff, "0x1.26580cp+30"); - written = func(buff, 20, "%A", 1234567890.0); + written = func(buff, 20, "%A", 1234567890.0f); EXPECT_EQ(written, 14); ASSERT_STREQ(buff, "0X1.26580CP+30"); } @@ -314,10 +314,10 @@ public: char buff[25]; int written; - written = func(buff, 20, "%.9e", 1234567890.0); + written = func(buff, 20, "%.9e", 1234567890.0f); ASSERT_STREQ_LEN(written, buff, "1.234567936e+09"); - written = func(buff, 20, "%.9E", 1234567890.0); + written = func(buff, 20, "%.9E", 1234567890.0f); ASSERT_STREQ_LEN(written, buff, "1.234567936E+09"); } @@ -379,10 +379,10 @@ public: char buff[25]; int written; - written = func(buff, 20, "%.9g", 1234567890.0); + written = func(buff, 20, "%.9g", 1234567890.0f); ASSERT_STREQ_LEN(written, buff, "1.23456794e+09"); - written = func(buff, 20, "%.9G", 1234567890.0); + written = func(buff, 20, "%.9G", 1234567890.0f); ASSERT_STREQ_LEN(written, buff, "1.23456794E+09"); } diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp index adf6ef7..ce267d1 100644 --- a/libc/test/src/string/memcpy_test.cpp +++ b/libc/test/src/string/memcpy_test.cpp @@ -48,7 +48,7 @@ TEST(LlvmLibcMemcpyTest, CheckAccess) { auto page = pages.GetPageB().WithAccess(PROT_WRITE); // And fill it with random numbers. for (size_t i = 0; i < page.page_size; ++i) - page.page_ptr[i] = rand(); + page.page_ptr[i] = static_cast<uint8_t>(rand()); // Then return it in read mode. return page.WithAccess(PROT_READ); }(); diff --git a/libc/test/src/sys/random/linux/getrandom_test.cpp b/libc/test/src/sys/random/linux/getrandom_test.cpp index e3481b7..eb5b23c 100644 --- a/libc/test/src/sys/random/linux/getrandom_test.cpp +++ b/libc/test/src/sys/random/linux/getrandom_test.cpp @@ -16,14 +16,16 @@ TEST(LlvmLibcGetRandomTest, InvalidFlag) { LIBC_NAMESPACE::cpp::array<char, 10> buffer; LIBC_NAMESPACE::libc_errno = 0; - ASSERT_THAT(LIBC_NAMESPACE::getrandom(buffer.data(), buffer.size(), -1), - LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails(EINVAL)); + ASSERT_THAT( + LIBC_NAMESPACE::getrandom(buffer.data(), buffer.size(), -1), + LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails<ssize_t>(EINVAL)); } TEST(LlvmLibcGetRandomTest, InvalidBuffer) { LIBC_NAMESPACE::libc_errno = 0; - ASSERT_THAT(LIBC_NAMESPACE::getrandom(nullptr, 65536, 0), - LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails(EFAULT)); + ASSERT_THAT( + LIBC_NAMESPACE::getrandom(nullptr, 65536, 0), + LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails<ssize_t>(EFAULT)); } TEST(LlvmLibcGetRandomTest, ReturnsSize) { diff --git a/libc/test/src/sys/uio/readv_test.cpp b/libc/test/src/sys/uio/readv_test.cpp index 7852b8a..7cbaa33 100644 --- a/libc/test/src/sys/uio/readv_test.cpp +++ b/libc/test/src/sys/uio/readv_test.cpp @@ -36,8 +36,8 @@ TEST(LlvmLibcSysUioReadvTest, SmokeTest) { iov[1].iov_base = buf1; iov[1].iov_len = 2; ASSERT_THAT(LIBC_NAMESPACE::readv(fd, iov, 2), - returns(EQ(3)).with_errno(EQ(0))); + returns(EQ(ssize_t(3))).with_errno(EQ(0))); ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds()); ASSERT_THAT(LIBC_NAMESPACE::unlink(filename), - returns(EQ(0)).with_errno(EQ(0))); + returns(EQ(ssize_t(0))).with_errno(EQ(0))); } diff --git a/libc/test/src/sys/uio/writev_test.cpp b/libc/test/src/sys/uio/writev_test.cpp index 2c1c445..69db0de 100644 --- a/libc/test/src/sys/uio/writev_test.cpp +++ b/libc/test/src/sys/uio/writev_test.cpp @@ -27,8 +27,8 @@ TEST(LlvmLibcSysUioWritevTest, SmokeTest) { iov[1].iov_base = const_cast<char *>(data + 7); iov[1].iov_len = 8; ASSERT_THAT(LIBC_NAMESPACE::writev(fd, iov, 2), - returns(EQ(15)).with_errno(EQ(0))); + returns(EQ(ssize_t(15))).with_errno(EQ(0))); ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds()); ASSERT_THAT(LIBC_NAMESPACE::unlink(filename), - returns(EQ(0)).with_errno(EQ(0))); + returns(EQ(ssize_t(0))).with_errno(EQ(0))); } diff --git a/libc/test/src/time/strftime_test.cpp b/libc/test/src/time/strftime_test.cpp index 4fbd115..cac7560 100644 --- a/libc/test/src/time/strftime_test.cpp +++ b/libc/test/src/time/strftime_test.cpp @@ -31,13 +31,13 @@ constexpr int get_adjusted_year(int year) { // A helper class to generate simple padded numbers. It places the result in its // internal buffer, which is cleared on every call. class SimplePaddedNum { - static constexpr size_t BUFF_LEN = 16; + static constexpr int BUFF_LEN = 16; char buff[BUFF_LEN]; size_t cur_len; // length of string currently in buff void clear_buff() { // TODO: builtin_memset? - for (size_t i = 0; i < BUFF_LEN; ++i) + for (int i = 0; i < BUFF_LEN; ++i) buff[i] = '\0'; } @@ -56,9 +56,9 @@ public: // loop through all the possibilities, and for time those are all positive. LIBC_NAMESPACE::IntegerToString<int> raw(num); auto str = raw.view(); - int leading_zeroes = min_width - raw.size(); + int leading_zeroes = static_cast<int>(min_width - raw.size()); - size_t i = 0; + int i = 0; for (; static_cast<int>(i) < leading_zeroes; ++i) buff[i] = padding_char; for (size_t str_cur = 0, e = str.size(); str_cur < e; ++i, ++str_cur) @@ -290,7 +290,7 @@ TEST(LlvmLibcStrftimeTest, TwoDigitDayOfMonth) { SimplePaddedNum spn; // Tests on all the well defined values - for (size_t i = 1; i <= MAX_DAYS_PER_MONTH; ++i) { + for (int i = 1; i <= MAX_DAYS_PER_MONTH; ++i) { time.tm_mday = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%d", &time); char *result = spn.get_padded_num(i, 2); @@ -330,7 +330,7 @@ TEST(LlvmLibcStrftimeTest, MinDigitDayOfMonth) { SimplePaddedNum spn; // Tests on all the well defined values - for (size_t i = 1; i < 32; ++i) { + for (int i = 1; i < 32; ++i) { time.tm_mday = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%e", &time); char *result = spn.get_padded_num(i, 2, ' '); @@ -380,7 +380,7 @@ TEST(LlvmLibcStrftimeTest, ISOYearOfCentury) { time.tm_yday = 100; // Test the easy cases - for (size_t i = 0; i < 102; ++i) { + for (int i = 0; i < 102; ++i) { time.tm_year = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%g", &time); char *result = spn.get_padded_num(i % 100, 2); @@ -411,8 +411,8 @@ everywhere else should be in the current year. */ // check the first days of the year - for (size_t yday = 0; yday < 5; ++yday) { - for (size_t iso_wday = LIBC_NAMESPACE::time_constants::MONDAY; iso_wday < 8; + for (int yday = 0; yday < 5; ++yday) { + for (int iso_wday = LIBC_NAMESPACE::time_constants::MONDAY; iso_wday < 8; ++iso_wday) { // start with monday, to match the ISO week. time.tm_wday = iso_wday % LIBC_NAMESPACE::time_constants::DAYS_PER_WEEK; @@ -427,7 +427,7 @@ everywhere else should be in the current year. } else { // iso_wday is 5, 6, or 7 and yday is 0, 1, or 2. // days_since_thursday is therefor 1, 2, or 3. - const size_t days_since_thursday = + const int days_since_thursday = iso_wday - LIBC_NAMESPACE::time_constants::THURSDAY; if (days_since_thursday > yday) { @@ -482,8 +482,8 @@ year end - yday yday // check the last days of the year. Checking 5 to make sure all the leap year // cases are covered as well. - for (size_t days_left = 0; days_left < 5; ++days_left) { - for (size_t iso_wday = LIBC_NAMESPACE::time_constants::MONDAY; iso_wday < 8; + for (int days_left = 0; days_left < 5; ++days_left) { + for (int iso_wday = LIBC_NAMESPACE::time_constants::MONDAY; iso_wday < 8; ++iso_wday) { // start with monday, to match the ISO week. time.tm_wday = iso_wday % LIBC_NAMESPACE::time_constants::DAYS_PER_WEEK; @@ -580,8 +580,8 @@ TEST(LlvmLibcStrftimeTest, ISOYear) { time.tm_year = get_adjusted_year(1999); // check the first days of the year - for (size_t yday = 0; yday < 5; ++yday) { - for (size_t iso_wday = 1; iso_wday < 8; ++iso_wday) { + for (int yday = 0; yday < 5; ++yday) { + for (int iso_wday = 1; iso_wday < 8; ++iso_wday) { // start with monday, to match the ISO week. time.tm_wday = iso_wday % LIBC_NAMESPACE::time_constants::DAYS_PER_WEEK; time.tm_yday = yday; @@ -595,7 +595,7 @@ TEST(LlvmLibcStrftimeTest, ISOYear) { } else { // iso_wday is 5, 6, or 7 and yday is 0, 1, or 2. // days_since_thursday is therefor 1, 2, or 3. - const size_t days_since_thursday = + const int days_since_thursday = iso_wday - LIBC_NAMESPACE::time_constants::THURSDAY; if (days_since_thursday > yday) { @@ -616,8 +616,8 @@ TEST(LlvmLibcStrftimeTest, ISOYear) { // check the last days of the year. Checking 5 to make sure all the leap year // cases are covered as well. - for (size_t days_left = 0; days_left < 5; ++days_left) { - for (size_t iso_wday = 1; iso_wday < 8; ++iso_wday) { + for (int days_left = 0; days_left < 5; ++days_left) { + for (int iso_wday = 1; iso_wday < 8; ++iso_wday) { // start with monday, to match the ISO week. time.tm_wday = iso_wday % LIBC_NAMESPACE::time_constants::DAYS_PER_WEEK; // subtract 1 from the max yday to handle yday being 0-indexed. @@ -692,7 +692,7 @@ TEST(LlvmLibcStrftimeTest, TwentyFourHour) { SimplePaddedNum spn; // Tests on all the well defined values - for (size_t i = 0; i < 24; ++i) { + for (int i = 0; i < 24; ++i) { time.tm_hour = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%H", &time); char *result = spn.get_padded_num(i, 2); @@ -737,7 +737,7 @@ TEST(LlvmLibcStrftimeTest, TwelveHour) { // Tests on all the well defined values, except 0 since it was easier to // special case it. - for (size_t i = 1; i <= 12; ++i) { + for (int i = 1; i <= 12; ++i) { char *result = spn.get_padded_num(i, 2); time.tm_hour = i; @@ -783,8 +783,7 @@ TEST(LlvmLibcStrftimeTest, DayOfYear) { SimplePaddedNum spn; // Tests on all the well defined values - for (size_t i = 0; i < LIBC_NAMESPACE::time_constants::DAYS_PER_LEAP_YEAR; - ++i) { + for (int i = 0; i < LIBC_NAMESPACE::time_constants::DAYS_PER_LEAP_YEAR; ++i) { time.tm_yday = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%j", &time); char *result = spn.get_padded_num(i + 1, 3); @@ -824,7 +823,7 @@ TEST(LlvmLibcStrftimeTest, MonthOfYear) { SimplePaddedNum spn; // Tests on all the well defined values - for (size_t i = 0; i < LIBC_NAMESPACE::time_constants::MONTHS_PER_YEAR; ++i) { + for (int i = 0; i < LIBC_NAMESPACE::time_constants::MONTHS_PER_YEAR; ++i) { time.tm_mon = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%m", &time); // %m is 1 indexed, so add 1 to the number we're comparing to. @@ -865,8 +864,7 @@ TEST(LlvmLibcStrftimeTest, MinuteOfHour) { SimplePaddedNum spn; // Tests on all the well defined values - for (size_t i = 0; i < LIBC_NAMESPACE::time_constants::MINUTES_PER_HOUR; - ++i) { + for (int i = 0; i < LIBC_NAMESPACE::time_constants::MINUTES_PER_HOUR; ++i) { time.tm_min = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%M", &time); char *result = spn.get_padded_num(i, 2); @@ -971,7 +969,7 @@ TEST(LlvmLibcStrftimeTest, SecondOfMinute) { SimplePaddedNum spn; // Tests on all the well defined values - for (size_t i = 0; i < LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN; ++i) { + for (int i = 0; i < LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN; ++i) { time.tm_sec = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%S", &time); char *result = spn.get_padded_num(i, 2); @@ -1016,7 +1014,7 @@ TEST(LlvmLibcStrftimeTest, ISODayOfWeek) { // Tests on all the well defined values except for sunday, which is 0 in // normal weekdays but 7 here. - for (size_t i = LIBC_NAMESPACE::time_constants::MONDAY; + for (int i = LIBC_NAMESPACE::time_constants::MONDAY; i <= LIBC_NAMESPACE::time_constants::SATURDAY; ++i) { time.tm_wday = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%u", &time); @@ -1052,14 +1050,14 @@ TEST(LlvmLibcStrftimeTest, WeekOfYearStartingSunday) { const int WEEK_START = LIBC_NAMESPACE::time_constants::SUNDAY; - for (size_t first_weekday = LIBC_NAMESPACE::time_constants::SUNDAY; + for (int first_weekday = LIBC_NAMESPACE::time_constants::SUNDAY; first_weekday <= LIBC_NAMESPACE::time_constants::SATURDAY; ++first_weekday) { time.tm_wday = first_weekday; - size_t cur_week = 0; + int cur_week = 0; // iterate through the year, starting on first_weekday. - for (size_t yday = 0; + for (int yday = 0; yday < LIBC_NAMESPACE::time_constants::DAYS_PER_LEAP_YEAR; ++yday) { time.tm_yday = yday; // If the week just ended, move to the next week. @@ -1122,13 +1120,13 @@ TEST(LlvmLibcStrftimeTest, ISOWeekOfYear) { const int WEEK_START = LIBC_NAMESPACE::time_constants::MONDAY; - for (size_t first_weekday = LIBC_NAMESPACE::time_constants::SUNDAY; + for (int first_weekday = LIBC_NAMESPACE::time_constants::SUNDAY; first_weekday <= LIBC_NAMESPACE::time_constants::SATURDAY; ++first_weekday) { time.tm_year = starting_year; time.tm_wday = first_weekday; time.tm_yday = 0; - size_t cur_week = 1; + int cur_week = 1; if (first_weekday == LIBC_NAMESPACE::time_constants::SUNDAY || first_weekday == LIBC_NAMESPACE::time_constants::SATURDAY) cur_week = 52; @@ -1206,7 +1204,7 @@ TEST(LlvmLibcStrftimeTest, DayOfWeek) { SimplePaddedNum spn; // Tests on all the well defined values. - for (size_t i = LIBC_NAMESPACE::time_constants::SUNDAY; + for (int i = LIBC_NAMESPACE::time_constants::SUNDAY; i <= LIBC_NAMESPACE::time_constants::SATURDAY; ++i) { time.tm_wday = i; written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%w", &time); @@ -1242,14 +1240,14 @@ TEST(LlvmLibcStrftimeTest, WeekOfYearStartingMonday) { const int WEEK_START = LIBC_NAMESPACE::time_constants::MONDAY; - for (size_t first_weekday = LIBC_NAMESPACE::time_constants::SUNDAY; + for (int first_weekday = LIBC_NAMESPACE::time_constants::SUNDAY; first_weekday <= LIBC_NAMESPACE::time_constants::SATURDAY; ++first_weekday) { time.tm_wday = first_weekday; - size_t cur_week = 0; + int cur_week = 0; // iterate through the year, starting on first_weekday. - for (size_t yday = 0; + for (int yday = 0; yday < LIBC_NAMESPACE::time_constants::DAYS_PER_LEAP_YEAR; ++yday) { time.tm_yday = yday; // If the week just ended, move to the next week. @@ -1303,7 +1301,7 @@ TEST(LlvmLibcStrftimeTest, YearOfCentury) { time.tm_year = get_adjusted_year(2000); // iterate through the year, starting on first_weekday. - for (size_t year = 1900; year < 2001; ++year) { + for (int year = 1900; year < 2001; ++year) { time.tm_year = get_adjusted_year(year); written = LIBC_NAMESPACE::strftime(buffer, sizeof(buffer), "%y", &time); diff --git a/libc/test/src/unistd/lseek_test.cpp b/libc/test/src/unistd/lseek_test.cpp index 40c0bf0..7a147f2 100644 --- a/libc/test/src/unistd/lseek_test.cpp +++ b/libc/test/src/unistd/lseek_test.cpp @@ -24,7 +24,7 @@ TEST(LlvmLibcUniStd, LseekTest) { ASSERT_ERRNO_SUCCESS(); ASSERT_GT(fd, 0); constexpr const char LSEEK_TEST[] = "lseek test"; - constexpr int LSEEK_TEST_SIZE = sizeof(LSEEK_TEST) - 1; + constexpr ssize_t LSEEK_TEST_SIZE = sizeof(LSEEK_TEST) - 1; char read_buf[20]; ASSERT_THAT(LIBC_NAMESPACE::read(fd, read_buf, LSEEK_TEST_SIZE), @@ -33,7 +33,7 @@ TEST(LlvmLibcUniStd, LseekTest) { EXPECT_STREQ(read_buf, LSEEK_TEST); // Seek to the beginning of the file and re-read. - ASSERT_THAT(LIBC_NAMESPACE::lseek(fd, 0, SEEK_SET), Succeeds(0)); + ASSERT_THAT(LIBC_NAMESPACE::lseek(fd, 0, SEEK_SET), Succeeds(off_t(0))); ASSERT_THAT(LIBC_NAMESPACE::read(fd, read_buf, LSEEK_TEST_SIZE), Succeeds(LSEEK_TEST_SIZE)); read_buf[LSEEK_TEST_SIZE] = '\0'; @@ -41,7 +41,7 @@ TEST(LlvmLibcUniStd, LseekTest) { // Seek to the beginning of the file from the end and re-read. ASSERT_THAT(LIBC_NAMESPACE::lseek(fd, -LSEEK_TEST_SIZE, SEEK_END), - Succeeds(0)); + Succeeds(off_t(0))); ASSERT_THAT(LIBC_NAMESPACE::read(fd, read_buf, LSEEK_TEST_SIZE), Succeeds(LSEEK_TEST_SIZE)); read_buf[LSEEK_TEST_SIZE] = '\0'; @@ -58,6 +58,6 @@ TEST(LlvmLibcUniStd, LseekFailsTest) { int fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY); ASSERT_ERRNO_SUCCESS(); ASSERT_GT(fd, 0); - EXPECT_THAT(LIBC_NAMESPACE::lseek(fd, -1, SEEK_CUR), Fails(EINVAL)); + EXPECT_THAT(LIBC_NAMESPACE::lseek(fd, -1, SEEK_CUR), Fails<off_t>(EINVAL)); ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0)); } diff --git a/libc/test/src/unistd/pread_pwrite_test.cpp b/libc/test/src/unistd/pread_pwrite_test.cpp index 3c42fcc..397a0da 100644 --- a/libc/test/src/unistd/pread_pwrite_test.cpp +++ b/libc/test/src/unistd/pread_pwrite_test.cpp @@ -25,10 +25,10 @@ TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) { // file again and pread at an offset and make sure that only expected data // is being read back. This also confirms that pwrite happened successfully. constexpr const char HELLO[] = "hello"; - constexpr int HELLO_SIZE = sizeof(HELLO); + constexpr ssize_t HELLO_SIZE = sizeof(HELLO); constexpr off_t OFFSET = 3; constexpr const char OFFSET_TEXT[] = "helhello"; - constexpr int OFFSET_TEXT_SIZE = sizeof(OFFSET_TEXT); + constexpr ssize_t OFFSET_TEXT_SIZE = sizeof(OFFSET_TEXT); using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; @@ -67,10 +67,10 @@ TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) { TEST(LlvmLibcUniStd, PWriteFails) { using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; - EXPECT_THAT(LIBC_NAMESPACE::pwrite(-1, "", 1, 0), Fails(EBADF)); + EXPECT_THAT(LIBC_NAMESPACE::pwrite(-1, "", 1, 0), Fails<ssize_t>(EBADF)); } TEST(LlvmLibcUniStd, PReadFails) { using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; - EXPECT_THAT(LIBC_NAMESPACE::pread(-1, nullptr, 1, 0), Fails(EBADF)); + EXPECT_THAT(LIBC_NAMESPACE::pread(-1, nullptr, 1, 0), Fails<ssize_t>(EBADF)); } diff --git a/libc/test/src/unistd/read_write_test.cpp b/libc/test/src/unistd/read_write_test.cpp index 8b6ba42..ba3aeff 100644 --- a/libc/test/src/unistd/read_write_test.cpp +++ b/libc/test/src/unistd/read_write_test.cpp @@ -27,7 +27,7 @@ TEST(LlvmLibcUniStd, WriteAndReadBackTest) { ASSERT_ERRNO_SUCCESS(); ASSERT_GT(write_fd, 0); constexpr const char HELLO[] = "hello"; - constexpr int HELLO_SIZE = sizeof(HELLO); + constexpr ssize_t HELLO_SIZE = sizeof(HELLO); ASSERT_THAT(LIBC_NAMESPACE::write(write_fd, HELLO, HELLO_SIZE), Succeeds(HELLO_SIZE)); ASSERT_THAT(LIBC_NAMESPACE::fsync(write_fd), Succeeds(0)); @@ -48,15 +48,15 @@ TEST(LlvmLibcUniStd, WriteAndReadBackTest) { TEST(LlvmLibcUniStd, WriteFails) { using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; - EXPECT_THAT(LIBC_NAMESPACE::write(-1, "", 1), Fails(EBADF)); + EXPECT_THAT(LIBC_NAMESPACE::write(-1, "", 1), Fails<ssize_t>(EBADF)); EXPECT_THAT(LIBC_NAMESPACE::write(1, reinterpret_cast<const void *>(-1), 1), - Fails(EFAULT)); + Fails<ssize_t>(EFAULT)); } TEST(LlvmLibcUniStd, ReadFails) { using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; - EXPECT_THAT(LIBC_NAMESPACE::read(-1, nullptr, 1), Fails(EBADF)); + EXPECT_THAT(LIBC_NAMESPACE::read(-1, nullptr, 1), Fails<ssize_t>(EBADF)); EXPECT_THAT(LIBC_NAMESPACE::read(0, reinterpret_cast<void *>(-1), 1), - Fails(EFAULT)); + Fails<ssize_t>(EFAULT)); } diff --git a/libc/test/src/unistd/readlink_test.cpp b/libc/test/src/unistd/readlink_test.cpp index 6b27294..ffc0500 100644 --- a/libc/test/src/unistd/readlink_test.cpp +++ b/libc/test/src/unistd/readlink_test.cpp @@ -45,5 +45,5 @@ TEST(LlvmLibcReadlinkTest, ReadlinkInNonExistentPath) { constexpr auto LEN = 8; char buf[LEN]; ASSERT_THAT(LIBC_NAMESPACE::readlink("non-existent-link", buf, LEN), - Fails(ENOENT)); + Fails<ssize_t>(ENOENT)); } diff --git a/libc/test/src/unistd/readlinkat_test.cpp b/libc/test/src/unistd/readlinkat_test.cpp index 9e4bb9a..a62fde5 100644 --- a/libc/test/src/unistd/readlinkat_test.cpp +++ b/libc/test/src/unistd/readlinkat_test.cpp @@ -48,5 +48,5 @@ TEST(LlvmLibcReadlinkatTest, ReadlinkInNonExistentPath) { char buf[LEN]; ASSERT_THAT( LIBC_NAMESPACE::readlinkat(AT_FDCWD, "non-existent-link", buf, LEN), - Fails(ENOENT)); + Fails<ssize_t>(ENOENT)); } diff --git a/libc/test/src/unistd/syscall_test.cpp b/libc/test/src/unistd/syscall_test.cpp index f6cc3ea..b5a775a 100644 --- a/libc/test/src/unistd/syscall_test.cpp +++ b/libc/test/src/unistd/syscall_test.cpp @@ -75,15 +75,15 @@ TEST(LlvmLibcSyscallTest, FileReadWrite) { constexpr const char *TEST_FILE = "testdata/syscall_pread_pwrite.test"; #ifdef SYS_open - int fd = + long fd = LIBC_NAMESPACE::syscall(SYS_open, TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU); #elif defined(SYS_openat) - int fd = LIBC_NAMESPACE::syscall(SYS_openat, AT_FDCWD, TEST_FILE, - O_WRONLY | O_CREAT, S_IRWXU); + long fd = LIBC_NAMESPACE::syscall(SYS_openat, AT_FDCWD, TEST_FILE, + O_WRONLY | O_CREAT, S_IRWXU); #else #error "open and openat syscalls not available." #endif - ASSERT_GT(fd, 0); + ASSERT_GT(fd, 0l); ASSERT_ERRNO_SUCCESS(); ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_pwrite64, fd, HELLO, HELLO_SIZE, 0), @@ -112,29 +112,29 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) { // 4. Cleanup the file and its link. #ifdef SYS_open - int write_fd = LIBC_NAMESPACE::syscall(SYS_open, TEST_FILE_PATH, - O_WRONLY | O_CREAT, S_IRWXU); + long write_fd = LIBC_NAMESPACE::syscall(SYS_open, TEST_FILE_PATH, + O_WRONLY | O_CREAT, S_IRWXU); #elif defined(SYS_openat) - int write_fd = LIBC_NAMESPACE::syscall(SYS_openat, AT_FDCWD, TEST_FILE_PATH, - O_WRONLY | O_CREAT, S_IRWXU); + long write_fd = LIBC_NAMESPACE::syscall(SYS_openat, AT_FDCWD, TEST_FILE_PATH, + O_WRONLY | O_CREAT, S_IRWXU); #else #error "open and openat syscalls not available." #endif - ASSERT_GT(write_fd, 0); + ASSERT_GT(write_fd, 0l); ASSERT_ERRNO_SUCCESS(); ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_close, write_fd), 0l); ASSERT_ERRNO_SUCCESS(); #ifdef SYS_open - int dir_fd = LIBC_NAMESPACE::syscall(SYS_open, TEST_DIR, O_DIRECTORY, 0); + long dir_fd = LIBC_NAMESPACE::syscall(SYS_open, TEST_DIR, O_DIRECTORY, 0); #elif defined(SYS_openat) - int dir_fd = + long dir_fd = LIBC_NAMESPACE::syscall(SYS_openat, AT_FDCWD, TEST_DIR, O_DIRECTORY, 0); #else #error "open and openat syscalls not available." #endif - ASSERT_GT(dir_fd, 0); + ASSERT_GT(dir_fd, 0l); ASSERT_ERRNO_SUCCESS(); ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_linkat, dir_fd, TEST_FILE, dir_fd, @@ -142,15 +142,15 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) { 0l); ASSERT_ERRNO_SUCCESS(); #ifdef SYS_open - int link_fd = + long link_fd = LIBC_NAMESPACE::syscall(SYS_open, TEST_FILE_LINK_PATH, O_PATH, 0); #elif defined(SYS_openat) - int link_fd = LIBC_NAMESPACE::syscall(SYS_openat, AT_FDCWD, - TEST_FILE_LINK_PATH, O_PATH, 0); + long link_fd = LIBC_NAMESPACE::syscall(SYS_openat, AT_FDCWD, + TEST_FILE_LINK_PATH, O_PATH, 0); #else #error "open and openat syscalls not available." #endif - ASSERT_GT(link_fd, 0); + ASSERT_GT(link_fd, 0l); ASSERT_ERRNO_SUCCESS(); #ifdef SYS_unlink diff --git a/libc/utils/MPFRWrapper/MPCommon.cpp b/libc/utils/MPFRWrapper/MPCommon.cpp index 8f104c9..ac8cde2 100644 --- a/libc/utils/MPFRWrapper/MPCommon.cpp +++ b/libc/utils/MPFRWrapper/MPCommon.cpp @@ -263,7 +263,7 @@ MPFRNumber MPFRNumber::frexp(int &exp) { MPFRNumber result(*this); mpfr_exp_t resultExp; mpfr_frexp(&resultExp, result.value, value, mpfr_rounding); - exp = resultExp; + exp = static_cast<int>(resultExp); return result; } @@ -307,7 +307,7 @@ MPFRNumber MPFRNumber::remquo(const MPFRNumber &divisor, int "ient) { MPFRNumber remainder(*this); long q; mpfr_remquo(remainder.value, &q, value, divisor.value, mpfr_rounding); - quotient = q; + quotient = static_cast<int>(q); return remainder; } |