[libc-commits] [libc] [libc] Fix definition of `UINT_MAX` in limits.h (PR #95279)
via libc-commits
libc-commits at lists.llvm.org
Wed Jun 12 10:51:34 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Joseph Huber (jhuber6)
<details>
<summary>Changes</summary>
Summary:
Currently we use `(~0U)` for this definition, however the ~ operator
returns a different sign, meaning that preprocessor checks against this
value will fail. See https://godbolt.org/z/TrjaY1d8q where the
preprocessor thinks that it's not `0xffffffff` while the static
assertion thinks it is. This is because the latter does implicit
conversion but the preprocessor does not. This is now consistent with
other headers.
---
Full diff: https://github.com/llvm/llvm-project/pull/95279.diff
1 Files Affected:
- (modified) libc/include/llvm-libc-macros/limits-macros.h (+3-3)
``````````diff
diff --git a/libc/include/llvm-libc-macros/limits-macros.h b/libc/include/llvm-libc-macros/limits-macros.h
index 95f0f5f0baa58..3fab996b61ac9 100644
--- a/libc/include/llvm-libc-macros/limits-macros.h
+++ b/libc/include/llvm-libc-macros/limits-macros.h
@@ -148,7 +148,7 @@
#endif // INT_MAX
#ifndef UINT_MAX
-#define UINT_MAX (~0U)
+#define UINT_MAX (INT_MAX * 2U + 1U)
#endif // UINT_MAX
#ifndef LONG_MAX
@@ -160,7 +160,7 @@
#endif // LONG_MAX
#ifndef ULONG_MAX
-#define ULONG_MAX (~0UL)
+#define ULONG_MAX (LONG_MAX * 2UL + 1UL)
#endif // ULONG_MAX
#ifndef LLONG_MAX
@@ -172,7 +172,7 @@
#endif // LLONG_MAX
#ifndef ULLONG_MAX
-#define ULLONG_MAX (~0ULL)
+#define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
#endif // ULLONG_MAX
// *_MIN macros
``````````
</details>
https://github.com/llvm/llvm-project/pull/95279
More information about the libc-commits
mailing list