Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] Fix use of cpp::numeric_limits<...>::digits #102674

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libc/src/stdio/printf_core/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ template <typename ArgProvider> class Parser {
case (LengthModifier::wf):
if (bw == 0) {
section.has_conv = false;
} else if (bw <= cpp::numeric_limits<int>::digits) {
} else if (bw <= cpp::numeric_limits<unsigned int>::digits) {
WRITE_ARG_VAL_SIMPLEST(section.conv_val_raw, int, conv_index);
} else if (bw <= cpp::numeric_limits<long>::digits) {
} else if (bw <= cpp::numeric_limits<unsigned long>::digits) {
WRITE_ARG_VAL_SIMPLEST(section.conv_val_raw, long, conv_index);
} else if (bw <= cpp::numeric_limits<long long>::digits) {
} else if (bw <= cpp::numeric_limits<unsigned long long>::digits) {
WRITE_ARG_VAL_SIMPLEST(section.conv_val_raw, long long, conv_index);
} else {
WRITE_ARG_VAL_SIMPLEST(section.conv_val_raw, intmax_t, conv_index);
Expand Down
13 changes: 7 additions & 6 deletions libc/test/src/stdbit/stdc_leading_zeros_ui_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#include <stddef.h>

TEST(LlvmLibcStdcLeadingZerosUiTest, Zero) {
EXPECT_EQ(
LIBC_NAMESPACE::stdc_leading_zeros_ui(0U),
static_cast<unsigned>(LIBC_NAMESPACE::cpp::numeric_limits<int>::digits));
EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_ui(0U),
static_cast<unsigned>(
LIBC_NAMESPACE::cpp::numeric_limits<unsigned int>::digits));
}

TEST(LlvmLibcStdcLeadingZerosUiTest, OneHot) {
for (unsigned i = 0U; i != LIBC_NAMESPACE::cpp::numeric_limits<int>::digits;
++i)
for (unsigned i = 0U;
i != LIBC_NAMESPACE::cpp::numeric_limits<unsigned int>::digits; ++i)
EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_ui(1U << i),
LIBC_NAMESPACE::cpp::numeric_limits<int>::digits - i - 1);
LIBC_NAMESPACE::cpp::numeric_limits<unsigned int>::digits - i -
1);
}
Loading