[libc-commits] [libc] [libc] Fix gcc warnings. (PR #240958)
via libc-commits
libc-commits at lists.llvm.org
Tue Nov 10 10:49:40 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: lntue
<details>
<summary>Changes</summary>
Mostly implicit casts in floating point tests, and some gcc warnings.
Assisted-by: Gemini
---
Patch is 137.16 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/240958.diff
54 Files Affected:
- (modified) libc/cmake/modules/CheckCompilerFeatures.cmake (+24-14)
- (modified) libc/hdr/types/char8_t.h (+7)
- (modified) libc/include/llvm-libc-macros/cfloat128-macros.h (+2-1)
- (modified) libc/include/llvm-libc-macros/containerof-macro.h (+1-1)
- (modified) libc/include/llvm-libc-types/char8_t.h (+7)
- (modified) libc/src/__support/alloc-checker.h (+8)
- (modified) libc/src/__support/integer_to_string.h (+9-5)
- (modified) libc/src/__support/wchar/wcsnrtombs.h (+6-3)
- (modified) libc/src/string/memory_utils/utils.h (+1-1)
- (modified) libc/test/UnitTest/HermeticTestUtils.cpp (+2)
- (modified) libc/test/integration/src/__support/threads/thread_tls_test.cpp (+1-1)
- (modified) libc/test/integration/startup/linux/init_fini_array_test.cpp (+2-2)
- (modified) libc/test/integration/startup/linux/irelative_test.cpp (+2-3)
- (modified) libc/test/integration/startup/linux/tls_test.cpp (+1-1)
- (modified) libc/test/shared/shared_math_test.cpp (+1-1)
- (modified) libc/test/src/__support/OSUtil/linux/sysinfo_test.cpp (+2-1)
- (modified) libc/test/src/__support/wchar/wcsnrtombs_test.cpp (+2-2)
- (modified) libc/test/src/grp/getgrent_test.cpp (+5-4)
- (modified) libc/test/src/grp/getgrgid_test.cpp (+5-4)
- (modified) libc/test/src/grp/getgrnam_test.cpp (+5-4)
- (modified) libc/test/src/math/FModTest.h (+37-23)
- (modified) libc/test/src/math/HypotTest.h (+2-1)
- (modified) libc/test/src/math/atan2f16_test.cpp (+20-7)
- (modified) libc/test/src/math/atan2f_test.cpp (+1-1)
- (modified) libc/test/src/math/atan_test.cpp (+1-1)
- (modified) libc/test/src/math/cbrt_test.cpp (+1-1)
- (modified) libc/test/src/math/cos_test.cpp (+1-1)
- (modified) libc/test/src/math/erff_test.cpp (+1-1)
- (modified) libc/test/src/math/exhaustive/exp2f_test.cpp (+4)
- (modified) libc/test/src/math/exhaustive/expf_test.cpp (+4)
- (modified) libc/test/src/math/expm1_test.cpp (+1-1)
- (modified) libc/test/src/math/hypotf_hard_to_round.h (+1216-1216)
- (modified) libc/test/src/math/log10_test.cpp (+1-1)
- (modified) libc/test/src/math/log1p_test.cpp (+1-1)
- (modified) libc/test/src/math/log2_test.cpp (+1-1)
- (modified) libc/test/src/math/log_test.cpp (+1-1)
- (modified) libc/test/src/math/sin_test.cpp (+1-1)
- (modified) libc/test/src/math/smoke/LdExpTest.h (+10-10)
- (modified) libc/test/src/math/smoke/acosf16_test.cpp (+5-3)
- (modified) libc/test/src/math/smoke/acospif16_test.cpp (+5-3)
- (modified) libc/test/src/math/smoke/asinf16_test.cpp (+4-2)
- (modified) libc/test/src/math/smoke/asinpif16_test.cpp (+4-2)
- (modified) libc/test/src/math/smoke/atan2f16_test.cpp (+8-3)
- (modified) libc/test/src/math/smoke/cbrtf16_test.cpp (+22-10)
- (modified) libc/test/src/math/tan_test.cpp (+1-1)
- (modified) libc/test/src/signal/pthread_sigmask_test.cpp (+1-1)
- (modified) libc/test/src/stdio/fopen_test.cpp (+2-1)
- (modified) libc/test/src/string/memory_utils/memory_check_utils.h (+2-2)
- (modified) libc/test/src/string/memory_utils/op_tests.cpp (+2-2)
- (modified) libc/test/src/string/memset_explicit_test.cpp (+1-1)
- (modified) libc/test/src/string/memset_test.cpp (+1-1)
- (modified) libc/test/src/sys/wait/waitid_test.cpp (+3-1)
- (modified) libc/test/src/time/strftime_test.cpp (+1-1)
- (modified) libc/utils/MPCWrapper/MPCUtils.cpp (+1)
``````````diff
diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index eaf702710b1cce..7d372074ad896a 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -60,6 +60,20 @@ function(_intersection output_var list1 list2)
set(${output_var} ${tmp} PARENT_SCOPE)
endfunction()
+### Compiler Feature Detection ###
+
+# clang-8+, gcc-12+
+check_cxx_compiler_flag("-ftrivial-auto-var-init=pattern" LIBC_CC_SUPPORTS_PATTERN_INIT)
+
+# clang-6+, gcc-13+
+check_cxx_compiler_flag("-nostdlib++" LIBC_CC_SUPPORTS_NOSTDLIBPP)
+
+# clang-3.0+
+check_cxx_compiler_flag("-nostdlibinc" LIBC_CC_SUPPORTS_NOSTDLIBINC)
+
+# clang-all, gcc-8+
+check_cxx_compiler_flag("-Wextra-semi" LIBC_CC_SUPPORTS_EXTRA_SEMI)
+
set(AVAILABLE_COMPILER_FEATURES "")
# Try compile a C file to check if flag is supported.
@@ -93,6 +107,16 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
endif()
+ if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_TARGET_OS_IS_GPU AND NOT MSVC)
+ list(APPEND compile_options "-ffreestanding")
+ if(LIBC_CC_SUPPORTS_NOSTDLIBINC)
+ list(APPEND compile_options "-nostdlibinc")
+ elseif(COMPILER_RESOURCE_DIR)
+ list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include")
+ list(APPEND compile_options "-nostdinc")
+ endif()
+ endif()
+
if(LIBC_TARGET_OS_IS_GPU)
# CUDA shouldn't be required to build the libc, only to test it, so we can't
# try to build CUDA binaries here. Since GPU builds are always compiled with
@@ -154,17 +178,3 @@ set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT})
set(link_options "")
message(STATUS "Compiler features available: ${AVAILABLE_COMPILER_FEATURES}")
-
-### Compiler Feature Detection ###
-
-# clang-8+, gcc-12+
-check_cxx_compiler_flag("-ftrivial-auto-var-init=pattern" LIBC_CC_SUPPORTS_PATTERN_INIT)
-
-# clang-6+, gcc-13+
-check_cxx_compiler_flag("-nostdlib++" LIBC_CC_SUPPORTS_NOSTDLIBPP)
-
-# clang-3.0+
-check_cxx_compiler_flag("-nostdlibinc" LIBC_CC_SUPPORTS_NOSTDLIBINC)
-
-# clang-all, gcc-8+
-check_cxx_compiler_flag("-Wextra-semi" LIBC_CC_SUPPORTS_EXTRA_SEMI)
diff --git a/libc/hdr/types/char8_t.h b/libc/hdr/types/char8_t.h
index 76334b338cf297..560415ed417194 100644
--- a/libc/hdr/types/char8_t.h
+++ b/libc/hdr/types/char8_t.h
@@ -23,7 +23,14 @@
// Define char8_t in C++ for internal usage if it is not provided by compiler
// or system uchar.h header.
#ifndef __cpp_char8_t
+#if defined(__GNUC__) && !defined(__clang__) && defined(__cplusplus)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++20-compat"
+#endif
using char8_t = unsigned char;
+#if defined(__GNUC__) && !defined(__clang__) && defined(__cplusplus)
+#pragma GCC diagnostic pop
+#endif
#endif // !__cpp_char8_t
#endif // LIBC_FULL_BUILD
diff --git a/libc/include/llvm-libc-macros/cfloat128-macros.h b/libc/include/llvm-libc-macros/cfloat128-macros.h
index ff4aa530685de0..709a682ad12248 100644
--- a/libc/include/llvm-libc-macros/cfloat128-macros.h
+++ b/libc/include/llvm-libc-macros/cfloat128-macros.h
@@ -27,7 +27,8 @@
#define LIBC_TYPES_HAS_CFLOAT128
#endif
#elif defined(__GNUC__)
-#if (defined(__STDC_IEC_60559_COMPLEX__) && defined(__SIZEOF_FLOAT128__)) && \
+#if (defined(__STDC_IEC_60559_COMPLEX__) || defined(__GCC_IEC_559_COMPLEX)) && \
+ defined(__SIZEOF_FLOAT128__) && \
(__GNUC__ >= 13 || (!defined(__cplusplus)))
#define LIBC_TYPES_HAS_CFLOAT128
#endif
diff --git a/libc/include/llvm-libc-macros/containerof-macro.h b/libc/include/llvm-libc-macros/containerof-macro.h
index debf441bf845e3..20baed4b52a444 100644
--- a/libc/include/llvm-libc-macros/containerof-macro.h
+++ b/libc/include/llvm-libc-macros/containerof-macro.h
@@ -14,7 +14,7 @@
#define __containerof(ptr, type, member) \
({ \
const __typeof(((type *)0)->member) *__ptr = (ptr); \
- (type *)(void *)((const char *)__ptr - offsetof(type, member)); \
+ (type *)(__UINTPTR_TYPE__)((const char *)__ptr - offsetof(type, member)); \
})
#endif // LLVM_LIBC_MACROS_CONTAINEROF_MACRO_H
diff --git a/libc/include/llvm-libc-types/char8_t.h b/libc/include/llvm-libc-types/char8_t.h
index 6c121276017270..8cf434c956ab76 100644
--- a/libc/include/llvm-libc-types/char8_t.h
+++ b/libc/include/llvm-libc-types/char8_t.h
@@ -10,7 +10,14 @@
#define LLVM_LIBC_TYPES_CHAR8_T_H
#ifndef __cpp_char8_t
+#if defined(__GNUC__) && !defined(__clang__) && defined(__cplusplus)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++20-compat"
+#endif
typedef unsigned char char8_t;
+#if defined(__GNUC__) && !defined(__clang__) && defined(__cplusplus)
+#pragma GCC diagnostic pop
+#endif
#endif // !__cpp_char8_t
#endif // LLVM_LIBC_TYPES_CHAR8_T_H
diff --git a/libc/src/__support/alloc-checker.h b/libc/src/__support/alloc-checker.h
index 0c4c22edff7862..d3e8cb2503941d 100644
--- a/libc/src/__support/alloc-checker.h
+++ b/libc/src/__support/alloc-checker.h
@@ -34,6 +34,11 @@ class AllocChecker {
LIBC_INLINE static void *alloc(size_t s, AllocChecker &ac) {
void *mem = ::malloc(s);
ac = (mem != nullptr);
+#ifdef LIBC_COMPILER_IS_GCC
+ // Prevent GCC's -Wmismatched-new-delete from tracking the inlined malloc
+ // call back from our custom operator delete overloads.
+ __asm__("" : "+r"(mem));
+#endif
return mem;
}
@@ -49,6 +54,9 @@ class AllocChecker {
void *mem = ::aligned_alloc(static_cast<size_t>(align), s);
#endif
ac = (mem != nullptr);
+#ifdef LIBC_COMPILER_IS_GCC
+ __asm__("" : "+r"(mem));
+#endif
return mem;
}
};
diff --git a/libc/src/__support/integer_to_string.h b/libc/src/__support/integer_to_string.h
index f392fa65ac7714..b81919145992fa 100644
--- a/libc/src/__support/integer_to_string.h
+++ b/libc/src/__support/integer_to_string.h
@@ -199,16 +199,20 @@ extract_decimal_digit(T &value) {
constexpr Word HALFWORD_MASK = ((Word(1) << HALFWORD_BITS) - 1);
// Sum both halves of all words except the low one.
for (size_t i = 1; i < T::WORD_COUNT; i++) {
- acc_remainder += value.val[i] >> HALFWORD_BITS;
- acc_remainder += value.val[i] & HALFWORD_MASK;
+ acc_remainder =
+ static_cast<Word>(acc_remainder + (value.val[i] >> HALFWORD_BITS));
+ acc_remainder =
+ static_cast<Word>(acc_remainder + (value.val[i] & HALFWORD_MASK));
}
// Add the high half of the low word. Then we have everything that needs to
// be multiplied by 6, so do that.
- acc_remainder += value.val[0] >> HALFWORD_BITS;
- acc_remainder *= 6;
+ acc_remainder =
+ static_cast<Word>(acc_remainder + (value.val[0] >> HALFWORD_BITS));
+ acc_remainder = static_cast<Word>(acc_remainder * 6);
// Having multiplied it by 6, add the lowest half-word, and then reduce mod
// 10 by normal integer division to finish.
- acc_remainder += value.val[0] & HALFWORD_MASK;
+ acc_remainder =
+ static_cast<Word>(acc_remainder + (value.val[0] & HALFWORD_MASK));
uint8_t digit = static_cast<uint8_t>(acc_remainder % 10);
// Now we have the output digit. Subtract it from the input value, and shift
diff --git a/libc/src/__support/wchar/wcsnrtombs.h b/libc/src/__support/wchar/wcsnrtombs.h
index 5faf035145ff69..7305576d91bdfd 100644
--- a/libc/src/__support/wchar/wcsnrtombs.h
+++ b/libc/src/__support/wchar/wcsnrtombs.h
@@ -35,9 +35,12 @@ wcsnrtombs(char *__restrict dest, const wchar_t **__restrict ptr_to_src,
if (dest == nullptr)
dest_len = SIZE_MAX;
- StringConverter<char32_t> str_conv(
- reinterpret_cast<const char32_t *>(*ptr_to_src), ps, dest_len,
- num_src_widechars);
+#if defined(LIBC_TYPES_WCHAR_T_IS_UTF32)
+ StringConverter<wchar_t> str_conv(*ptr_to_src, ps, dest_len,
+ num_src_widechars);
+#else
+#error "wcsnrtombs is currently only supported when wchar_t is 32-bit UTF-32."
+#endif
size_t dst_idx = 0;
ErrorOr<char8_t> converted = str_conv.pop<char8_t>();
while (converted.has_value()) {
diff --git a/libc/src/string/memory_utils/utils.h b/libc/src/string/memory_utils/utils.h
index b1a4885cb8c1f2..38aec196cd44ac 100644
--- a/libc/src/string/memory_utils/utils.h
+++ b/libc/src/string/memory_utils/utils.h
@@ -212,7 +212,7 @@ LIBC_INLINE MemcmpReturnType cmp_neq_uint64_t(uint64_t a, uint64_t b) {
// Loads bytes from memory (possibly unaligned) and materializes them as
// type.
template <typename T> LIBC_INLINE T load_unaligned(CPtr ptr) {
- T out;
+ T out{};
memcpy_inline<sizeof(T)>(&out, ptr);
return out;
}
diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 3d9cb6d2cbf1e0..2155606a9309a7 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -154,6 +154,8 @@ void operator delete(void *ptr) { free(ptr); }
void operator delete[](void *ptr) { free(ptr); }
+void operator delete[](void *ptr, size_t) { free(ptr); }
+
void operator delete(void *ptr, size_t) { free(ptr); }
// Defining members in the std namespace is not preferred. But, we do it here
diff --git a/libc/test/integration/src/__support/threads/thread_tls_test.cpp b/libc/test/integration/src/__support/threads/thread_tls_test.cpp
index d7ad54e52b81c0..f6286bc99bd94d 100644
--- a/libc/test/integration/src/__support/threads/thread_tls_test.cpp
+++ b/libc/test/integration/src/__support/threads/thread_tls_test.cpp
@@ -22,7 +22,7 @@ int func(void *) {
}
void thread_local_test() {
- int retval;
+ int retval = 0;
LIBC_NAMESPACE::Thread th1;
th1.run(func, nullptr, nullptr, 0);
diff --git a/libc/test/integration/startup/linux/init_fini_array_test.cpp b/libc/test/integration/startup/linux/init_fini_array_test.cpp
index ed14e03a60c05e..534a9ea1f9a2eb 100644
--- a/libc/test/integration/startup/linux/init_fini_array_test.cpp
+++ b/libc/test/integration/startup/linux/init_fini_array_test.cpp
@@ -39,14 +39,14 @@ int preinitval = 0;
__attribute__((constructor)) void set_initval() {
initval = INITVAL_INITIALIZER;
}
-__attribute__((destructor(1))) void reset_initval() {
+__attribute__((destructor(101))) void reset_initval() {
ASSERT_TRUE(global_destroyed);
ASSERT_EQ(preinitval, 0);
initval = 0;
}
void set_preinitval() { preinitval = INITVAL_INITIALIZER; }
-__attribute__((destructor(2))) void reset_preinitval() {
+__attribute__((destructor(102))) void reset_preinitval() {
ASSERT_TRUE(global_destroyed);
ASSERT_EQ(initval, INITVAL_INITIALIZER);
preinitval = 0;
diff --git a/libc/test/integration/startup/linux/irelative_test.cpp b/libc/test/integration/startup/linux/irelative_test.cpp
index 0fda65c95660b2..11e8e541887fba 100644
--- a/libc/test/integration/startup/linux/irelative_test.cpp
+++ b/libc/test/integration/startup/linux/irelative_test.cpp
@@ -22,11 +22,10 @@ static int impl_b() { return 84; }
// receives (hwcap, hwcap2). We use extern "C" to ensure C linkage for the
// ifunc attribute.
extern "C" {
-// Declare the resolver to return a generic function pointer.
// For testing, unconditionally select impl_a.
-void *my_ifunc_resolver() {
+int (*my_ifunc_resolver())() {
(void)impl_b; // Suppress unused warning.
- return reinterpret_cast<void *>(impl_a);
+ return impl_a;
}
}
diff --git a/libc/test/integration/startup/linux/tls_test.cpp b/libc/test/integration/startup/linux/tls_test.cpp
index fac6c3ec5c24f0..b40a6f6048b00b 100644
--- a/libc/test/integration/startup/linux/tls_test.cpp
+++ b/libc/test/integration/startup/linux/tls_test.cpp
@@ -14,7 +14,7 @@
#include <sys/mman.h>
constexpr int threadLocalDataSize = 101;
-_Thread_local int a[threadLocalDataSize] = {123};
+thread_local int a[threadLocalDataSize] = {123};
TEST_MAIN([[maybe_unused]] int argc, [[maybe_unused]] char **argv,
[[maybe_unused]] char **envp) {
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 97e975a238922d..e7f51664366932 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -593,7 +593,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
// Emulated float128 tests
TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
- int exponent;
+ int exponent = 0;
using FPBits = LIBC_NAMESPACE::fputil::FPBits<Float128>;
EXPECT_FP_EQ(Float128(0.0),
diff --git a/libc/test/src/__support/OSUtil/linux/sysinfo_test.cpp b/libc/test/src/__support/OSUtil/linux/sysinfo_test.cpp
index 8ff00eb67a4e44..0672c914fe6089 100644
--- a/libc/test/src/__support/OSUtil/linux/sysinfo_test.cpp
+++ b/libc/test/src/__support/OSUtil/linux/sysinfo_test.cpp
@@ -73,8 +73,9 @@ TEST(LlvmLibcOSUtilSysinfoTest, SyntheticCpuLists) {
ASSERT_EQ(write_test_file(test_file, test_case.contents), 0);
cpp::optional<size_t> parsed = sysinfo::parse_nproc_from(test_file);
EXPECT_EQ(static_cast<bool>(parsed), static_cast<bool>(test_case.expected));
- if (parsed)
+ if (parsed) {
EXPECT_EQ(*parsed, *test_case.expected);
+ }
EXPECT_GT(sysinfo::parse_nproc_with_fallback_from(test_file), size_t(0));
}
diff --git a/libc/test/src/__support/wchar/wcsnrtombs_test.cpp b/libc/test/src/__support/wchar/wcsnrtombs_test.cpp
index 2d431eddf4a6fd..67cf81878988a8 100644
--- a/libc/test/src/__support/wchar/wcsnrtombs_test.cpp
+++ b/libc/test/src/__support/wchar/wcsnrtombs_test.cpp
@@ -188,13 +188,13 @@ TEST(LlvmLibcWcsnrtombs, InvalidCharacter) {
char mbs[11];
// n parameter ignored when dest is null
- auto res = LIBC_NAMESPACE::internal::wcsnrtombs(mbs, &cur, 5, 7, &state1);
+ auto res = LIBC_NAMESPACE::internal::wcsnrtombs(mbs, &cur, 4, 7, &state1);
ASSERT_TRUE(res.has_value());
ASSERT_EQ(res.value(), static_cast<size_t>(7));
LIBC_NAMESPACE::internal::mbstate state2;
cur = src;
- res = LIBC_NAMESPACE::internal::wcsnrtombs(mbs, &cur, 5, 11, &state2);
+ res = LIBC_NAMESPACE::internal::wcsnrtombs(mbs, &cur, 4, 11, &state2);
ASSERT_FALSE(res.has_value());
ASSERT_EQ(res.error(), EILSEQ);
}
diff --git a/libc/test/src/grp/getgrent_test.cpp b/libc/test/src/grp/getgrent_test.cpp
index 48e70c3702cf03..d6fd2eb3808176 100644
--- a/libc/test/src/grp/getgrent_test.cpp
+++ b/libc/test/src/grp/getgrent_test.cpp
@@ -184,11 +184,12 @@ TEST_F(LlvmLibcGrpTest, DynamicMemberAndLineGrowth) {
if (i > 0)
content[offset++] = ',';
content[offset++] = 'u';
+ content[offset++] = LIBC_NAMESPACE::internal::int_to_b36_char(
+ static_cast<int>((i / 100) % 10));
+ content[offset++] = LIBC_NAMESPACE::internal::int_to_b36_char(
+ static_cast<int>((i / 10) % 10));
content[offset++] =
- LIBC_NAMESPACE::internal::int_to_b36_char((i / 100) % 10);
- content[offset++] =
- LIBC_NAMESPACE::internal::int_to_b36_char((i / 10) % 10);
- content[offset++] = LIBC_NAMESPACE::internal::int_to_b36_char(i % 10);
+ LIBC_NAMESPACE::internal::int_to_b36_char(static_cast<int>(i % 10));
}
content[offset++] = '\n';
content[offset] = '\0';
diff --git a/libc/test/src/grp/getgrgid_test.cpp b/libc/test/src/grp/getgrgid_test.cpp
index 1723bdb8fd5402..c77a0a764d5ef8 100644
--- a/libc/test/src/grp/getgrgid_test.cpp
+++ b/libc/test/src/grp/getgrgid_test.cpp
@@ -118,11 +118,12 @@ TEST_F(LlvmLibcGetgrgidTest, LongRecordGrowsBuffer) {
if (i > 0)
content[offset++] = ',';
content[offset++] = 'u';
+ content[offset++] = LIBC_NAMESPACE::internal::int_to_b36_char(
+ static_cast<int>((i / 100) % 10));
+ content[offset++] = LIBC_NAMESPACE::internal::int_to_b36_char(
+ static_cast<int>((i / 10) % 10));
content[offset++] =
- LIBC_NAMESPACE::internal::int_to_b36_char((i / 100) % 10);
- content[offset++] =
- LIBC_NAMESPACE::internal::int_to_b36_char((i / 10) % 10);
- content[offset++] = LIBC_NAMESPACE::internal::int_to_b36_char(i % 10);
+ LIBC_NAMESPACE::internal::int_to_b36_char(static_cast<int>(i % 10));
}
content[offset++] = '\n';
content[offset] = '\0';
diff --git a/libc/test/src/grp/getgrnam_test.cpp b/libc/test/src/grp/getgrnam_test.cpp
index 9c385730144012..58ad4d6e54676f 100644
--- a/libc/test/src/grp/getgrnam_test.cpp
+++ b/libc/test/src/grp/getgrnam_test.cpp
@@ -126,11 +126,12 @@ TEST_F(LlvmLibcGetgrnamTest, LongRecordGrowsBuffer) {
if (i > 0)
content[offset++] = ',';
content[offset++] = 'u';
+ content[offset++] = LIBC_NAMESPACE::internal::int_to_b36_char(
+ static_cast<int>((i / 100) % 10));
+ content[offset++] = LIBC_NAMESPACE::internal::int_to_b36_char(
+ static_cast<int>((i / 10) % 10));
content[offset++] =
- LIBC_NAMESPACE::internal::int_to_b36_char((i / 100) % 10);
- content[offset++] =
- LIBC_NAMESPACE::internal::int_to_b36_char((i / 10) % 10);
- content[offset++] = LIBC_NAMESPACE::internal::int_to_b36_char(i % 10);
+ LIBC_NAMESPACE::internal::int_to_b36_char(static_cast<int>(i % 10));
}
content[offset++] = '\n';
content[offset] = '\0';
diff --git a/libc/test/src/math/FModTest.h b/libc/test/src/math/FModTest.h
index 63320f7d3c9bfb..da34f1bbe8f401 100644
--- a/libc/test/src/math/FModTest.h
+++ b/libc/test/src/math/FModTest.h
@@ -18,6 +18,7 @@
#include "hdr/math_macros.h"
#include "src/__support/FPUtil/BasicOperations.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/cast.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -228,32 +229,45 @@ class FmodTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
}
void testRegularExtreme(FModFunc f) {
+ using LIBC_NAMESPACE::fputil::cast;
- TEST_REGULAR(0x1p127L, -0x3p-149L, 0x1p-149L);
- TEST_REGULAR(0x1p127L, 0x3p-148L, 0x1p-147L);
- TEST_REGULAR(0x1p127L, -0x3p-148L, 0x1p-147L);
- TEST_REGULAR(0x1p127L, 0x3p-126L, 0x1p-125L);
- TEST_REGULAR(0x1p127L, -0x3p-126L, 0x1p-125L);
- TEST_REGULAR(-0x1p127L, 0x3p-149L, -0x1p-149L);
- TEST_REGULAR(-0x1p127L, -0x3p-149L, -0x1p-149L);
- TEST_REGULAR(-0x1p127L, 0x3p-148L, -0x1p-147L);
- TEST_REGULAR(-0x1p127L, -0x3p-148L, -0x1p-147L);
- TEST_REGULAR(-0x1p127L, 0x3p-126L, -0x1p-125L);
- TEST_REGULAR(-0x1p127L, -0x3p-126L, -0x1p-125L);
+ TEST_REGULAR(cast<T>(0x1p127L), cast<T>(-0x3p-149L), cast<T>(0x1p-149L));
+ TEST_REGULAR(cast<T>(0x1p127L), cast<T>(0x3p-148L), cast<T>(0x1p-147L));
+ TEST_REGULAR(cast<T>(0x1p127L), cast<T>(-0x3p-148L), cast<T>(0x1p-147L));
+ TEST_REGULAR(cast<T>(0x1p127L), cast<T>(0x3p-126L), cast<T>(0x1p-125L));
+ TEST_REGULAR(cast<T>(0x1p127L), cast<T>(-0x3p-126L), cast<T>(0x1p-125L));
+ TEST_REGULAR(cast<T>(-0x1p127L), cast<T>(0x3p-149L), cast<T>(-0x1p-149L));
+ TEST_REGULAR(cast<T>(-0x1p127L), cast<T>(-0x3p-149L), cast<T>(-0x1p-149L));
+ TEST_REGULAR(cast<T>(-0x1p127L), cast<T>(0x3p-148L), cast<T>(-0x1p-147L));
+ TEST_REGULAR(cast<T>(-0x1p127L), cast<T>(-0x3p-148L), cast<T>(-0x1p-147L));
+ TEST_REGULAR(cast<T>(-0x1p127L), cast<T>(0x3p-126L), cast<T>(-0x1p-125L));
+ TEST_REGULAR(cast<T>(-0x1p127L), cast<T>(-0x3p-126L), cast<T>(-0x1p-125L));
if constexpr (sizeof(T) >= sizeof(double)) {
- TEST_REGULAR(0x1p1023L, 0x3p-1074L, 0x1p-1073L);
- TEST_REGULAR(0x1p1023L, -0x3p-1074L, 0x1p-1073L);
- TEST_REGULAR(0x1p1023L, 0x3p-1073L, 0x1p-1073L);
- TEST_REGULAR(0x1p1023L, -0x3p-1073L, 0x1p-1073L);
- TEST_REGULAR(0x1p1023L, 0x3p-1022L, 0x1p-1021L);
- TEST_REGULAR(0x1p1023L, -0x3p-1022L, 0x1p-1021L);
- TEST_REGULAR(-0x1p1023L, 0x3p-1074L, -0x1p-1073L);
- TEST_REGULAR(-0x1p1023L, -0x3p-1074L, -0x1p-1073L);
- TEST_REGULAR(-0x1p1023L, 0x3p-1073L, -0x1p-1073L);
- TEST_REGULAR(-0x1p1023L, -0x3p-1073L, -0x1p-1073L);
- TEST_REGULAR(-0x1p1023L, 0x3p-1022L, -0x1p-1021L);
- TEST_REGULAR(-0x1p1023L, -0x3p-1022L, -0x1p-1021L);
+ TEST_REGULAR(cast<T>(0x1p1023L), cast<T>(0x3p-1074L),
+ cast<T>(0x1p-1073L));
+ TEST_REGULAR(cast<T>(0x1p1023L), cast<T>(-0x3p-1074L),
+ cast<T>(0x1p-1073L));
+ TEST_REGULAR(cast<T>(0x1p1023L), cast<T>(0x3p-1073L),
+ cast<T>(0x1p-1073L));
+ TEST_REGULAR(cast<T>(0x1p1023L), cast<T>(-0x3p-1073L),
+ cast<T>(0x1p-...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/240958
More information about the libc-commits
mailing list