Skip to content

Commit 241f16e

Browse files
committed
Sync and remove all internal usage of #include <limits.h>.
1 parent b03ddf3 commit 241f16e

32 files changed

+44
-39
lines changed

libc/cmake/modules/LLVMLibCLibraryRules.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,17 @@ function(create_header_library fq_target_name)
173173
target_sources(${fq_target_name} INTERFACE ${ADD_HEADER_HDRS})
174174
if(ADD_HEADER_DEPENDS)
175175
add_dependencies(${fq_target_name} ${ADD_HEADER_DEPENDS})
176-
target_link_libraries(${fq_target_name} INTERFACE ${ADD_HEADER_DEPENDS})
176+
177+
# `*.__copied_hdr__` is created only to copy the header files to the target
178+
# location, not to be linked against.
179+
set(link_lib "")
180+
foreach(dep ${ADD_HEADER_DEPENDS})
181+
if (NOT dep MATCHES "__copied_hdr__")
182+
list(APPEND link_lib ${dep})
183+
endif()
184+
endforeach()
185+
186+
target_link_libraries(${fq_target_name} INTERFACE ${link_lib})
177187
endif()
178188
if(ADD_HEADER_COMPILE_OPTIONS)
179189
target_compile_options(${fq_target_name} INTERFACE ${ADD_HEADER_COMPILE_OPTIONS})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#endif // __has_include_next(<limits.h>)
3737

3838
// Supplement missing macros if there are any.
39+
// Making sure that we provide all C23 constants.
3940

4041
#ifndef CHAR_BIT
4142
#ifdef __CHAR_BIT__

libc/src/__support/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ add_header_library(
3434
HDRS
3535
math_extras.h
3636
DEPENDS
37+
libc.src.__support.CPP.limits
3738
libc.src.__support.CPP.type_traits
3839
libc.src.__support.macros.attributes
3940
libc.src.__support.macros.config

libc/src/__support/CPP/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ add_header_library(
4848
limits.h
4949
DEPENDS
5050
.type_traits
51+
libc.include.llvm-libc-macros.limits_macros
5152
)
5253

5354
add_header_library(

libc/src/__support/CPP/limits.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,14 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
1010
#define LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
1111

12+
#include "include/llvm-libc-macros/limits-macros.h" // CHAR_BIT
1213
#include "src/__support/CPP/type_traits/is_integral.h"
1314
#include "src/__support/CPP/type_traits/is_signed.h"
1415
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1516

16-
#include <limits.h> // CHAR_BIT
17-
1817
namespace LIBC_NAMESPACE {
1918
namespace cpp {
2019

21-
// Some older gcc distributions don't define these for 32 bit targets.
22-
#ifndef LLONG_MAX
23-
constexpr unsigned int LLONG_BIT_WIDTH = sizeof(long long) * 8;
24-
constexpr long long LLONG_MAX = ~0LL ^ (1LL << (LLONG_BIT_WIDTH - 1));
25-
constexpr long long LLONG_MIN = 1LL << (LLONG_BIT_WIDTH - 1);
26-
constexpr unsigned long long ULLONG_MAX = ~0ULL;
27-
#endif
28-
2920
namespace internal {
3021

3122
template <typename T, T min_value, T max_value> struct integer_impl {

libc/src/__support/FPUtil/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ add_header_library(
8484
.nearest_integer_operations
8585
.normal_float
8686
libc.src.__support.CPP.bit
87+
libc.src.__support.CPP.limits
8788
libc.src.__support.CPP.type_traits
8889
libc.src.__support.common
8990
libc.src.__support.macros.optimization

libc/src/__support/FPUtil/ManipulationFunctions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#include "NormalFloat.h"
1515

1616
#include "src/__support/CPP/bit.h"
17+
#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN
1718
#include "src/__support/CPP/type_traits.h"
1819
#include "src/__support/FPUtil/FEnvImpl.h"
1920
#include "src/__support/macros/attributes.h"
2021
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
2122

22-
#include <limits.h>
2323
#include <math.h>
2424

2525
namespace LIBC_NAMESPACE {

libc/src/__support/math_extras.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
1111
#define LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
1212

13+
#include "src/__support/CPP/limits.h" // CHAR_BIT
1314
#include "src/__support/CPP/type_traits.h" // is_unsigned_v
1415
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1516
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
1617

17-
#include <limits.h> // CHAR_BIT
18-
1918
namespace LIBC_NAMESPACE {
2019

2120
// Create a bitmask with the count right-most bits set to 1, and all other bits

libc/src/__support/str_to_integer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "src/__support/ctype_utils.h"
1616
#include "src/__support/str_to_num_result.h"
1717
#include "src/errno/libc_errno.h" // For ERANGE
18-
#include <limits.h>
1918

2019
namespace LIBC_NAMESPACE {
2120
namespace internal {

libc/src/__support/threads/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ add_object_library(
5252
DEPENDS
5353
libc.include.sys_syscall
5454
libc.src.__support.CPP.atomic
55+
libc.src.__support.CPP.limits
5556
libc.src.__support.OSUtil.osutil
5657
)

libc/src/__support/threads/linux/callonce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#include "futex_word.h"
1010

1111
#include "src/__support/CPP/atomic.h"
12+
#include "src/__support/CPP/limits.h" // INT_MAX
1213
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
1314
#include "src/__support/threads/callonce.h"
1415

15-
#include <limits.h>
1616
#include <linux/futex.h>
1717
#include <sys/syscall.h> // For syscall numbers.
1818

libc/src/time/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_object_library(
1010
time_utils.h
1111
DEPENDS
1212
libc.include.time
13+
libc.src.__support.CPP.limits
1314
libc.src.errno.errno
1415
)
1516

libc/src/time/mktime.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include "src/__support/common.h"
1111
#include "src/time/time_utils.h"
1212

13-
#include <limits.h>
14-
1513
namespace LIBC_NAMESPACE {
1614

1715
using LIBC_NAMESPACE::time_utils::TimeConstants;

libc/src/time/time_utils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/time/time_utils.h"
10+
#include "src/__support/CPP/limits.h" // INT_MIN, INT_MAX
1011
#include "src/__support/common.h"
1112

12-
#include <limits.h>
13-
1413
namespace LIBC_NAMESPACE {
1514
namespace time_utils {
1615

libc/test/src/math/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
767767
DEPENDS
768768
libc.include.math
769769
libc.src.math.ilogb
770+
libc.src.__support.CPP.limits
770771
libc.src.__support.FPUtil.fp_bits
771772
libc.src.__support.FPUtil.manipulation_functions
772773
)
@@ -782,6 +783,7 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
782783
DEPENDS
783784
libc.include.math
784785
libc.src.math.ilogbf
786+
libc.src.__support.CPP.limits
785787
libc.src.__support.FPUtil.fp_bits
786788
libc.src.__support.FPUtil.manipulation_functions
787789
)
@@ -798,6 +800,7 @@ add_fp_unittest(
798800
DEPENDS
799801
libc.include.math
800802
libc.src.math.ilogbl
803+
libc.src.__support.CPP.limits
801804
libc.src.__support.FPUtil.fp_bits
802805
libc.src.__support.FPUtil.manipulation_functions
803806
)
@@ -813,6 +816,7 @@ add_fp_unittest(
813816
DEPENDS
814817
libc.include.math
815818
libc.src.math.ldexp
819+
libc.src.__support.CPP.limits
816820
libc.src.__support.FPUtil.fp_bits
817821
libc.src.__support.FPUtil.normal_float
818822
)
@@ -828,6 +832,7 @@ add_fp_unittest(
828832
DEPENDS
829833
libc.include.math
830834
libc.src.math.ldexpf
835+
libc.src.__support.CPP.limits
831836
libc.src.__support.FPUtil.fp_bits
832837
libc.src.__support.FPUtil.normal_float
833838
)
@@ -843,6 +848,7 @@ add_fp_unittest(
843848
DEPENDS
844849
libc.include.math
845850
libc.src.math.ldexpl
851+
libc.src.__support.CPP.limits
846852
libc.src.__support.FPUtil.fp_bits
847853
libc.src.__support.FPUtil.normal_float
848854
)

libc/test/src/math/ILogbTest.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
1111

12+
#include "src/__support/CPP/limits.h" // INT_MAX
1213
#include "src/__support/FPUtil/FPBits.h"
1314
#include "src/__support/FPUtil/ManipulationFunctions.h"
1415
#include "test/UnitTest/Test.h"
1516
#include <math.h>
1617

17-
#include <limits.h>
18-
1918
class LlvmLibcILogbTest : public LIBC_NAMESPACE::testing::Test {
2019
public:
2120
template <typename T> struct ILogbFunc {

libc/test/src/math/LdExpTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
1111

12+
#include "src/__support/CPP/limits.h" // INT_MAX
1213
#include "src/__support/FPUtil/FPBits.h"
1314
#include "src/__support/FPUtil/NormalFloat.h"
1415
#include "test/UnitTest/FPMatcher.h"
1516
#include "test/UnitTest/Test.h"
1617

17-
#include <limits.h>
1818
#include <math.h>
1919
#include <stdint.h>
2020

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
761761
DEPENDS
762762
libc.include.math
763763
libc.src.math.ilogb
764+
libc.src.__support.CPP.limits
764765
libc.src.__support.FPUtil.fp_bits
765766
libc.src.__support.FPUtil.manipulation_functions
766767
)
@@ -776,6 +777,7 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
776777
DEPENDS
777778
libc.include.math
778779
libc.src.math.ilogbf
780+
libc.src.__support.CPP.limits
779781
libc.src.__support.FPUtil.fp_bits
780782
libc.src.__support.FPUtil.manipulation_functions
781783
)
@@ -792,6 +794,7 @@ add_fp_unittest(
792794
DEPENDS
793795
libc.include.math
794796
libc.src.math.ilogbl
797+
libc.src.__support.CPP.limits
795798
libc.src.__support.FPUtil.fp_bits
796799
libc.src.__support.FPUtil.manipulation_functions
797800
)
@@ -807,6 +810,7 @@ add_fp_unittest(
807810
DEPENDS
808811
libc.include.math
809812
libc.src.math.ldexp
813+
libc.src.__support.CPP.limits
810814
libc.src.__support.FPUtil.fp_bits
811815
libc.src.__support.FPUtil.normal_float
812816
)
@@ -822,6 +826,7 @@ add_fp_unittest(
822826
DEPENDS
823827
libc.include.math
824828
libc.src.math.ldexpf
829+
libc.src.__support.CPP.limits
825830
libc.src.__support.FPUtil.fp_bits
826831
libc.src.__support.FPUtil.normal_float
827832
)
@@ -837,6 +842,7 @@ add_fp_unittest(
837842
DEPENDS
838843
libc.include.math
839844
libc.src.math.ldexpl
845+
libc.src.__support.CPP.limits
840846
libc.src.__support.FPUtil.fp_bits
841847
libc.src.__support.FPUtil.normal_float
842848
)

libc/test/src/math/smoke/ILogbTest.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
1111

12+
#include "src/__support/CPP/limits.h" // INT_MAX
1213
#include "src/__support/FPUtil/FPBits.h"
1314
#include "src/__support/FPUtil/ManipulationFunctions.h"
1415
#include "test/UnitTest/Test.h"
1516
#include <math.h>
1617

17-
#include <limits.h>
18-
1918
class LlvmLibcILogbTest : public LIBC_NAMESPACE::testing::Test {
2019
public:
2120
template <typename T> struct ILogbFunc {

libc/test/src/math/smoke/LdExpTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
1111

12+
#include "src/__support/CPP/limits.h" // INT_MAX
1213
#include "src/__support/FPUtil/FPBits.h"
1314
#include "src/__support/FPUtil/NormalFloat.h"
1415
#include "test/UnitTest/FPMatcher.h"
1516
#include "test/UnitTest/Test.h"
1617

17-
#include <limits.h>
1818
#include <math.h>
1919
#include <stdint.h>
2020

libc/test/src/stdlib/AtoiTest.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN, LLONG_MAX, LLONG_MIN
910
#include "src/__support/CPP/type_traits.h"
1011
#include "test/UnitTest/Test.h"
1112

12-
#include <limits.h>
13-
1413
using LIBC_NAMESPACE::cpp::is_same_v;
1514

1615
template <typename ReturnT>

libc/test/src/stdlib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_header_library(
1717
AtoiTest.h
1818
DEPENDS
1919
libc.src.errno.errno
20+
libc.src.__support.CPP.limits
2021
libc.src.__support.CPP.type_traits
2122
)
2223

libc/test/src/stdlib/StrtolTest.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "src/errno/libc_errno.h"
1313
#include "test/UnitTest/Test.h"
1414

15-
#include <limits.h>
1615
#include <stddef.h>
1716

1817
using LIBC_NAMESPACE::cpp::is_signed_v;

libc/test/src/stdlib/atof_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "test/UnitTest/ErrnoSetterMatcher.h"
1414
#include "test/UnitTest/Test.h"
1515

16-
#include <limits.h>
1716
#include <stddef.h>
1817

1918
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;

libc/test/src/stdlib/strtod_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "test/UnitTest/RoundingModeUtils.h"
1515
#include "test/UnitTest/Test.h"
1616

17-
#include <limits.h>
1817
#include <stddef.h>
1918

2019
using LIBC_NAMESPACE::fputil::testing::ForceRoundingModeTest;

libc/test/src/stdlib/strtof_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "test/UnitTest/RoundingModeUtils.h"
1515
#include "test/UnitTest/Test.h"
1616

17-
#include <limits.h>
1817
#include <stddef.h>
1918

2019
using LIBC_NAMESPACE::fputil::testing::ForceRoundingModeTest;

libc/test/src/stdlib/strtold_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include "test/UnitTest/Test.h"
1515

16-
#include <limits.h>
1716
#include <stddef.h>
1817

1918
#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)

libc/test/src/time/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ add_libc_unittest(
7171
TmMatcher.h
7272
DEPENDS
7373
libc.src.time.gmtime
74+
libc.src.__support.CPP.limits
7475
)
7576

7677
add_libc_unittest(
@@ -98,6 +99,7 @@ add_libc_unittest(
9899
20
99100
DEPENDS
100101
libc.src.time.mktime
102+
libc.src.__support.CPP.limits
101103
)
102104

103105
# Sleeping is not supported on older NVPTX architectures.

libc/test/src/time/clock_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "src/time/clock.h"
1010
#include "test/UnitTest/Test.h"
1111

12-
#include <limits.h>
1312
#include <time.h>
1413

1514
TEST(LlvmLibcClockTest, SmokeTest) {

0 commit comments

Comments
 (0)