[libc-commits] [libc] [libc] Fix use of cpp::numeric_limits<...>::digits (PR #102674)
via libc-commits
libc-commits at lists.llvm.org
Fri Aug 9 13:07:18 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Roland McGrath (frobtech)
<details>
<summary>Changes</summary>
The previous change replaced INT_WIDTH with
cpp::numberic_limits<int>::digits, but these don't have the same
value. While INT_WIDTH == UINT_WIDTH, not so for ::digits, so
use cpp::numberic_limits<unsigned int>::digits et al instead for
the intended effects.
Bug: https://issues.fuchsia.dev/358196552
---
Full diff: https://github.com/llvm/llvm-project/pull/102674.diff
2 Files Affected:
- (modified) libc/src/stdio/printf_core/parser.h (+3-3)
- (modified) libc/test/src/stdbit/stdc_leading_zeros_ui_test.cpp (+7-6)
``````````diff
diff --git a/libc/src/stdio/printf_core/parser.h b/libc/src/stdio/printf_core/parser.h
index 9a3f19a919744..684911a567569 100644
--- a/libc/src/stdio/printf_core/parser.h
+++ b/libc/src/stdio/printf_core/parser.h
@@ -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);
diff --git a/libc/test/src/stdbit/stdc_leading_zeros_ui_test.cpp b/libc/test/src/stdbit/stdc_leading_zeros_ui_test.cpp
index f1b8363ecc8f7..c047457cc82e5 100644
--- a/libc/test/src/stdbit/stdc_leading_zeros_ui_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_zeros_ui_test.cpp
@@ -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);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/102674
More information about the libc-commits
mailing list