[libcxx-commits] [libcxx] [libc++] Remove libc++'s own <limits.h> (PR #65472)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 27 08:00:56 PDT 2023


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/65472

>From cdf0fdc3bb62627de6133513beb1b08461e77a60 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 6 Sep 2023 09:11:07 -0400
Subject: [PATCH] [libc++] Remove libc++'s own <limits.h>

We do not define anything beyond the C Library's limits.h, so it
shouldn't be needed. This removes the need for a GCC-specific
workaround, see [1].

[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107795

Differential Revision: https://reviews.llvm.org/D138384
---
 libcxx/include/CMakeLists.txt                 |  1 -
 libcxx/include/__std_clang_module             |  1 -
 libcxx/include/climits                        |  8 ---
 libcxx/include/limits.h                       | 71 -------------------
 libcxx/include/module.modulemap.in            |  4 --
 .../depr.c.headers/limits_h.compile.pass.cpp  |  5 +-
 libcxx/utils/data/ignore_format.txt           |  1 -
 7 files changed, 4 insertions(+), 87 deletions(-)
 delete mode 100644 libcxx/include/limits.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..8a57774cf081896 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -954,7 +954,6 @@ set(files
   latch
   libcxx.imp
   limits
-  limits.h
   list
   locale
   locale.h
diff --git a/libcxx/include/__std_clang_module b/libcxx/include/__std_clang_module
index 4d02336d30b0649..2644ea98b4907f7 100644
--- a/libcxx/include/__std_clang_module
+++ b/libcxx/include/__std_clang_module
@@ -135,7 +135,6 @@
 #if !defined(_LIBCPP_HAS_NO_THREADS)
 #  include <latch>
 #endif
-#include <limits.h>
 #include <limits>
 #include <list>
 #if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
diff --git a/libcxx/include/climits b/libcxx/include/climits
index d773af50d299132..2e8993e4d6a5195 100644
--- a/libcxx/include/climits
+++ b/libcxx/include/climits
@@ -42,14 +42,6 @@ Macros:
 
 #include <limits.h>
 
-#ifndef _LIBCPP_LIMITS_H
-#   error <climits> tried including <limits.h> but didn't find libc++'s <limits.h> header. \
-          This usually means that your header search paths are not configured properly. \
-          The header search paths should contain the C++ Standard Library headers before \
-          any C Standard Library, and you are probably using compiler flags that make that \
-          not be the case.
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
diff --git a/libcxx/include/limits.h b/libcxx/include/limits.h
deleted file mode 100644
index 537a4b1439f9c82..000000000000000
--- a/libcxx/include/limits.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// 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 _LIBCPP_LIMITS_H
-#define _LIBCPP_LIMITS_H
-
-/*
-    limits.h synopsis
-
-Macros:
-
-    CHAR_BIT
-    SCHAR_MIN
-    SCHAR_MAX
-    UCHAR_MAX
-    CHAR_MIN
-    CHAR_MAX
-    MB_LEN_MAX
-    SHRT_MIN
-    SHRT_MAX
-    USHRT_MAX
-    INT_MIN
-    INT_MAX
-    UINT_MAX
-    LONG_MIN
-    LONG_MAX
-    ULONG_MAX
-    LLONG_MIN   // C99
-    LLONG_MAX   // C99
-    ULLONG_MAX  // C99
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-#ifdef _LIBCPP_COMPILER_GCC
-
-// GCC header limits.h recursively includes itself through another header called
-// syslimits.h for some reason. This setup breaks down if we directly
-// #include_next GCC's limits.h (reasons not entirely clear to me).
-// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107795 for more details.
-// Therefore, we manually re-create the necessary include sequence below:
-
-// Get the system limits.h defines (force recurse into the next level)
-#define _GCC_LIMITS_H_
-#define _GCC_NEXT_LIMITS_H
-#include_next <limits.h>
-
-// Get the ISO C defines
-#undef _GCC_LIMITS_H_
-#include_next <limits.h>
-
-#else
-
-#  if __has_include_next(<limits.h>)
-#    include_next <limits.h>
-#  endif
-
-#endif // _LIBCPP_COMPILER_GCC
-
-#endif // _LIBCPP_LIMITS_H
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 6d9bb8653fcb5e9..1a06c2ef1f357f3 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -448,10 +448,6 @@ module std_inttypes_h [system] {
   export *
 }
 // <iso646.h> provided by compiler.
-module std_limits_h [system] {
-  header "limits.h"
-  export *
-}
 module std_locale_h [system] {
   header "locale.h"
   export *
diff --git a/libcxx/test/std/depr/depr.c.headers/limits_h.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/limits_h.compile.pass.cpp
index 4738cc4028cf95c..14fb8b69fac74ce 100644
--- a/libcxx/test/std/depr/depr.c.headers/limits_h.compile.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/limits_h.compile.pass.cpp
@@ -6,7 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
- // test limits.h
+// test <limits.h>
+//
+// Even though <limits.h> is not provided by libc++, we still test that
+// using it with libc++ on the search path will work.
 
 #include <limits.h>
 
diff --git a/libcxx/utils/data/ignore_format.txt b/libcxx/utils/data/ignore_format.txt
index e071aaabc6f41b7..93f7517050a9901 100644
--- a/libcxx/utils/data/ignore_format.txt
+++ b/libcxx/utils/data/ignore_format.txt
@@ -292,7 +292,6 @@ libcxx/include/__iterator/unreachable_sentinel.h
 libcxx/include/__iterator/wrap_iter.h
 libcxx/include/latch
 libcxx/include/limits
-libcxx/include/limits.h
 libcxx/include/list
 libcxx/include/__locale
 libcxx/include/locale



More information about the libcxx-commits mailing list