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

This commit is contained in:
lntue 2025-09-24 14:18:32 -04:00 committed by GitHub
parent ce170d28ad
commit 3c53adec68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 78 additions and 76 deletions

View File

@ -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 =

View File

@ -161,11 +161,11 @@ private:
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';
}

View File

@ -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)));
}

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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 @@ public:
}
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 @@ public:
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 @@ public:
}
};
#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 @@ public:
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

View File

@ -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);
}
}