Skip to content

Commit d6bbe2e

Browse files
authored
[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.
1 parent 0cb2ae3 commit d6bbe2e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libc/include/llvm-libc-macros/limits-macros.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
#endif // INT_MAX
149149

150150
#ifndef UINT_MAX
151-
#define UINT_MAX (~0U)
151+
#define UINT_MAX (INT_MAX * 2U + 1U)
152152
#endif // UINT_MAX
153153

154154
#ifndef LONG_MAX
@@ -160,7 +160,7 @@
160160
#endif // LONG_MAX
161161

162162
#ifndef ULONG_MAX
163-
#define ULONG_MAX (~0UL)
163+
#define ULONG_MAX (LONG_MAX * 2UL + 1UL)
164164
#endif // ULONG_MAX
165165

166166
#ifndef LLONG_MAX
@@ -172,7 +172,7 @@
172172
#endif // LLONG_MAX
173173

174174
#ifndef ULLONG_MAX
175-
#define ULLONG_MAX (~0ULL)
175+
#define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
176176
#endif // ULLONG_MAX
177177

178178
// *_MIN macros

0 commit comments

Comments
 (0)