[libc-commits] [libc] [llvm] [libc] Remove header templates from several C standard headers. (PR #188878)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Fri Mar 27 10:49:32 PDT 2026


https://github.com/vonosmas updated https://github.com/llvm/llvm-project/pull/188878

>From 407c6f7b4b1965a9fc09d8dfa6518b3e665997a4 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Thu, 26 Mar 2026 23:25:45 +0000
Subject: [PATCH 1/2] [libc] Remove header templates from several C standard
 headers.

Switches the following headers to hdrgen-produced ones by
referencing some macro from C standard and the file containing the
declarations in corresponding YAML files:

* limits.h (referenced _WIDTH / _MAX / _MIN families).
* locale.h (referenced LC_ family).
* time.h (referenced CLOCKS_PER_SEC).
* wchar.h (referenced WEOF).
---
 libc/include/limits.h.def | 14 --------
 libc/include/limits.yaml  | 75 +++++++++++++++++++++++++++++++++++++--
 libc/include/locale.h.def | 18 ----------
 libc/include/locale.yaml  | 17 ++++++++-
 libc/include/time.h.def   | 17 ---------
 libc/include/time.yaml    |  5 ++-
 libc/include/wchar.h.def  | 17 ---------
 libc/include/wchar.yaml   |  5 ++-
 8 files changed, 97 insertions(+), 71 deletions(-)
 delete mode 100644 libc/include/limits.h.def
 delete mode 100644 libc/include/locale.h.def
 delete mode 100644 libc/include/time.h.def
 delete mode 100644 libc/include/wchar.h.def

diff --git a/libc/include/limits.h.def b/libc/include/limits.h.def
deleted file mode 100644
index c37c97c69a843..0000000000000
--- a/libc/include/limits.h.def
+++ /dev/null
@@ -1,14 +0,0 @@
-//===-- 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/limits.yaml b/libc/include/limits.yaml
index b664041bb56c2..1f0956128fb00 100644
--- a/libc/include/limits.yaml
+++ b/libc/include/limits.yaml
@@ -1,8 +1,79 @@
 header: limits.h
-header_template: limits.h.def
 standards:
   - stdc
-macros: []
+macros:
+  - macro_name: CHAR_BIT
+    macro_header: limits-macros.h
+  - macro_name: MB_LEN_MAX
+    macro_header: limits-macros.h
+  - macro_name: CHAR_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: SCHAR_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: UCHAR_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: SHRT_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: USHRT_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: INT_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: UINT_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: LONG_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: ULONG_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: LLONG_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: ULLONG_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: BOOL_WIDTH
+    macro_header: limits-macros.h
+  - macro_name: SCHAR_MAX
+    macro_header: limits-macros.h
+  - macro_name: UCHAR_MAX
+    macro_header: limits-macros.h
+  - macro_name: CHAR_MAX
+    macro_header: limits-macros.h
+  - macro_name: SHRT_MAX
+    macro_header: limits-macros.h
+  - macro_name: USHRT_MAX
+    macro_header: limits-macros.h
+  - macro_name: INT_MAX
+    macro_header: limits-macros.h
+  - macro_name: UINT_MAX
+    macro_header: limits-macros.h
+  - macro_name: LONG_MAX
+    macro_header: limits-macros.h
+  - macro_name: ULONG_MAX
+    macro_header: limits-macros.h
+  - macro_name: LLONG_MAX
+    macro_header: limits-macros.h
+  - macro_name: ULLONG_MAX
+    macro_header: limits-macros.h
+  - macro_name: SCHAR_MIN
+    macro_header: limits-macros.h
+  - macro_name: UCHAR_MIN
+    macro_header: limits-macros.h
+  - macro_name: CHAR_MIN
+    macro_header: limits-macros.h
+  - macro_name: SHRT_MIN
+    macro_header: limits-macros.h
+  - macro_name: USHRT_MIN
+    macro_header: limits-macros.h
+  - macro_name: INT_MIN
+    macro_header: limits-macros.h
+  - macro_name: UINT_MIN
+    macro_header: limits-macros.h
+  - macro_name: LONG_MIN
+    macro_header: limits-macros.h
+  - macro_name: ULONG_MIN
+    macro_header: limits-macros.h
+  - macro_name: LLONG_MIN
+    macro_header: limits-macros.h
+  - macro_name: ULLONG_MIN
+    macro_header: limits-macros.h
 types: []
 enums: []
 objects: []
diff --git a/libc/include/locale.h.def b/libc/include/locale.h.def
deleted file mode 100644
index 930373eade4d5..0000000000000
--- a/libc/include/locale.h.def
+++ /dev/null
@@ -1,18 +0,0 @@
-//===-- C standard library header locale.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_LOCALE_H
-#define LLVM_LIBC_LOCALE_H
-
-#include "__llvm-libc-common.h"
-
-#include "llvm-libc-macros/locale-macros.h"
-
-%%public_api()
-
-#endif // LLVM_LIBC_LOCALE_H
diff --git a/libc/include/locale.yaml b/libc/include/locale.yaml
index 3c3998eb07aa4..6934c123bed0b 100644
--- a/libc/include/locale.yaml
+++ b/libc/include/locale.yaml
@@ -1,8 +1,23 @@
 header: locale.h
-header_template: locale.h.def
+standards:
+  - stdc
 macros:
   - macro_name: "NULL"
     macro_header: null-macro.h
+  - macro_name: LC_ALL
+    macro_header: locale-macros.h
+  - macro_name: LC_COLLATE
+    macro_header: locale-macros.h
+  - macro_name: LC_CTYPE
+    macro_header: locale-macros.h
+  - macro_name: LC_MESSAGES
+    macro_header: locale-macros.h
+  - macro_name: LC_MONETARY
+    macro_header: locale-macros.h
+  - macro_name: LC_NUMERIC
+    macro_header: locale-macros.h
+  - macro_name: LC_TIME
+    macro_header: locale-macros.h
 types:
   - type_name: locale_t
   - type_name: struct_lconv
diff --git a/libc/include/time.h.def b/libc/include/time.h.def
deleted file mode 100644
index 2355e8822fad7..0000000000000
--- a/libc/include/time.h.def
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- C standard library header time.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_TIME_H
-#define LLVM_LIBC_TIME_H
-
-#include "__llvm-libc-common.h"
-#include "llvm-libc-macros/time-macros.h"
-
-%%public_api()
-
-#endif // LLVM_LIBC_TIME_H
diff --git a/libc/include/time.yaml b/libc/include/time.yaml
index 2311f045d1502..defc6077e0b13 100644
--- a/libc/include/time.yaml
+++ b/libc/include/time.yaml
@@ -1,8 +1,11 @@
 header: time.h
-header_template: time.h.def
+standards:
+  - stdc
 macros:
   - macro_name: "NULL"
     macro_header: null-macro.h
+  - macro_name: CLOCKS_PER_SEC
+    macro_header: time-macros.h
 types:
   - type_name: struct_timeval
   - type_name: clockid_t
diff --git a/libc/include/wchar.h.def b/libc/include/wchar.h.def
deleted file mode 100644
index 4c25de700d606..0000000000000
--- a/libc/include/wchar.h.def
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- C standard library header wchar.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_WCHAR_H
-#define LLVM_LIBC_WCHAR_H
-
-#include "__llvm-libc-common.h"
-#include "llvm-libc-macros/wchar-macros.h"
-
-%%public_api()
-
-#endif // LLVM_LIBC_WCHAR_H
diff --git a/libc/include/wchar.yaml b/libc/include/wchar.yaml
index 32e13d040621a..1bd829dc5efd6 100644
--- a/libc/include/wchar.yaml
+++ b/libc/include/wchar.yaml
@@ -1,8 +1,11 @@
 header: wchar.h
-header_template: wchar.h.def
+standards:
+  - stdc 
 macros:
   - macro_name: "NULL"
     macro_header: null-macro.h
+  - macro_name: WEOF
+    macro_header: wchar-macros.h
 types:
   - type_name: FILE
   - type_name: rsize_t

>From 7a5d9936328fe112dfbad0c1ce4a0518c9ea7a88 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Fri, 27 Mar 2026 17:48:44 +0000
Subject: [PATCH 2/2] Also update Bazel config.

---
 .../llvm-project-overlay/libc/BUILD.bazel     | 20 ++++---------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 926f177681f96..b57b60490e570 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -152,18 +152,10 @@ LLVM_LIBC_HEADERS = [
         "inttypes",
         has_def_template = True,
     ),
-    libc_header_info(
-        "limits",
-        has_def_template = True,
-    ),
     libc_header_info(
         "link",
         has_def_template = True,
     ),
-    libc_header_info(
-        "locale",
-        has_def_template = True,
-    ),
     libc_header_info(
         "math",
         has_def_template = True,
@@ -268,22 +260,16 @@ LLVM_LIBC_HEADERS = [
         "termios",
         has_def_template = True,
     ),
-    libc_header_info(
-        "time",
-        has_def_template = True,
-    ),
     libc_header_info(
         "unistd",
         has_def_template = True,
     ),
-    libc_header_info(
-        "wchar",
-        has_def_template = True,
-    ),
     libc_header_info("ctype"),
     libc_header_info("dirent"),
     libc_header_info("dlfcn"),
     libc_header_info("fenv"),
+    libc_header_info("limits"),
+    libc_header_info("locale"),
     libc_header_info("nl_types"),
     libc_header_info("pthread"),
     libc_header_info("search"),
@@ -295,7 +281,9 @@ LLVM_LIBC_HEADERS = [
     libc_header_info("sys/statvfs"),
     libc_header_info("sys/utsname"),
     libc_header_info("threads"),
+    libc_header_info("time"),
     libc_header_info("uchar"),
+    libc_header_info("wchar"),
     libc_header_info("wctype"),
     libc_header_info(
         "stdlib",



More information about the libc-commits mailing list