[libc-commits] [libc] d6bbe2e - [libc] Fix definition of `UINT_MAX` in limits.h (#95279)
via libc-commits
libc-commits at lists.llvm.org
Wed Jun 12 13:29:13 PDT 2024
Author: Joseph Huber
Date: 2024-06-12T15:29:10-05:00
New Revision: d6bbe2e20ff21cc2d31106742dfe1711ae5c641e
URL: https://github.com/llvm/llvm-project/commit/d6bbe2e20ff21cc2d31106742dfe1711ae5c641e
DIFF: https://github.com/llvm/llvm-project/commit/d6bbe2e20ff21cc2d31106742dfe1711ae5c641e.diff
LOG: [libc] Fix definition of `UINT_MAX` in limits.h (#95279)
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.
Added:
Modified:
libc/include/llvm-libc-macros/limits-macros.h
Removed:
################################################################################
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
More information about the libc-commits
mailing list