[libc-commits] [libc] [libc] Add limits.h header. (PR #78887)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Tue Jan 23 10:46:58 PST 2024


================
@@ -0,0 +1,251 @@
+//===-- 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
+
+#if __has_include_next(<limits.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__, __GNUC__
+
+#if defined(__GNUC__) && !defined(__clang__) && !defined(_GCC_LIMITS_H_)
+// The system's limits.h may, in turn, try to #include_next GCC's limits.h when
+// building with GCC.
+// Define the macro _GCC_LIMITS_H_ to stop its chains of #include_next.
----------------
nickdesaulniers wrote:

It's the other way around.  It's gcc's limits.h which includes gcc's syslimits.h which reincluded gcc's limits.h which finally include_next's glibc's limits.h which is the problem.  I would reword this as:

> Prevent GCC from including glibc's limits.h.

---

For reference the include chain looks like:
```
In file included:
(GLIBC) from /usr/include/limits.h:26,
(GCC) from /usr/lib/gcc/x86_64-linux-gnu/13/include/limits.h:205,
(GCC) from /usr/lib/gcc/x86_64-linux-gnu/13/include/syslimits.h:7,
(GCC) from /usr/lib/gcc/x86_64-linux-gnu/13/include/limits.h:34,
(LLVMLIBC) from /android0/llvm-project/libc/src/__support/CPP/limits.h:16,
```

https://github.com/llvm/llvm-project/pull/78887


More information about the libc-commits mailing list