[libc-commits] [libc] [libc] Build with -Wshadow (PR #196519)
Nico Weber via libc-commits
libc-commits at lists.llvm.org
Sun May 10 15:56:16 PDT 2026
https://github.com/nico updated https://github.com/llvm/llvm-project/pull/196519
>From 39d85eb46637b50e9c6cef9df08b618cb124ab5f Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Thu, 7 May 2026 11:09:47 -0400
Subject: [PATCH 1/4] [libc] Build with -Wshadow
---
libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 2d3703eefa0ac..db541a4dfb985 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -301,6 +301,7 @@ function(_get_common_compile_options output_var flags)
if(NOT CMAKE_COMPILER_IS_GNUCXX)
list(APPEND compile_options "-Wnewline-eof")
list(APPEND compile_options "-Wnonportable-system-include-path")
+ list(APPEND compile_options "-Wshadow")
list(APPEND compile_options "-Wstrict-prototypes")
list(APPEND compile_options "-Wthread-safety")
list(APPEND compile_options "-Wglobal-constructors")
>From 1c7feb984c1345af07e3b7a624b59b5c0860bb4d Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Sun, 10 May 2026 17:48:58 -0400
Subject: [PATCH 2/4] [libc] Fix -Wshadow warnings in inline_strlen.h
---
libc/src/string/memory_utils/generic/inline_strlen.h | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/libc/src/string/memory_utils/generic/inline_strlen.h b/libc/src/string/memory_utils/generic/inline_strlen.h
index e9f1542f41424..833ff9fbcbf80 100644
--- a/libc/src/string/memory_utils/generic/inline_strlen.h
+++ b/libc/src/string/memory_utils/generic/inline_strlen.h
@@ -39,9 +39,8 @@ LIBC_NO_SANITIZE_OOB_ACCESS LIBC_INLINE size_t string_length(const char *src) {
return cpp::find_first_set(shift_mask<char>(mask, offset));
for (;;) {
- cpp::simd<char> chars = cpp::load<cpp::simd<char>>(++aligned,
- /*aligned=*/true);
- cpp::simd_mask<char> mask = chars == null_byte;
+ chars = cpp::load<cpp::simd<char>>(++aligned, /*aligned=*/true);
+ mask = chars == null_byte;
if (cpp::any_of(mask))
return (reinterpret_cast<const char *>(aligned) - src) +
cpp::find_first_set(mask);
@@ -78,8 +77,8 @@ find_first_character(const unsigned char *s, unsigned char c, size_t n) {
for (size_t bytes_checked = sizeof(Vector) - offset; bytes_checked < n;
bytes_checked += sizeof(Vector)) {
aligned++;
- Vector chars = cpp::load<Vector>(aligned, /*aligned=*/true);
- Mask cmp_v = chars == c_byte;
+ chars = cpp::load<Vector>(aligned, /*aligned=*/true);
+ cmp_v = chars == c_byte;
if (cpp::any_of(cmp_v))
return calculate_find_first_character_return(
reinterpret_cast<const char *>(aligned), cmp_v, n - bytes_checked);
>From 321b73008c9b2ca1576f1e71a4961b321a411d5f Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Sun, 10 May 2026 17:49:14 -0400
Subject: [PATCH 3/4] [libc] Fix -Wshadow warning in sqrtf128.h
sqrtf128() contained both `using namespace sqrtf128_internal;`
and `using FPBits = fputil::FPBits<float128>;`, but sqrtf128_internal
also had a `using FPBits = fputil::FPBits<float128>;`. The outer
`using` wasn't actually used, so remove that one.
---
libc/src/__support/math/sqrtf128.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/libc/src/__support/math/sqrtf128.h b/libc/src/__support/math/sqrtf128.h
index d5b54b724c259..14dcbec1acbb6 100644
--- a/libc/src/__support/math/sqrtf128.h
+++ b/libc/src/__support/math/sqrtf128.h
@@ -60,8 +60,6 @@ namespace math {
namespace sqrtf128_internal {
-using FPBits = fputil::FPBits<float128>;
-
template <typename T, typename U = T> LIBC_INLINE constexpr T prod_hi(T, U);
// Get high part of integer multiplications.
>From 72f8d6fa01fb8cb32d4eca09df001320d661c73e Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Sun, 10 May 2026 18:54:49 -0400
Subject: [PATCH 4/4] [libc] Remove some global printf_core declarations in
float_dec_converter.h
fixed_converter.h, float_hex_converter.h have local declarations
with the same name shadowing these, causing -Wshadow warnings.
For now, just don't have global declarations for these.
---
.../stdio/printf_core/float_dec_converter.h | 21 +++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/libc/src/stdio/printf_core/float_dec_converter.h b/libc/src/stdio/printf_core/float_dec_converter.h
index 509b4e24ada32..8b99688cb993c 100644
--- a/libc/src/stdio/printf_core/float_dec_converter.h
+++ b/libc/src/stdio/printf_core/float_dec_converter.h
@@ -29,11 +29,6 @@
namespace LIBC_NAMESPACE_DECL {
namespace printf_core {
-#ifdef LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
-using StorageType = UInt128;
-#else
-using StorageType = fputil::FPBits<long double>::StorageType;
-#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
using DecimalString = IntegerToString<intmax_t>;
using ExponentString =
IntegerToString<intmax_t, radix::Dec::WithWidth<2>::WithSign>;
@@ -51,7 +46,6 @@ constexpr uint32_t MAX_BLOCK = 999999999;
// constexpr size_t BLOCK_SIZE = 18;
// constexpr uint32_t MAX_BLOCK = 999999999999999999;
-constexpr char DECIMAL_POINT = '.';
LIBC_INLINE RoundDirection get_round_direction(int last_digit, bool truncated,
Sign sign) {
@@ -176,6 +170,7 @@ template <WriteMode write_mode> class FloatWriter {
LIBC_INLINE int flush_buffer(bool round_up_max_blocks = false) {
const char MAX_BLOCK_DIGIT = (round_up_max_blocks ? '0' : '9');
+ constexpr char DECIMAL_POINT = '.';
// Write the most recent buffered block, and mark has_written
if (!has_written) {
@@ -368,6 +363,8 @@ template <WriteMode write_mode> class FloatWriter {
// has_carry should only be true here if every previous digit is 9, which
// implies that the number has never been written.
if (has_carry /* && !has_written */) {
+ constexpr char DECIMAL_POINT = '.';
+
if (has_exp) { // This is in %e style
// Since this is exponential notation, we don't write any more digits
// but we do increment the exponent.
@@ -604,6 +601,12 @@ template <typename T, WriteMode write_mode,
LIBC_INLINE int convert_float_dec_exp_typed(Writer<write_mode> *writer,
const FormatSection &to_conv,
fputil::FPBits<T> float_bits) {
+#ifdef LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
+ using StorageType = UInt128;
+#else
+ using StorageType = fputil::FPBits<long double>::StorageType;
+#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
+
// signed because later we use -FRACTION_LEN
constexpr int32_t FRACTION_LEN = fputil::FPBits<T>::FRACTION_LEN;
int exponent = float_bits.get_explicit_exponent();
@@ -766,6 +769,12 @@ template <typename T, WriteMode write_mode,
LIBC_INLINE int convert_float_dec_auto_typed(Writer<write_mode> *writer,
const FormatSection &to_conv,
fputil::FPBits<T> float_bits) {
+#ifdef LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
+ using StorageType = UInt128;
+#else
+ using StorageType = fputil::FPBits<long double>::StorageType;
+#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
+
// signed because later we use -FRACTION_LEN
constexpr int32_t FRACTION_LEN = fputil::FPBits<T>::FRACTION_LEN;
int exponent = float_bits.get_explicit_exponent();
More information about the libc-commits
mailing list