[libc-commits] [libc] [libc][NFC] Remove usage of the C keyword `I`. (PR #160567)

via libc-commits libc-commits at lists.llvm.org
Wed Sep 24 10:26:01 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (lntue)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/160567.diff


8 Files Affected:

- (modified) libc/benchmarks/LibcMemoryBenchmark.cpp (+2-2) 
- (modified) libc/benchmarks/LibcMemoryBenchmarkMain.cpp (+3-3) 
- (modified) libc/benchmarks/LibcMemoryBenchmarkTest.cpp (+3-3) 
- (modified) libc/src/__support/CPP/tuple.h (+24-24) 
- (modified) libc/test/UnitTest/MemoryMatcher.cpp (+2-2) 
- (modified) libc/test/integration/src/pthread/pthread_create_test.cpp (+4-4) 
- (modified) libc/test/src/math/smoke/RoundToIntegerTest.h (+35-33) 
- (modified) libc/test/src/string/memory_utils/utils_test.cpp (+5-5) 


``````````diff
diff --git a/libc/benchmarks/LibcMemoryBenchmark.cpp b/libc/benchmarks/LibcMemoryBenchmark.cpp
index 3ced306584d15..9307ee45b2853 100644
--- a/libc/benchmarks/LibcMemoryBenchmark.cpp
+++ b/libc/benchmarks/LibcMemoryBenchmark.cpp
@@ -53,8 +53,8 @@ MismatchOffsetDistribution::MismatchOffsetDistribution(size_t BufferSize,
     : MismatchAt(MismatchAt) {
   if (MismatchAt <= 1)
     return;
-  for (size_t I = MaxSizeValue + 1; I < BufferSize; I += MaxSizeValue)
-    MismatchIndices.push_back(I);
+  for (size_t i = MaxSizeValue + 1; i < BufferSize; i += MaxSizeValue)
+    MismatchIndices.push_back(i);
   if (MismatchIndices.empty())
     report_fatal_error("Unable to generate mismatch");
   MismatchIndexSelector =
diff --git a/libc/benchmarks/LibcMemoryBenchmarkMain.cpp b/libc/benchmarks/LibcMemoryBenchmarkMain.cpp
index c042b29cad98e..613160d72c17f 100644
--- a/libc/benchmarks/LibcMemoryBenchmarkMain.cpp
+++ b/libc/benchmarks/LibcMemoryBenchmarkMain.cpp
@@ -161,11 +161,11 @@ struct MemfunctionBenchmarkBase : public BenchmarkSetup {
     if (Percent == LastPercent)
       return;
     LastPercent = Percent;
-    size_t I = 0;
+    size_t i = 0;
     errs() << '[';
-    for (; I <= Percent; ++I)
+    for (; i <= Percent; ++i)
       errs() << '#';
-    for (; I <= 100; ++I)
+    for (; i <= 100; ++i)
       errs() << '_';
     errs() << "] " << Percent << '%' << '\r';
   }
diff --git a/libc/benchmarks/LibcMemoryBenchmarkTest.cpp b/libc/benchmarks/LibcMemoryBenchmarkTest.cpp
index 00866e5a65c27..3c796c8ecc284 100644
--- a/libc/benchmarks/LibcMemoryBenchmarkTest.cpp
+++ b/libc/benchmarks/LibcMemoryBenchmarkTest.cpp
@@ -38,7 +38,7 @@ TEST(OffsetDistribution, AlignToBegin) {
   const size_t BufferSize = 8192;
   OffsetDistribution OD(BufferSize, 1024, std::nullopt);
   std::default_random_engine Gen;
-  for (size_t I = 0; I <= 10; ++I)
+  for (size_t i = 0; i <= 10; ++i)
     EXPECT_EQ(OD(Gen), 0U);
 }
 
@@ -46,7 +46,7 @@ TEST(OffsetDistribution, NoAlignment) {
   const size_t BufferSize = 8192;
   OffsetDistribution OD(BufferSize, 1, Align(1));
   std::default_random_engine Gen;
-  for (size_t I = 0; I <= 10; ++I)
+  for (size_t i = 0; i <= 10; ++i)
     EXPECT_THAT(OD(Gen), AllOf(Ge(0U), Lt(8192U)));
 }
 
@@ -59,7 +59,7 @@ TEST(OffsetDistribution, Aligned) {
   const size_t BufferSize = 8192;
   OffsetDistribution OD(BufferSize, 1, Align(16));
   std::default_random_engine Gen;
-  for (size_t I = 0; I <= 10; ++I)
+  for (size_t i = 0; i <= 10; ++i)
     EXPECT_THAT(OD(Gen), AllOf(Ge(0U), Lt(8192U), IsDivisibleBy(16U)));
 }
 
diff --git a/libc/src/__support/CPP/tuple.h b/libc/src/__support/CPP/tuple.h
index cce8e0ef2bfae..fa4fcd08cc04f 100644
--- a/libc/src/__support/CPP/tuple.h
+++ b/libc/src/__support/CPP/tuple.h
@@ -48,33 +48,33 @@ template <typename... Ts> LIBC_INLINE constexpr auto tie(Ts &...args) {
   return tuple<Ts &...>(args...);
 }
 
-template <size_t I, typename Head, typename... Tail>
+template <size_t Idx, typename Head, typename... Tail>
 LIBC_INLINE constexpr auto &get(tuple<Head, Tail...> &t) {
-  if constexpr (I == 0)
+  if constexpr (Idx == 0)
     return t.get_head();
   else
-    return get<I - 1>(t.get_tail());
+    return get<Idx - 1>(t.get_tail());
 }
-template <size_t I, typename Head, typename... Tail>
+template <size_t Idx, typename Head, typename... Tail>
 LIBC_INLINE constexpr const auto &get(const tuple<Head, Tail...> &t) {
-  if constexpr (I == 0)
+  if constexpr (Idx == 0)
     return t.get_head();
   else
-    return get<I - 1>(t.get_tail());
+    return get<Idx - 1>(t.get_tail());
 }
-template <size_t I, typename Head, typename... Tail>
+template <size_t Idx, typename Head, typename... Tail>
 LIBC_INLINE constexpr auto &&get(tuple<Head, Tail...> &&t) {
-  if constexpr (I == 0)
+  if constexpr (Idx == 0)
     return static_cast<Head &&>(t.get_head());
   else
-    return get<I - 1>(static_cast<tuple<Tail...> &&>(t.get_tail()));
+    return get<Idx - 1>(static_cast<tuple<Tail...> &&>(t.get_tail()));
 }
-template <size_t I, typename Head, typename... Tail>
+template <size_t Idx, typename Head, typename... Tail>
 LIBC_INLINE constexpr const auto &&get(const tuple<Head, Tail...> &&t) {
-  if constexpr (I == 0)
+  if constexpr (Idx == 0)
     return static_cast<const Head &&>(t.get_head());
   else
-    return get<I - 1>(static_cast<const tuple<Tail...> &&>(t.get_tail()));
+    return get<Idx - 1>(static_cast<const tuple<Tail...> &&>(t.get_tail()));
 }
 
 template <typename T> struct tuple_size;
@@ -82,21 +82,21 @@ template <typename... Ts> struct tuple_size<tuple<Ts...>> {
   static constexpr size_t value = sizeof...(Ts);
 };
 
-template <size_t I, typename T> struct tuple_element;
-template <size_t I, typename Head, typename... Tail>
-struct tuple_element<I, tuple<Head, Tail...>>
-    : tuple_element<I - 1, tuple<Tail...>> {};
+template <size_t Idx, typename T> struct tuple_element;
+template <size_t Idx, typename Head, typename... Tail>
+struct tuple_element<Idx, tuple<Head, Tail...>>
+    : tuple_element<Idx - 1, tuple<Tail...>> {};
 template <typename Head, typename... Tail>
 struct tuple_element<0, tuple<Head, Tail...>> {
   using type = cpp::remove_cv_t<cpp::remove_reference_t<Head>>;
 };
 
 namespace internal {
-template <typename... As, typename... Bs, size_t... I, size_t... J>
+template <typename... As, typename... Bs, size_t... Idx, size_t... J>
 LIBC_INLINE constexpr auto
 tuple_cat(const tuple<As...> &a, const tuple<Bs...> &b,
-          cpp::index_sequence<I...>, cpp::index_sequence<J...>) {
-  return tuple<As..., Bs...>(get<I>(a)..., get<J>(b)...);
+          cpp::index_sequence<Idx...>, cpp::index_sequence<J...>) {
+  return tuple<As..., Bs...>(get<Idx>(a)..., get<J>(b)...);
 }
 
 template <typename First, typename Second, typename... Rest>
@@ -128,16 +128,16 @@ LIBC_INLINE constexpr auto tuple_cat(const Tuples &...tuples) {
 namespace std {
 
 template <class T> struct tuple_size;
-template <size_t I, class T> struct tuple_element;
+template <size_t Idx, class T> struct tuple_element;
 
 template <typename... Ts>
 struct tuple_size<LIBC_NAMESPACE::cpp::tuple<Ts...>>
     : LIBC_NAMESPACE::cpp::tuple_size<LIBC_NAMESPACE::cpp::tuple<Ts...>> {};
 
-template <size_t I, typename... Ts>
-struct tuple_element<I, LIBC_NAMESPACE::cpp::tuple<Ts...>>
-    : LIBC_NAMESPACE::cpp::tuple_element<I, LIBC_NAMESPACE::cpp::tuple<Ts...>> {
-};
+template <size_t Idx, typename... Ts>
+struct tuple_element<Idx, LIBC_NAMESPACE::cpp::tuple<Ts...>>
+    : LIBC_NAMESPACE::cpp::tuple_element<Idx,
+                                         LIBC_NAMESPACE::cpp::tuple<Ts...>> {};
 
 } // namespace std
 
diff --git a/libc/test/UnitTest/MemoryMatcher.cpp b/libc/test/UnitTest/MemoryMatcher.cpp
index 3cd5174fd7f75..6e375768e9333 100644
--- a/libc/test/UnitTest/MemoryMatcher.cpp
+++ b/libc/test/UnitTest/MemoryMatcher.cpp
@@ -40,9 +40,9 @@ bool MemoryMatcher::match(MemoryView actualValue) {
 }
 
 static void display(char C) {
-  const auto print = [](unsigned char I) {
+  const auto print = [](unsigned char i) {
     tlog << static_cast<char>(LIBC_NAMESPACE::internal::toupper(
-        LIBC_NAMESPACE::internal::int_to_b36_char(I)));
+        LIBC_NAMESPACE::internal::int_to_b36_char(i)));
   };
   print(static_cast<unsigned char>(C) / 16);
   print(static_cast<unsigned char>(C) & 15);
diff --git a/libc/test/integration/src/pthread/pthread_create_test.cpp b/libc/test/integration/src/pthread/pthread_create_test.cpp
index abd348e707c09..d436cc3270d9c 100644
--- a/libc/test/integration/src/pthread/pthread_create_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_create_test.cpp
@@ -108,14 +108,14 @@ static void *successThread(void *Arg) {
     volatile uint8_t *bytes_on_stack =
         (volatile uint8_t *)__builtin_alloca(test_stacksize);
 
-    for (size_t I = 0; I < test_stacksize; ++I) {
+    for (size_t i = 0; i < test_stacksize; ++i) {
       // Write permissions
-      bytes_on_stack[I] = static_cast<uint8_t>(I);
+      bytes_on_stack[i] = static_cast<uint8_t>(i);
     }
 
-    for (size_t I = 0; I < test_stacksize; ++I) {
+    for (size_t i = 0; i < test_stacksize; ++i) {
       // Read/write permissions
-      bytes_on_stack[I] += static_cast<uint8_t>(I);
+      bytes_on_stack[i] += static_cast<uint8_t>(i);
     }
   }
 
diff --git a/libc/test/src/math/smoke/RoundToIntegerTest.h b/libc/test/src/math/smoke/RoundToIntegerTest.h
index f8be5a5bcc737..c0b326e5dcbb0 100644
--- a/libc/test/src/math/smoke/RoundToIntegerTest.h
+++ b/libc/test/src/math/smoke/RoundToIntegerTest.h
@@ -22,25 +22,26 @@
 static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
                                           FE_TONEAREST};
 
-template <typename F, typename I, bool TestModes = false>
+template <typename FloatType, typename IntType, bool TestModes = false>
 class RoundToIntegerTestTemplate
     : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 public:
-  typedef I (*RoundToIntegerFunc)(F);
+  typedef IntType (*RoundToIntegerFunc)(FloatType);
 
 private:
-  DECLARE_SPECIAL_CONSTANTS(F)
+  DECLARE_SPECIAL_CONSTANTS(FloatType)
 
   static constexpr StorageType MAX_SUBNORMAL =
       FPBits::max_subnormal().uintval();
   static constexpr StorageType MIN_SUBNORMAL =
       FPBits::min_subnormal().uintval();
 
-  static constexpr I INTEGER_MIN = I(1) << (sizeof(I) * 8 - 1);
-  static constexpr I INTEGER_MAX = -(INTEGER_MIN + 1);
+  static constexpr IntType INTEGER_MIN = IntType(1)
+                                         << (sizeof(IntType) * 8 - 1);
+  static constexpr IntType INTEGER_MAX = -(INTEGER_MIN + 1);
 
-  void test_one_input(RoundToIntegerFunc func, F input, I expected,
-                      bool expectError) {
+  void test_one_input(RoundToIntegerFunc func, FloatType input,
+                      IntType expected, bool expectError) {
     libc_errno = 0;
     LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
 
@@ -92,14 +93,14 @@ class RoundToIntegerTestTemplate
   }
 
   void do_round_numbers_test(RoundToIntegerFunc func) {
-    test_one_input(func, zero, I(0), false);
-    test_one_input(func, neg_zero, I(0), false);
-    test_one_input(func, F(1.0), I(1), false);
-    test_one_input(func, F(-1.0), I(-1), false);
-    test_one_input(func, F(10.0), I(10), false);
-    test_one_input(func, F(-10.0), I(-10), false);
-    test_one_input(func, F(1232.0), I(1232), false);
-    test_one_input(func, F(-1232.0), I(-1232), false);
+    test_one_input(func, zero, IntType(0), false);
+    test_one_input(func, neg_zero, IntType(0), false);
+    test_one_input(func, FloatType(1.0), IntType(1), false);
+    test_one_input(func, FloatType(-1.0), IntType(-1), false);
+    test_one_input(func, FloatType(10.0), IntType(10), false);
+    test_one_input(func, FloatType(-10.0), IntType(-10), false);
+    test_one_input(func, FloatType(1232.0), IntType(1232), false);
+    test_one_input(func, FloatType(-1232.0), IntType(-1232), false);
   }
 
   void testRoundNumbers(RoundToIntegerFunc func) {
@@ -120,29 +121,29 @@ class RoundToIntegerTestTemplate
         static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
         StorageType(1));
     for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
-      F x = FPBits(i).get_val();
-      if (x == F(0.0))
+      FloatType x = FPBits(i).get_val();
+      if (x == FloatType(0.0))
         continue;
       // All subnormal numbers should round to zero.
       if (TestModes) {
         if (x > zero) {
           LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
-          test_one_input(func, x, I(1), false);
+          test_one_input(func, x, IntType(1), false);
           LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
-          test_one_input(func, x, I(0), false);
+          test_one_input(func, x, IntType(0), false);
           LIBC_NAMESPACE::fputil::set_round(FE_TOWARDZERO);
-          test_one_input(func, x, I(0), false);
+          test_one_input(func, x, IntType(0), false);
           LIBC_NAMESPACE::fputil::set_round(FE_TONEAREST);
-          test_one_input(func, x, I(0), false);
+          test_one_input(func, x, IntType(0), false);
         } else {
           LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
-          test_one_input(func, x, I(0), false);
+          test_one_input(func, x, IntType(0), false);
           LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
-          test_one_input(func, x, I(-1), false);
+          test_one_input(func, x, IntType(-1), false);
           LIBC_NAMESPACE::fputil::set_round(FE_TOWARDZERO);
-          test_one_input(func, x, I(0), false);
+          test_one_input(func, x, IntType(0), false);
           LIBC_NAMESPACE::fputil::set_round(FE_TONEAREST);
-          test_one_input(func, x, I(0), false);
+          test_one_input(func, x, IntType(0), false);
         }
       } else {
         test_one_input(func, x, 0L, false);
@@ -151,9 +152,10 @@ class RoundToIntegerTestTemplate
   }
 };
 
-#define LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, TestModes)              \
+#define LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func,           \
+                                           TestModes)                          \
   using LlvmLibcRoundToIntegerTest =                                           \
-      RoundToIntegerTestTemplate<F, I, TestModes>;                             \
+      RoundToIntegerTestTemplate<FloatType, IntType, TestModes>;               \
   TEST_F(LlvmLibcRoundToIntegerTest, InfinityAndNaN) {                         \
     testInfinityAndNaN(&func);                                                 \
   }                                                                            \
@@ -164,16 +166,16 @@ class RoundToIntegerTestTemplate
     testSubnormalRange(&func);                                                 \
   }
 
-#define LIST_ROUND_TO_INTEGER_TESTS(F, I, func)                                \
-  LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false)
+#define LIST_ROUND_TO_INTEGER_TESTS(FloatType, IntType, func)                  \
+  LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, false)
 
 // The GPU target does not support different rounding modes.
 #ifdef LIBC_TARGET_ARCH_IS_GPU
-#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func)                     \
-  LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false)
+#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(FloatType, IntType, func)       \
+  LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, false)
 #else
-#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func)                     \
-  LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, true)
+#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(FloatType, IntType, func)       \
+  LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, true)
 #endif
 
 #endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H
diff --git a/libc/test/src/string/memory_utils/utils_test.cpp b/libc/test/src/string/memory_utils/utils_test.cpp
index 4dff0684b9111..2ab2e8d3ad867 100644
--- a/libc/test/src/string/memory_utils/utils_test.cpp
+++ b/libc/test/src/string/memory_utils/utils_test.cpp
@@ -47,14 +47,14 @@ TEST(LlvmLibcUtilsTest, DistanceToAlignDown) {
 TEST(LlvmLibcUtilsTest, Adjust2) {
   char a, b;
   const size_t base_size = 10;
-  for (uintptr_t I = 0; I < 4; ++I) {
+  for (uintptr_t i = 0; i < 4; ++i) {
     auto *p1 = &a;
     auto *p2 = &b;
     size_t size = base_size;
-    adjust(static_cast<ptrdiff_t>(I), p1, p2, size);
-    EXPECT_EQ(intptr_t(p1), intptr_t(&a + I));
-    EXPECT_EQ(intptr_t(p2), intptr_t(&b + I));
-    EXPECT_EQ(size, base_size - I);
+    adjust(static_cast<ptrdiff_t>(i), p1, p2, size);
+    EXPECT_EQ(intptr_t(p1), intptr_t(&a + i));
+    EXPECT_EQ(intptr_t(p2), intptr_t(&b + i));
+    EXPECT_EQ(size, base_size - i);
   }
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/160567


More information about the libc-commits mailing list