Skip to content

Commit 3c53ade

Browse files
authored
[libc][NFC] Remove usage of the C keyword I. (#160567)
1 parent ce170d2 commit 3c53ade

File tree

8 files changed

+78
-76
lines changed

8 files changed

+78
-76
lines changed

libc/benchmarks/LibcMemoryBenchmark.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ MismatchOffsetDistribution::MismatchOffsetDistribution(size_t BufferSize,
5353
: MismatchAt(MismatchAt) {
5454
if (MismatchAt <= 1)
5555
return;
56-
for (size_t I = MaxSizeValue + 1; I < BufferSize; I += MaxSizeValue)
57-
MismatchIndices.push_back(I);
56+
for (size_t i = MaxSizeValue + 1; i < BufferSize; i += MaxSizeValue)
57+
MismatchIndices.push_back(i);
5858
if (MismatchIndices.empty())
5959
report_fatal_error("Unable to generate mismatch");
6060
MismatchIndexSelector =

libc/benchmarks/LibcMemoryBenchmarkMain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ struct MemfunctionBenchmarkBase : public BenchmarkSetup {
161161
if (Percent == LastPercent)
162162
return;
163163
LastPercent = Percent;
164-
size_t I = 0;
164+
size_t i = 0;
165165
errs() << '[';
166-
for (; I <= Percent; ++I)
166+
for (; i <= Percent; ++i)
167167
errs() << '#';
168-
for (; I <= 100; ++I)
168+
for (; i <= 100; ++i)
169169
errs() << '_';
170170
errs() << "] " << Percent << '%' << '\r';
171171
}

libc/benchmarks/LibcMemoryBenchmarkTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ TEST(OffsetDistribution, AlignToBegin) {
3838
const size_t BufferSize = 8192;
3939
OffsetDistribution OD(BufferSize, 1024, std::nullopt);
4040
std::default_random_engine Gen;
41-
for (size_t I = 0; I <= 10; ++I)
41+
for (size_t i = 0; i <= 10; ++i)
4242
EXPECT_EQ(OD(Gen), 0U);
4343
}
4444

4545
TEST(OffsetDistribution, NoAlignment) {
4646
const size_t BufferSize = 8192;
4747
OffsetDistribution OD(BufferSize, 1, Align(1));
4848
std::default_random_engine Gen;
49-
for (size_t I = 0; I <= 10; ++I)
49+
for (size_t i = 0; i <= 10; ++i)
5050
EXPECT_THAT(OD(Gen), AllOf(Ge(0U), Lt(8192U)));
5151
}
5252

@@ -59,7 +59,7 @@ TEST(OffsetDistribution, Aligned) {
5959
const size_t BufferSize = 8192;
6060
OffsetDistribution OD(BufferSize, 1, Align(16));
6161
std::default_random_engine Gen;
62-
for (size_t I = 0; I <= 10; ++I)
62+
for (size_t i = 0; i <= 10; ++i)
6363
EXPECT_THAT(OD(Gen), AllOf(Ge(0U), Lt(8192U), IsDivisibleBy(16U)));
6464
}
6565

libc/src/__support/CPP/tuple.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,55 +48,55 @@ template <typename... Ts> LIBC_INLINE constexpr auto tie(Ts &...args) {
4848
return tuple<Ts &...>(args...);
4949
}
5050

51-
template <size_t I, typename Head, typename... Tail>
51+
template <size_t Idx, typename Head, typename... Tail>
5252
LIBC_INLINE constexpr auto &get(tuple<Head, Tail...> &t) {
53-
if constexpr (I == 0)
53+
if constexpr (Idx == 0)
5454
return t.get_head();
5555
else
56-
return get<I - 1>(t.get_tail());
56+
return get<Idx - 1>(t.get_tail());
5757
}
58-
template <size_t I, typename Head, typename... Tail>
58+
template <size_t Idx, typename Head, typename... Tail>
5959
LIBC_INLINE constexpr const auto &get(const tuple<Head, Tail...> &t) {
60-
if constexpr (I == 0)
60+
if constexpr (Idx == 0)
6161
return t.get_head();
6262
else
63-
return get<I - 1>(t.get_tail());
63+
return get<Idx - 1>(t.get_tail());
6464
}
65-
template <size_t I, typename Head, typename... Tail>
65+
template <size_t Idx, typename Head, typename... Tail>
6666
LIBC_INLINE constexpr auto &&get(tuple<Head, Tail...> &&t) {
67-
if constexpr (I == 0)
67+
if constexpr (Idx == 0)
6868
return static_cast<Head &&>(t.get_head());
6969
else
70-
return get<I - 1>(static_cast<tuple<Tail...> &&>(t.get_tail()));
70+
return get<Idx - 1>(static_cast<tuple<Tail...> &&>(t.get_tail()));
7171
}
72-
template <size_t I, typename Head, typename... Tail>
72+
template <size_t Idx, typename Head, typename... Tail>
7373
LIBC_INLINE constexpr const auto &&get(const tuple<Head, Tail...> &&t) {
74-
if constexpr (I == 0)
74+
if constexpr (Idx == 0)
7575
return static_cast<const Head &&>(t.get_head());
7676
else
77-
return get<I - 1>(static_cast<const tuple<Tail...> &&>(t.get_tail()));
77+
return get<Idx - 1>(static_cast<const tuple<Tail...> &&>(t.get_tail()));
7878
}
7979

8080
template <typename T> struct tuple_size;
8181
template <typename... Ts> struct tuple_size<tuple<Ts...>> {
8282
static constexpr size_t value = sizeof...(Ts);
8383
};
8484

85-
template <size_t I, typename T> struct tuple_element;
86-
template <size_t I, typename Head, typename... Tail>
87-
struct tuple_element<I, tuple<Head, Tail...>>
88-
: tuple_element<I - 1, tuple<Tail...>> {};
85+
template <size_t Idx, typename T> struct tuple_element;
86+
template <size_t Idx, typename Head, typename... Tail>
87+
struct tuple_element<Idx, tuple<Head, Tail...>>
88+
: tuple_element<Idx - 1, tuple<Tail...>> {};
8989
template <typename Head, typename... Tail>
9090
struct tuple_element<0, tuple<Head, Tail...>> {
9191
using type = cpp::remove_cv_t<cpp::remove_reference_t<Head>>;
9292
};
9393

9494
namespace internal {
95-
template <typename... As, typename... Bs, size_t... I, size_t... J>
95+
template <typename... As, typename... Bs, size_t... Idx, size_t... J>
9696
LIBC_INLINE constexpr auto
9797
tuple_cat(const tuple<As...> &a, const tuple<Bs...> &b,
98-
cpp::index_sequence<I...>, cpp::index_sequence<J...>) {
99-
return tuple<As..., Bs...>(get<I>(a)..., get<J>(b)...);
98+
cpp::index_sequence<Idx...>, cpp::index_sequence<J...>) {
99+
return tuple<As..., Bs...>(get<Idx>(a)..., get<J>(b)...);
100100
}
101101

102102
template <typename First, typename Second, typename... Rest>
@@ -128,16 +128,16 @@ LIBC_INLINE constexpr auto tuple_cat(const Tuples &...tuples) {
128128
namespace std {
129129

130130
template <class T> struct tuple_size;
131-
template <size_t I, class T> struct tuple_element;
131+
template <size_t Idx, class T> struct tuple_element;
132132

133133
template <typename... Ts>
134134
struct tuple_size<LIBC_NAMESPACE::cpp::tuple<Ts...>>
135135
: LIBC_NAMESPACE::cpp::tuple_size<LIBC_NAMESPACE::cpp::tuple<Ts...>> {};
136136

137-
template <size_t I, typename... Ts>
138-
struct tuple_element<I, LIBC_NAMESPACE::cpp::tuple<Ts...>>
139-
: LIBC_NAMESPACE::cpp::tuple_element<I, LIBC_NAMESPACE::cpp::tuple<Ts...>> {
140-
};
137+
template <size_t Idx, typename... Ts>
138+
struct tuple_element<Idx, LIBC_NAMESPACE::cpp::tuple<Ts...>>
139+
: LIBC_NAMESPACE::cpp::tuple_element<Idx,
140+
LIBC_NAMESPACE::cpp::tuple<Ts...>> {};
141141

142142
} // namespace std
143143

libc/test/UnitTest/MemoryMatcher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ bool MemoryMatcher::match(MemoryView actualValue) {
4040
}
4141

4242
static void display(char C) {
43-
const auto print = [](unsigned char I) {
43+
const auto print = [](unsigned char i) {
4444
tlog << static_cast<char>(LIBC_NAMESPACE::internal::toupper(
45-
LIBC_NAMESPACE::internal::int_to_b36_char(I)));
45+
LIBC_NAMESPACE::internal::int_to_b36_char(i)));
4646
};
4747
print(static_cast<unsigned char>(C) / 16);
4848
print(static_cast<unsigned char>(C) & 15);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ static void *successThread(void *Arg) {
108108
volatile uint8_t *bytes_on_stack =
109109
(volatile uint8_t *)__builtin_alloca(test_stacksize);
110110

111-
for (size_t I = 0; I < test_stacksize; ++I) {
111+
for (size_t i = 0; i < test_stacksize; ++i) {
112112
// Write permissions
113-
bytes_on_stack[I] = static_cast<uint8_t>(I);
113+
bytes_on_stack[i] = static_cast<uint8_t>(i);
114114
}
115115

116-
for (size_t I = 0; I < test_stacksize; ++I) {
116+
for (size_t i = 0; i < test_stacksize; ++i) {
117117
// Read/write permissions
118-
bytes_on_stack[I] += static_cast<uint8_t>(I);
118+
bytes_on_stack[i] += static_cast<uint8_t>(i);
119119
}
120120
}
121121

libc/test/src/math/smoke/RoundToIntegerTest.h

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,26 @@
2222
static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
2323
FE_TONEAREST};
2424

25-
template <typename F, typename I, bool TestModes = false>
25+
template <typename FloatType, typename IntType, bool TestModes = false>
2626
class RoundToIntegerTestTemplate
2727
: public LIBC_NAMESPACE::testing::FEnvSafeTest {
2828
public:
29-
typedef I (*RoundToIntegerFunc)(F);
29+
typedef IntType (*RoundToIntegerFunc)(FloatType);
3030

3131
private:
32-
DECLARE_SPECIAL_CONSTANTS(F)
32+
DECLARE_SPECIAL_CONSTANTS(FloatType)
3333

3434
static constexpr StorageType MAX_SUBNORMAL =
3535
FPBits::max_subnormal().uintval();
3636
static constexpr StorageType MIN_SUBNORMAL =
3737
FPBits::min_subnormal().uintval();
3838

39-
static constexpr I INTEGER_MIN = I(1) << (sizeof(I) * 8 - 1);
40-
static constexpr I INTEGER_MAX = -(INTEGER_MIN + 1);
39+
static constexpr IntType INTEGER_MIN = IntType(1)
40+
<< (sizeof(IntType) * 8 - 1);
41+
static constexpr IntType INTEGER_MAX = -(INTEGER_MIN + 1);
4142

42-
void test_one_input(RoundToIntegerFunc func, F input, I expected,
43-
bool expectError) {
43+
void test_one_input(RoundToIntegerFunc func, FloatType input,
44+
IntType expected, bool expectError) {
4445
libc_errno = 0;
4546
LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
4647

@@ -92,14 +93,14 @@ class RoundToIntegerTestTemplate
9293
}
9394

9495
void do_round_numbers_test(RoundToIntegerFunc func) {
95-
test_one_input(func, zero, I(0), false);
96-
test_one_input(func, neg_zero, I(0), false);
97-
test_one_input(func, F(1.0), I(1), false);
98-
test_one_input(func, F(-1.0), I(-1), false);
99-
test_one_input(func, F(10.0), I(10), false);
100-
test_one_input(func, F(-10.0), I(-10), false);
101-
test_one_input(func, F(1232.0), I(1232), false);
102-
test_one_input(func, F(-1232.0), I(-1232), false);
96+
test_one_input(func, zero, IntType(0), false);
97+
test_one_input(func, neg_zero, IntType(0), false);
98+
test_one_input(func, FloatType(1.0), IntType(1), false);
99+
test_one_input(func, FloatType(-1.0), IntType(-1), false);
100+
test_one_input(func, FloatType(10.0), IntType(10), false);
101+
test_one_input(func, FloatType(-10.0), IntType(-10), false);
102+
test_one_input(func, FloatType(1232.0), IntType(1232), false);
103+
test_one_input(func, FloatType(-1232.0), IntType(-1232), false);
103104
}
104105

105106
void testRoundNumbers(RoundToIntegerFunc func) {
@@ -120,29 +121,29 @@ class RoundToIntegerTestTemplate
120121
static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
121122
StorageType(1));
122123
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
123-
F x = FPBits(i).get_val();
124-
if (x == F(0.0))
124+
FloatType x = FPBits(i).get_val();
125+
if (x == FloatType(0.0))
125126
continue;
126127
// All subnormal numbers should round to zero.
127128
if (TestModes) {
128129
if (x > zero) {
129130
LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
130-
test_one_input(func, x, I(1), false);
131+
test_one_input(func, x, IntType(1), false);
131132
LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
132-
test_one_input(func, x, I(0), false);
133+
test_one_input(func, x, IntType(0), false);
133134
LIBC_NAMESPACE::fputil::set_round(FE_TOWARDZERO);
134-
test_one_input(func, x, I(0), false);
135+
test_one_input(func, x, IntType(0), false);
135136
LIBC_NAMESPACE::fputil::set_round(FE_TONEAREST);
136-
test_one_input(func, x, I(0), false);
137+
test_one_input(func, x, IntType(0), false);
137138
} else {
138139
LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
139-
test_one_input(func, x, I(0), false);
140+
test_one_input(func, x, IntType(0), false);
140141
LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
141-
test_one_input(func, x, I(-1), false);
142+
test_one_input(func, x, IntType(-1), false);
142143
LIBC_NAMESPACE::fputil::set_round(FE_TOWARDZERO);
143-
test_one_input(func, x, I(0), false);
144+
test_one_input(func, x, IntType(0), false);
144145
LIBC_NAMESPACE::fputil::set_round(FE_TONEAREST);
145-
test_one_input(func, x, I(0), false);
146+
test_one_input(func, x, IntType(0), false);
146147
}
147148
} else {
148149
test_one_input(func, x, 0L, false);
@@ -151,9 +152,10 @@ class RoundToIntegerTestTemplate
151152
}
152153
};
153154

154-
#define LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, TestModes) \
155+
#define LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, \
156+
TestModes) \
155157
using LlvmLibcRoundToIntegerTest = \
156-
RoundToIntegerTestTemplate<F, I, TestModes>; \
158+
RoundToIntegerTestTemplate<FloatType, IntType, TestModes>; \
157159
TEST_F(LlvmLibcRoundToIntegerTest, InfinityAndNaN) { \
158160
testInfinityAndNaN(&func); \
159161
} \
@@ -164,16 +166,16 @@ class RoundToIntegerTestTemplate
164166
testSubnormalRange(&func); \
165167
}
166168

167-
#define LIST_ROUND_TO_INTEGER_TESTS(F, I, func) \
168-
LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false)
169+
#define LIST_ROUND_TO_INTEGER_TESTS(FloatType, IntType, func) \
170+
LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, false)
169171

170172
// The GPU target does not support different rounding modes.
171173
#ifdef LIBC_TARGET_ARCH_IS_GPU
172-
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func) \
173-
LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false)
174+
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(FloatType, IntType, func) \
175+
LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, false)
174176
#else
175-
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func) \
176-
LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, true)
177+
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(FloatType, IntType, func) \
178+
LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, true)
177179
#endif
178180

179181
#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H

libc/test/src/string/memory_utils/utils_test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ TEST(LlvmLibcUtilsTest, DistanceToAlignDown) {
4747
TEST(LlvmLibcUtilsTest, Adjust2) {
4848
char a, b;
4949
const size_t base_size = 10;
50-
for (uintptr_t I = 0; I < 4; ++I) {
50+
for (uintptr_t i = 0; i < 4; ++i) {
5151
auto *p1 = &a;
5252
auto *p2 = &b;
5353
size_t size = base_size;
54-
adjust(static_cast<ptrdiff_t>(I), p1, p2, size);
55-
EXPECT_EQ(intptr_t(p1), intptr_t(&a + I));
56-
EXPECT_EQ(intptr_t(p2), intptr_t(&b + I));
57-
EXPECT_EQ(size, base_size - I);
54+
adjust(static_cast<ptrdiff_t>(i), p1, p2, size);
55+
EXPECT_EQ(intptr_t(p1), intptr_t(&a + i));
56+
EXPECT_EQ(intptr_t(p2), intptr_t(&b + i));
57+
EXPECT_EQ(size, base_size - i);
5858
}
5959
}
6060

0 commit comments

Comments
 (0)