From ead9ac8331fd496ce4c348ab70e3709c68d46d50 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Fri, 27 Mar 2026 10:55:37 -0700 Subject: [PATCH] [libc] Remove header templates from several C standard headers. (#188878) 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 +- .../llvm-project-overlay/libc/BUILD.bazel | 20 +---- 9 files changed, 101 insertions(+), 87 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 c37c97c69a84..000000000000 --- 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 b664041bb56c..1f0956128fb0 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 930373eade4d..000000000000 --- 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 3c3998eb07aa..6934c123bed0 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 2355e8822fad..000000000000 --- 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 2311f045d150..defc6077e0b1 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 4c25de700d60..000000000000 --- 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 32e13d040621..1bd829dc5efd 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 diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 926f177681f9..b57b60490e57 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",