-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Add C23 limits.h header. #78887
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
53df4d8
[libc] Add limits.h header.
lntue 732feb4
Address comments.
lntue 7f22474
Add extra check to see if char is unsigned.
lntue 38ac968
Fix unsigned char check condition.
lntue 5a5195a
Use pragma clang for clang-only diagnostic.
lntue fbcafe9
Add extra checks for limits.h header when building with gcc.
lntue d620a88
Simplify macro checks.
lntue 50db524
Update comments.
lntue b03ddf3
Distinguish clang and gcc before setting _GCC_LIMITS_H_.
lntue 241f16e
Sync and remove all internal usage of `#include <limits.h>`.
lntue 4635eae
Remove #include_next <limits.h>
lntue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//===-- C standard library header limits.h --------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_LIMITS_H | ||
#define LLVM_LIBC_LIMITS_H | ||
|
||
#include <llvm-libc-macros/limits-macros.h> | ||
|
||
#endif // LLVM_LIBC_LIMITS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
//===-- Definition of macros from limits.h --------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef __LLVM_LIBC_MACROS_LIMITS_MACROS_H | ||
#define __LLVM_LIBC_MACROS_LIMITS_MACROS_H | ||
|
||
// Define all C23 macro constants of limits.h | ||
|
||
#ifndef CHAR_BIT | ||
#ifdef __CHAR_BIT__ | ||
#define CHAR_BIT __CHAR_BIT__ | ||
#else | ||
#define CHAR_BIT 8 | ||
#endif // __CHAR_BIT__ | ||
#endif // CHAR_BIT | ||
|
||
// TODO: https://github.com/llvm/llvm-project/issues/79358 | ||
// Define MB_LEN_MAX if missing. | ||
// clang: MB_LEN_MAX = 1 - | ||
// https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/limits.h#L64 | ||
// glibc: MB_LEN_MAX = 16 - | ||
// https://github.com/bminor/glibc/blob/master/include/limits.h#L32 | ||
|
||
// *_WIDTH macros | ||
|
||
#ifndef CHAR_WIDTH | ||
#define CHAR_WIDTH CHAR_BIT | ||
#endif // CHAR_WIDTH | ||
|
||
#ifndef SCHAR_WIDTH | ||
#define SCHAR_WIDTH CHAR_BIT | ||
#endif // SCHAR_WIDTH | ||
|
||
#ifndef UCHAR_WIDTH | ||
#define UCHAR_WIDTH CHAR_BIT | ||
#endif // UCHAR_WIDTH | ||
|
||
#ifndef SHRT_WIDTH | ||
#ifdef __SHRT_WIDTH__ | ||
#define SHRT_WIDTH __SHRT_WIDTH__ | ||
#else | ||
#define SHRT_WIDTH 16 | ||
#endif // __SHRT_WIDTH__ | ||
#endif // SHRT_WIDTH | ||
|
||
#ifndef USHRT_WIDTH | ||
#define USHRT_WIDTH SHRT_WIDTH | ||
#endif // USHRT_WIDTH | ||
|
||
#ifndef INT_WIDTH | ||
#ifdef __INT_WIDTH__ | ||
#define INT_WIDTH __INT_WIDTH__ | ||
#else | ||
#define INT_WIDTH 32 | ||
#endif // __INT_WIDTH__ | ||
#endif // INT_WIDTH | ||
|
||
#ifndef UINT_WIDTH | ||
#define UINT_WIDTH INT_WIDTH | ||
#endif // UINT_WIDTH | ||
|
||
#ifndef LONG_WIDTH | ||
#ifdef __LONG_WIDTH__ | ||
#define LONG_WIDTH __LONG_WIDTH__ | ||
#elif defined(__WORDSIZE) | ||
#define LONG_WIDTH __WORDSIZE | ||
#else | ||
#error "Unknown WORDSIZE to define LONG_WIDTH." | ||
#endif // __LONG_WIDTH__ | ||
#endif // LONG_WIDTH | ||
|
||
#ifndef ULONG_WIDTH | ||
#define ULONG_WIDTH LONG_WIDTH | ||
#endif // ULONG_WIDTH | ||
|
||
#ifndef LLONG_WIDTH | ||
#ifdef __LLONG_WIDTH__ | ||
#define LLONG_WIDTH __LLONG_WIDTH__ | ||
#else | ||
#define LLONG_WIDTH 64 | ||
#endif // __LLONG_WIDTH__ | ||
#endif // LLONG_WIDTH | ||
|
||
#ifndef ULLONG_WIDTH | ||
#define ULLONG_WIDTH LLONG_WIDTH | ||
#endif // ULLONG_WIDTH | ||
|
||
#ifndef BOOL_WIDTH | ||
#ifdef __BOOL_WIDTH__ | ||
#define BOOL_WIDTH __BOOL_WIDTH__ | ||
#else | ||
#define BOOL_WIDTH 1 | ||
#endif // __BOOL_WIDTH__ | ||
#endif // BOOL_WIDTH | ||
|
||
// *_MAX macros | ||
|
||
#ifndef SCHAR_MAX | ||
#ifdef __SCHAR_MAX__ | ||
#define SCHAR_MAX __SCHAR_MAX__ | ||
#else | ||
#define SCHAR_MAX 0x7f | ||
#endif // __SCHAR_MAX__ | ||
#endif // SCHAR_MAX | ||
|
||
#ifndef UCHAR_MAX | ||
#define UCHAR_MAX (SCHAR_MAX * 2 + 1) | ||
#endif // UCHAR_MAX | ||
|
||
// Check if char is unsigned. | ||
#if !defined(__CHAR_UNSIGNED__) && ('\xff' > 0) | ||
#define __CHAR_UNSIGNED__ | ||
#endif | ||
|
||
#ifndef CHAR_MAX | ||
#ifdef __CHAR_UNSIGNED__ | ||
SchrodingerZhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#define CHAR_MAX UCHAR_MAX | ||
#else | ||
#define CHAR_MAX SCHAR_MAX | ||
#endif // __CHAR_UNSIGNED__ | ||
#endif // CHAR_MAX | ||
|
||
#ifndef SHRT_MAX | ||
#ifdef __SHRT_MAX__ | ||
#define SHRT_MAX __SHRT_MAX__ | ||
#else | ||
#define SHRT_MAX 0x7fff | ||
#endif // __SHRT_MAX__ | ||
#endif // SHRT_MAX | ||
|
||
#ifndef USHRT_MAX | ||
#define USHRT_MAX (SHRT_MAX * 2U + 1U) | ||
#endif // USHRT_MAX | ||
|
||
#ifndef INT_MAX | ||
#ifdef __INT_MAX__ | ||
#define INT_MAX __INT_MAX__ | ||
#else | ||
#define INT_MAX (0 ^ (1 << (INT_WIDTH - 1))) | ||
#endif // __INT_MAX__ | ||
#endif // INT_MAX | ||
|
||
#ifndef UINT_MAX | ||
#define UINT_MAX (~0U) | ||
#endif // UINT_MAX | ||
|
||
#ifndef LONG_MAX | ||
#ifdef __LONG_MAX__ | ||
#define LONG_MAX __LONG_MAX__ | ||
#else | ||
#define LONG_MAX (0L ^ (1L << (LONG_WIDTH - 1))) | ||
#endif // __LONG_MAX__ | ||
#endif // LONG_MAX | ||
|
||
#ifndef ULONG_MAX | ||
#define ULONG_MAX (~0UL) | ||
#endif // ULONG_MAX | ||
|
||
#ifndef LLONG_MAX | ||
#ifdef __LONG_LONG_MAX__ | ||
#define LLONG_MAX __LONG_LONG_MAX__ | ||
#else | ||
#define LLONG_MAX (0LL ^ (1LL << (LLONG_WIDTH - 1))) | ||
#endif // __LONG_LONG_MAX__ | ||
#endif // LLONG_MAX | ||
|
||
#ifndef ULLONG_MAX | ||
#define ULLONG_MAX (~0ULL) | ||
#endif // ULLONG_MAX | ||
|
||
// *_MIN macros | ||
|
||
#ifndef SCHAR_MIN | ||
#define SCHAR_MIN (-SCHAR_MAX - 1) | ||
#endif // SCHAR_MIN | ||
|
||
#ifndef UCHAR_MIN | ||
#define UCHAR_MIN 0 | ||
#endif // UCHAR_MIN | ||
|
||
#ifndef CHAR_MIN | ||
#ifdef __CHAR_UNSIGNED__ | ||
#define CHAR_MIN UCHAR_MIN | ||
#else | ||
#define CHAR_MIN SCHAR_MIN | ||
#endif // __CHAR_UNSIGNED__ | ||
#endif // CHAR_MIN | ||
|
||
#ifndef SHRT_MIN | ||
#define SHRT_MIN (-SHRT_MAX - 1) | ||
#endif // SHRT_MIN | ||
|
||
#ifndef USHRT_MIN | ||
#define USHRT_MIN 0U | ||
#endif // USHRT_MIN | ||
|
||
#ifndef INT_MIN | ||
#define INT_MIN (-INT_MAX - 1) | ||
#endif // INT_MIN | ||
|
||
#ifndef UINT_MIN | ||
#define UINT_MIN 0U | ||
#endif // UINT_MIN | ||
|
||
#ifndef LONG_MIN | ||
#define LONG_MIN (-LONG_MAX - 1L) | ||
#endif // LONG_MIN | ||
|
||
#ifndef ULONG_MIN | ||
#define ULONG_MIN 0UL | ||
#endif // ULONG_MIN | ||
|
||
#ifndef LLONG_MIN | ||
#define LLONG_MIN (-LLONG_MAX - 1LL) | ||
#endif // LLONG_MIN | ||
|
||
#ifndef ULLONG_MIN | ||
#define ULLONG_MIN 0ULL | ||
#endif // ULLONG_MIN | ||
|
||
#endif // __LLVM_LIBC_MACROS_LIMITS_MACROS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: is this exposing your newly added limits.h to the consumers of llvm-libc?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's not. It just removes those extra command-only targets from getting linked. We won't add
limits.h
to the consumers, only the "internal"include/llvm-libc-macros/limit-macros.h
.