[libc-commits] [libc] 72ce629 - [libc] Add C23 limits.h header. (#78887)

via libc-commits libc-commits at lists.llvm.org
Wed Jan 24 13:09:00 PST 2024


Author: lntue
Date: 2024-01-24T16:08:56-05:00
New Revision: 72ce6294157964042b7ed5576ce2c99257eeea9d

URL: https://github.com/llvm/llvm-project/commit/72ce6294157964042b7ed5576ce2c99257eeea9d
DIFF: https://github.com/llvm/llvm-project/commit/72ce6294157964042b7ed5576ce2c99257eeea9d.diff

LOG: [libc] Add C23 limits.h header. (#78887)

Added: 
    libc/include/limits.h.def
    libc/include/llvm-libc-macros/limits-macros.h

Modified: 
    libc/cmake/modules/LLVMLibCLibraryRules.cmake
    libc/config/darwin/arm/headers.txt
    libc/config/darwin/x86_64/headers.txt
    libc/config/gpu/headers.txt
    libc/config/linux/aarch64/headers.txt
    libc/config/linux/riscv/headers.txt
    libc/config/linux/x86_64/headers.txt
    libc/include/CMakeLists.txt
    libc/include/llvm-libc-macros/CMakeLists.txt
    libc/include/llvm-libc-macros/float-macros.h
    libc/spec/stdc.td
    libc/src/__support/CMakeLists.txt
    libc/src/__support/CPP/CMakeLists.txt
    libc/src/__support/CPP/limits.h
    libc/src/__support/FPUtil/CMakeLists.txt
    libc/src/__support/FPUtil/ManipulationFunctions.h
    libc/src/__support/math_extras.h
    libc/src/__support/str_to_integer.h
    libc/src/__support/threads/linux/CMakeLists.txt
    libc/src/__support/threads/linux/callonce.cpp
    libc/src/time/CMakeLists.txt
    libc/src/time/mktime.cpp
    libc/src/time/time_utils.cpp
    libc/test/src/math/CMakeLists.txt
    libc/test/src/math/ILogbTest.h
    libc/test/src/math/LdExpTest.h
    libc/test/src/math/smoke/CMakeLists.txt
    libc/test/src/math/smoke/ILogbTest.h
    libc/test/src/math/smoke/LdExpTest.h
    libc/test/src/stdlib/AtoiTest.h
    libc/test/src/stdlib/CMakeLists.txt
    libc/test/src/stdlib/StrtolTest.h
    libc/test/src/stdlib/atof_test.cpp
    libc/test/src/stdlib/strtod_test.cpp
    libc/test/src/stdlib/strtof_test.cpp
    libc/test/src/stdlib/strtold_test.cpp
    libc/test/src/time/CMakeLists.txt
    libc/test/src/time/clock_test.cpp
    libc/test/src/time/gmtime_test.cpp
    libc/test/src/time/mktime_test.cpp
    libc/test/src/time/time_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCLibraryRules.cmake b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
index e6cfd79e65a085a..adb3bdeea2cb3bc 100644
--- a/libc/cmake/modules/LLVMLibCLibraryRules.cmake
+++ b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
@@ -173,7 +173,17 @@ function(create_header_library fq_target_name)
   target_sources(${fq_target_name} INTERFACE ${ADD_HEADER_HDRS})
   if(ADD_HEADER_DEPENDS)
     add_dependencies(${fq_target_name} ${ADD_HEADER_DEPENDS})
-    target_link_libraries(${fq_target_name} INTERFACE ${ADD_HEADER_DEPENDS})
+
+    # `*.__copied_hdr__` is created only to copy the header files to the target
+    # location, not to be linked against.
+    set(link_lib "")
+    foreach(dep ${ADD_HEADER_DEPENDS})
+      if (NOT dep MATCHES "__copied_hdr__")
+        list(APPEND link_lib ${dep})
+      endif()
+    endforeach()
+
+    target_link_libraries(${fq_target_name} INTERFACE ${link_lib})
   endif()
   if(ADD_HEADER_COMPILE_OPTIONS)
     target_compile_options(${fq_target_name} INTERFACE ${ADD_HEADER_COMPILE_OPTIONS})

diff  --git a/libc/config/darwin/arm/headers.txt b/libc/config/darwin/arm/headers.txt
index 2dd54b7c1f50535..d80628445af5c52 100644
--- a/libc/config/darwin/arm/headers.txt
+++ b/libc/config/darwin/arm/headers.txt
@@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.fenv
     libc.include.float
     libc.include.inttypes
+    libc.include.limits
     libc.include.math
     libc.include.stdlib
     libc.include.string

diff  --git a/libc/config/darwin/x86_64/headers.txt b/libc/config/darwin/x86_64/headers.txt
index 510d62688a45fa3..1e81e303ddd6b47 100644
--- a/libc/config/darwin/x86_64/headers.txt
+++ b/libc/config/darwin/x86_64/headers.txt
@@ -5,6 +5,7 @@ set(TARGET_PUBLIC_HEADERS
     #libc.include.fenv
     libc.include.float
     libc.include.inttypes
+    libc.include.limits
     libc.include.math
     libc.include.stdlib
     libc.include.string

diff  --git a/libc/config/gpu/headers.txt b/libc/config/gpu/headers.txt
index e68e18b87b10e27..3b04dd89fafe6f7 100644
--- a/libc/config/gpu/headers.txt
+++ b/libc/config/gpu/headers.txt
@@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.string
     libc.include.float
     libc.include.inttypes
+    libc.include.limits
     libc.include.math
     libc.include.fenv
     libc.include.time

diff  --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 709a8dbdedc98f1..60d978bcaa76e44 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -6,6 +6,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.fenv
     libc.include.float
     libc.include.inttypes
+    libc.include.limits
     libc.include.math
     libc.include.pthread
     libc.include.signal

diff  --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index dc1daa48f6c875f..0ade63dc5933b53 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -8,6 +8,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.fenv
     libc.include.float
     libc.include.inttypes
+    libc.include.limits
     libc.include.math
     libc.include.pthread
     libc.include.sched

diff  --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index b0e0219a30e673c..d103176897a74a8 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -8,6 +8,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.fenv
     libc.include.float
     libc.include.inttypes
+    libc.include.limits
     libc.include.math
     libc.include.pthread
     libc.include.sched

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index cec8b86516b51f0..89fffd1022758ea 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -83,6 +83,14 @@ add_gen_header(
     .llvm-libc-macros.float_macros
 )
 
+add_gen_header(
+  limits
+  DEF_FILE limits.h.def
+  GEN_HDR limits.h
+  DEPENDS
+    .llvm-libc-macros.limits_macros
+)
+
 add_gen_header(
   math
   DEF_FILE math.h.def

diff  --git a/libc/include/limits.h.def b/libc/include/limits.h.def
new file mode 100644
index 000000000000000..de5f3490459ed8b
--- /dev/null
+++ b/libc/include/limits.h.def
@@ -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

diff  --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index d965a6a9443ed2a..96ee29d7327224c 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -73,6 +73,12 @@ add_macro_header(
     float-macros.h
 )
 
+add_macro_header(
+  limits_macros
+  HDR
+    limits-macros.h
+)
+
 add_macro_header(
   math_macros
   HDR

diff  --git a/libc/include/llvm-libc-macros/float-macros.h b/libc/include/llvm-libc-macros/float-macros.h
index 8e4b91b9a0f557d..86ec4939393086c 100644
--- a/libc/include/llvm-libc-macros/float-macros.h
+++ b/libc/include/llvm-libc-macros/float-macros.h
@@ -9,8 +9,20 @@
 #ifndef __LLVM_LIBC_MACROS_FLOAT_MACROS_H
 #define __LLVM_LIBC_MACROS_FLOAT_MACROS_H
 
+// Suppress `#include_next is a language extension` warnings.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-include-next"
+#else // gcc
+#pragma GCC system_header
+#endif //__clang__
+
 #include_next <float.h>
 
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif //__clang__
+
 #ifndef FLT_RADIX
 #define FLT_RADIX __FLT_RADIX__
 #endif // FLT_RADIX

diff  --git a/libc/include/llvm-libc-macros/limits-macros.h b/libc/include/llvm-libc-macros/limits-macros.h
new file mode 100644
index 000000000000000..fc21d1318a081b2
--- /dev/null
+++ b/libc/include/llvm-libc-macros/limits-macros.h
@@ -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__
+#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

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 8c2feba23adbf3a..96bedf2f47f1b8e 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -857,6 +857,8 @@ def StdC : StandardSpec<"stdc"> {
       ]
   >;
 
+  HeaderSpec Limits = HeaderSpec<"limits.h">;
+
   NamedType SigAtomicT = NamedType<"sig_atomic_t">;
   HeaderSpec Signal = HeaderSpec<
       "signal.h",
@@ -1160,6 +1162,7 @@ def StdC : StandardSpec<"stdc"> {
     Errno,
     Fenv,
     Float,
+    Limits,
     Math,
     String,
     StdIO,

diff  --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 502bf72ae9906bf..595124702763bbb 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -34,6 +34,7 @@ add_header_library(
   HDRS
     math_extras.h
   DEPENDS
+    libc.src.__support.CPP.limits
     libc.src.__support.CPP.type_traits
     libc.src.__support.macros.attributes
     libc.src.__support.macros.config

diff  --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt
index 1a31b4ecbe47407..f10bb936047eb9a 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -48,6 +48,7 @@ add_header_library(
     limits.h
   DEPENDS
     .type_traits
+    libc.include.llvm-libc-macros.limits_macros
 )
 
 add_header_library(

diff  --git a/libc/src/__support/CPP/limits.h b/libc/src/__support/CPP/limits.h
index d9e7090a0b7b190..1ffde5f9556f871 100644
--- a/libc/src/__support/CPP/limits.h
+++ b/libc/src/__support/CPP/limits.h
@@ -9,23 +9,14 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
 #define LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
 
+#include "include/llvm-libc-macros/limits-macros.h" // CHAR_BIT
 #include "src/__support/CPP/type_traits/is_integral.h"
 #include "src/__support/CPP/type_traits/is_signed.h"
 #include "src/__support/macros/attributes.h" // LIBC_INLINE
 
-#include <limits.h> // CHAR_BIT
-
 namespace LIBC_NAMESPACE {
 namespace cpp {
 
-// Some older gcc distributions don't define these for 32 bit targets.
-#ifndef LLONG_MAX
-constexpr unsigned int LLONG_BIT_WIDTH = sizeof(long long) * 8;
-constexpr long long LLONG_MAX = ~0LL ^ (1LL << (LLONG_BIT_WIDTH - 1));
-constexpr long long LLONG_MIN = 1LL << (LLONG_BIT_WIDTH - 1);
-constexpr unsigned long long ULLONG_MAX = ~0ULL;
-#endif
-
 namespace internal {
 
 template <typename T, T min_value, T max_value> struct integer_impl {

diff  --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index ad2c4ad27bced3e..50cc904f0cfada2 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -84,6 +84,7 @@ add_header_library(
     .nearest_integer_operations
     .normal_float
     libc.src.__support.CPP.bit
+    libc.src.__support.CPP.limits
     libc.src.__support.CPP.type_traits
     libc.src.__support.common
     libc.src.__support.macros.optimization

diff  --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h
index 56e53e3d4f497cf..9becbaa45eadeb9 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -14,12 +14,12 @@
 #include "NormalFloat.h"
 
 #include "src/__support/CPP/bit.h"
+#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/macros/attributes.h"
 #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
 
-#include <limits.h>
 #include <math.h>
 
 namespace LIBC_NAMESPACE {

diff  --git a/libc/src/__support/math_extras.h b/libc/src/__support/math_extras.h
index 89bd0b72669ea22..8ec30396ffdb460 100644
--- a/libc/src/__support/math_extras.h
+++ b/libc/src/__support/math_extras.h
@@ -10,12 +10,11 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
 
+#include "src/__support/CPP/limits.h"        // CHAR_BIT
 #include "src/__support/CPP/type_traits.h"   // is_unsigned_v
 #include "src/__support/macros/attributes.h" // LIBC_INLINE
 #include "src/__support/macros/config.h"     // LIBC_HAS_BUILTIN
 
-#include <limits.h> // CHAR_BIT
-
 namespace LIBC_NAMESPACE {
 
 // Create a bitmask with the count right-most bits set to 1, and all other bits

diff  --git a/libc/src/__support/str_to_integer.h b/libc/src/__support/str_to_integer.h
index 4ee336ec9e2bbd8..e83a508e086b18a 100644
--- a/libc/src/__support/str_to_integer.h
+++ b/libc/src/__support/str_to_integer.h
@@ -15,7 +15,6 @@
 #include "src/__support/ctype_utils.h"
 #include "src/__support/str_to_num_result.h"
 #include "src/errno/libc_errno.h" // For ERANGE
-#include <limits.h>
 
 namespace LIBC_NAMESPACE {
 namespace internal {

diff  --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt
index 148a0ba061c5777..87a7a66ac6ea571 100644
--- a/libc/src/__support/threads/linux/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/CMakeLists.txt
@@ -52,5 +52,6 @@ add_object_library(
   DEPENDS
     libc.include.sys_syscall
     libc.src.__support.CPP.atomic
+    libc.src.__support.CPP.limits
     libc.src.__support.OSUtil.osutil
 )

diff  --git a/libc/src/__support/threads/linux/callonce.cpp b/libc/src/__support/threads/linux/callonce.cpp
index de1e1008784f604..b6a5ab8c0d07a9b 100644
--- a/libc/src/__support/threads/linux/callonce.cpp
+++ b/libc/src/__support/threads/linux/callonce.cpp
@@ -9,10 +9,10 @@
 #include "futex_word.h"
 
 #include "src/__support/CPP/atomic.h"
+#include "src/__support/CPP/limits.h"     // INT_MAX
 #include "src/__support/OSUtil/syscall.h" // For syscall functions.
 #include "src/__support/threads/callonce.h"
 
-#include <limits.h>
 #include <linux/futex.h>
 #include <sys/syscall.h> // For syscall numbers.
 

diff  --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt
index 210f3b23432b49f..5680718715974e8 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -10,6 +10,7 @@ add_object_library(
     time_utils.h
   DEPENDS
     libc.include.time
+    libc.src.__support.CPP.limits
     libc.src.errno.errno
 )
 

diff  --git a/libc/src/time/mktime.cpp b/libc/src/time/mktime.cpp
index e57565f0d1fe016..8a4397e5eac7c29 100644
--- a/libc/src/time/mktime.cpp
+++ b/libc/src/time/mktime.cpp
@@ -10,8 +10,6 @@
 #include "src/__support/common.h"
 #include "src/time/time_utils.h"
 
-#include <limits.h>
-
 namespace LIBC_NAMESPACE {
 
 using LIBC_NAMESPACE::time_utils::TimeConstants;

diff  --git a/libc/src/time/time_utils.cpp b/libc/src/time/time_utils.cpp
index 199a74cb168a2c3..713ed21e3191d5c 100644
--- a/libc/src/time/time_utils.cpp
+++ b/libc/src/time/time_utils.cpp
@@ -7,10 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/time/time_utils.h"
+#include "src/__support/CPP/limits.h" // INT_MIN, INT_MAX
 #include "src/__support/common.h"
 
-#include <limits.h>
-
 namespace LIBC_NAMESPACE {
 namespace time_utils {
 

diff  --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index fcb47449748dcac..8c105515e3525c0 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -767,6 +767,7 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
     DEPENDS
       libc.include.math
       libc.src.math.ilogb
+      libc.src.__support.CPP.limits
       libc.src.__support.FPUtil.fp_bits
       libc.src.__support.FPUtil.manipulation_functions
   )
@@ -782,6 +783,7 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
     DEPENDS
       libc.include.math
       libc.src.math.ilogbf
+      libc.src.__support.CPP.limits
       libc.src.__support.FPUtil.fp_bits
       libc.src.__support.FPUtil.manipulation_functions
   )
@@ -798,6 +800,7 @@ add_fp_unittest(
   DEPENDS
     libc.include.math
     libc.src.math.ilogbl
+    libc.src.__support.CPP.limits
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.manipulation_functions
 )
@@ -813,6 +816,7 @@ add_fp_unittest(
   DEPENDS
     libc.include.math
     libc.src.math.ldexp
+    libc.src.__support.CPP.limits
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.normal_float
 )
@@ -828,6 +832,7 @@ add_fp_unittest(
   DEPENDS
     libc.include.math
     libc.src.math.ldexpf
+    libc.src.__support.CPP.limits
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.normal_float
 )
@@ -843,6 +848,7 @@ add_fp_unittest(
   DEPENDS
     libc.include.math
     libc.src.math.ldexpl
+    libc.src.__support.CPP.limits
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.normal_float
 )

diff  --git a/libc/test/src/math/ILogbTest.h b/libc/test/src/math/ILogbTest.h
index fb8d77093eba3c9..5fb3a5ab8923bf9 100644
--- a/libc/test/src/math/ILogbTest.h
+++ b/libc/test/src/math/ILogbTest.h
@@ -9,13 +9,12 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
 
+#include "src/__support/CPP/limits.h" // INT_MAX
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/FPUtil/ManipulationFunctions.h"
 #include "test/UnitTest/Test.h"
 #include <math.h>
 
-#include <limits.h>
-
 class LlvmLibcILogbTest : public LIBC_NAMESPACE::testing::Test {
 public:
   template <typename T> struct ILogbFunc {

diff  --git a/libc/test/src/math/LdExpTest.h b/libc/test/src/math/LdExpTest.h
index 1d581f2c0a02fcb..faa9149830adcce 100644
--- a/libc/test/src/math/LdExpTest.h
+++ b/libc/test/src/math/LdExpTest.h
@@ -9,12 +9,12 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
 
+#include "src/__support/CPP/limits.h" // INT_MAX
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/FPUtil/NormalFloat.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
 #include <math.h>
 #include <stdint.h>
 

diff  --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 03526e019c3e9ff..a03342e428c301e 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -761,6 +761,7 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
     DEPENDS
       libc.include.math
       libc.src.math.ilogb
+      libc.src.__support.CPP.limits
       libc.src.__support.FPUtil.fp_bits
       libc.src.__support.FPUtil.manipulation_functions
   )
@@ -776,6 +777,7 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
     DEPENDS
       libc.include.math
       libc.src.math.ilogbf
+      libc.src.__support.CPP.limits
       libc.src.__support.FPUtil.fp_bits
       libc.src.__support.FPUtil.manipulation_functions
   )
@@ -792,6 +794,7 @@ add_fp_unittest(
   DEPENDS
     libc.include.math
     libc.src.math.ilogbl
+    libc.src.__support.CPP.limits
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.manipulation_functions
 )
@@ -807,6 +810,7 @@ add_fp_unittest(
   DEPENDS
     libc.include.math
     libc.src.math.ldexp
+    libc.src.__support.CPP.limits
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.normal_float
 )
@@ -822,6 +826,7 @@ add_fp_unittest(
   DEPENDS
     libc.include.math
     libc.src.math.ldexpf
+    libc.src.__support.CPP.limits
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.normal_float
 )
@@ -837,6 +842,7 @@ add_fp_unittest(
   DEPENDS
     libc.include.math
     libc.src.math.ldexpl
+    libc.src.__support.CPP.limits
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.normal_float
 )

diff  --git a/libc/test/src/math/smoke/ILogbTest.h b/libc/test/src/math/smoke/ILogbTest.h
index fb8d77093eba3c9..5fb3a5ab8923bf9 100644
--- a/libc/test/src/math/smoke/ILogbTest.h
+++ b/libc/test/src/math/smoke/ILogbTest.h
@@ -9,13 +9,12 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
 
+#include "src/__support/CPP/limits.h" // INT_MAX
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/FPUtil/ManipulationFunctions.h"
 #include "test/UnitTest/Test.h"
 #include <math.h>
 
-#include <limits.h>
-
 class LlvmLibcILogbTest : public LIBC_NAMESPACE::testing::Test {
 public:
   template <typename T> struct ILogbFunc {

diff  --git a/libc/test/src/math/smoke/LdExpTest.h b/libc/test/src/math/smoke/LdExpTest.h
index 1d581f2c0a02fcb..faa9149830adcce 100644
--- a/libc/test/src/math/smoke/LdExpTest.h
+++ b/libc/test/src/math/smoke/LdExpTest.h
@@ -9,12 +9,12 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
 
+#include "src/__support/CPP/limits.h" // INT_MAX
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/FPUtil/NormalFloat.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
 #include <math.h>
 #include <stdint.h>
 

diff  --git a/libc/test/src/stdlib/AtoiTest.h b/libc/test/src/stdlib/AtoiTest.h
index 85701828c0f6b7c..5e86a738a3aef31 100644
--- a/libc/test/src/stdlib/AtoiTest.h
+++ b/libc/test/src/stdlib/AtoiTest.h
@@ -6,11 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN, LLONG_MAX, LLONG_MIN
 #include "src/__support/CPP/type_traits.h"
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
-
 using LIBC_NAMESPACE::cpp::is_same_v;
 
 template <typename ReturnT>

diff  --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt
index 3c2eeeaa36926fa..da07dbbe7977205 100644
--- a/libc/test/src/stdlib/CMakeLists.txt
+++ b/libc/test/src/stdlib/CMakeLists.txt
@@ -17,6 +17,7 @@ add_header_library(
     AtoiTest.h
   DEPENDS
     libc.src.errno.errno
+    libc.src.__support.CPP.limits
     libc.src.__support.CPP.type_traits
 )
 

diff  --git a/libc/test/src/stdlib/StrtolTest.h b/libc/test/src/stdlib/StrtolTest.h
index 11794c4bfe05f8a..6aee049aa066a04 100644
--- a/libc/test/src/stdlib/StrtolTest.h
+++ b/libc/test/src/stdlib/StrtolTest.h
@@ -12,7 +12,6 @@
 #include "src/errno/libc_errno.h"
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
 #include <stddef.h>
 
 using LIBC_NAMESPACE::cpp::is_signed_v;

diff  --git a/libc/test/src/stdlib/atof_test.cpp b/libc/test/src/stdlib/atof_test.cpp
index 613b56d05091ec9..858ab326e38d013 100644
--- a/libc/test/src/stdlib/atof_test.cpp
+++ b/libc/test/src/stdlib/atof_test.cpp
@@ -13,7 +13,6 @@
 #include "test/UnitTest/ErrnoSetterMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
 #include <stddef.h>
 
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;

diff  --git a/libc/test/src/stdlib/strtod_test.cpp b/libc/test/src/stdlib/strtod_test.cpp
index 452a180d70cea65..e68c8610b40704c 100644
--- a/libc/test/src/stdlib/strtod_test.cpp
+++ b/libc/test/src/stdlib/strtod_test.cpp
@@ -14,7 +14,6 @@
 #include "test/UnitTest/RoundingModeUtils.h"
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
 #include <stddef.h>
 
 using LIBC_NAMESPACE::fputil::testing::ForceRoundingModeTest;

diff  --git a/libc/test/src/stdlib/strtof_test.cpp b/libc/test/src/stdlib/strtof_test.cpp
index 31b3f69f63a0c7a..f30c588c611b390 100644
--- a/libc/test/src/stdlib/strtof_test.cpp
+++ b/libc/test/src/stdlib/strtof_test.cpp
@@ -14,7 +14,6 @@
 #include "test/UnitTest/RoundingModeUtils.h"
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
 #include <stddef.h>
 
 using LIBC_NAMESPACE::fputil::testing::ForceRoundingModeTest;

diff  --git a/libc/test/src/stdlib/strtold_test.cpp b/libc/test/src/stdlib/strtold_test.cpp
index 51f9975772aa5e9..b7942ab66460b65 100644
--- a/libc/test/src/stdlib/strtold_test.cpp
+++ b/libc/test/src/stdlib/strtold_test.cpp
@@ -13,7 +13,6 @@
 
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
 #include <stddef.h>
 
 #if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)

diff  --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt
index 10b63ce6f39d295..ebb0998feb23e97 100644
--- a/libc/test/src/time/CMakeLists.txt
+++ b/libc/test/src/time/CMakeLists.txt
@@ -71,6 +71,7 @@ add_libc_unittest(
     TmMatcher.h
   DEPENDS
     libc.src.time.gmtime
+    libc.src.__support.CPP.limits
 )
 
 add_libc_unittest(
@@ -98,6 +99,7 @@ add_libc_unittest(
     20
   DEPENDS
     libc.src.time.mktime
+    libc.src.__support.CPP.limits
 )
 
 # Sleeping is not supported on older NVPTX architectures.

diff  --git a/libc/test/src/time/clock_test.cpp b/libc/test/src/time/clock_test.cpp
index a3dffc6bae3913d..05082aa23388529 100644
--- a/libc/test/src/time/clock_test.cpp
+++ b/libc/test/src/time/clock_test.cpp
@@ -9,7 +9,6 @@
 #include "src/time/clock.h"
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
 #include <time.h>
 
 TEST(LlvmLibcClockTest, SmokeTest) {

diff  --git a/libc/test/src/time/gmtime_test.cpp b/libc/test/src/time/gmtime_test.cpp
index 6b1d029a693c383..e59daf012d9b6ca 100644
--- a/libc/test/src/time/gmtime_test.cpp
+++ b/libc/test/src/time/gmtime_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN
 #include "src/errno/libc_errno.h"
 #include "src/time/gmtime.h"
 #include "src/time/time_utils.h"
@@ -13,8 +14,6 @@
 #include "test/UnitTest/Test.h"
 #include "test/src/time/TmMatcher.h"
 
-#include <limits.h>
-
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
 using LIBC_NAMESPACE::time_utils::TimeConstants;

diff  --git a/libc/test/src/time/mktime_test.cpp b/libc/test/src/time/mktime_test.cpp
index 6f179150953b7f1..3142a4f3d06dd84 100644
--- a/libc/test/src/time/mktime_test.cpp
+++ b/libc/test/src/time/mktime_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/__support/CPP/limits.h" // INT_MAX
 #include "src/time/mktime.h"
 #include "src/time/time_utils.h"
 #include "test/UnitTest/ErrnoSetterMatcher.h"
@@ -13,8 +14,6 @@
 #include "test/src/time/TmHelper.h"
 #include "test/src/time/TmMatcher.h"
 
-#include <limits.h>
-
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
 using LIBC_NAMESPACE::time_utils::Month;

diff  --git a/libc/test/src/time/time_test.cpp b/libc/test/src/time/time_test.cpp
index 1d938e8dae7adb2..d3d4dc9a285158e 100644
--- a/libc/test/src/time/time_test.cpp
+++ b/libc/test/src/time/time_test.cpp
@@ -9,7 +9,6 @@
 #include "src/time/time_func.h"
 #include "test/UnitTest/Test.h"
 
-#include <limits.h>
 #include <time.h>
 
 TEST(LlvmLibcTimeTest, SmokeTest) {


        


More information about the libc-commits mailing list