[libc-commits] [libc] 8e06210 - [libc][annex_k] Add errno_t (#163094)
via libc-commits
libc-commits at lists.llvm.org
Wed Mar 18 14:58:32 PDT 2026
Author: Muhammad Bassiouni
Date: 2026-03-18T23:58:27+02:00
New Revision: 8e062105593bee87b89ca99778b30e5695d398d7
URL: https://github.com/llvm/llvm-project/commit/8e062105593bee87b89ca99778b30e5695d398d7
DIFF: https://github.com/llvm/llvm-project/commit/8e062105593bee87b89ca99778b30e5695d398d7.diff
LOG: [libc][annex_k] Add errno_t (#163094)
RFC
https://discourse.llvm.org/t/rfc-bounds-checking-interfaces-for-llvm-libc/87685
Add `errno_t` type required by Annex K interface in LLVM libc.
Added:
libc/hdr/types/errno_t.h
libc/include/llvm-libc-types/errno_t.h
Modified:
libc/hdr/types/CMakeLists.txt
libc/include/CMakeLists.txt
libc/include/errno.yaml
libc/include/llvm-libc-types/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index dec73b0665f08..ba99a02a10118 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -162,6 +162,14 @@ add_proxy_header_library(
libc.include.fcntl
)
+add_proxy_header_library(
+ errno_t
+ HDRS
+ errno_t.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.errno_t
+)
+
add_proxy_header_library(
fenv_t
HDRS
diff --git a/libc/hdr/types/errno_t.h b/libc/hdr/types/errno_t.h
new file mode 100644
index 0000000000000..d83692a6585dd
--- /dev/null
+++ b/libc/hdr/types/errno_t.h
@@ -0,0 +1,30 @@
+//===-- Proxy for errno_t -------------------------------------------------===//
+//
+// 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_HDR_TYPES_ERRNO_T_H
+#define LLVM_LIBC_HDR_TYPES_ERRNO_T_H
+
+#ifndef __STDC_WANT_LIB_EXT1__
+#define __STDC_WANT_LIB_EXT1__ 1
+#endif
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/errno_t.h"
+
+#else // Overlay mode
+
+#include <errno.h>
+
+#endif // LIBC_FULL_BUILD
+
+#ifdef __STDC_WANT_LIB_EXT1__
+#undef __STDC_WANT_LIB_EXT1__
+#endif
+
+#endif // LLVM_LIBC_HDR_TYPES_ERRNO_T_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index b2ebd035872aa..9eae20c820e98 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -318,6 +318,7 @@ add_header_macro(
DEPENDS
.llvm-libc-macros.generic_error_number_macros
.llvm-libc-macros.error_number_macros
+ .llvm-libc-types.errno_t
)
add_header_macro(
diff --git a/libc/include/errno.yaml b/libc/include/errno.yaml
index 188a9fa1211a1..86afd2f03b20c 100644
--- a/libc/include/errno.yaml
+++ b/libc/include/errno.yaml
@@ -5,7 +5,8 @@ standards:
- Linux
- POSIX
macros: []
-types: []
+types:
+ - type_name: errno_t
enums: []
objects: []
functions: []
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 5d82660fd6762..09f9d759f0dd8 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -29,6 +29,7 @@ add_header(double_t HDR double_t.h)
add_header(DIR HDR DIR.h)
add_header(dev_t HDR dev_t.h)
add_header(div_t HDR div_t.h)
+add_header(errno_t HDR errno_t.h DEPENDS libc.include.llvm-libc-macros.annex_k_macros)
add_header(ldiv_t HDR ldiv_t.h)
add_header(lldiv_t HDR lldiv_t.h)
add_header(FILE HDR FILE.h)
diff --git a/libc/include/llvm-libc-types/errno_t.h b/libc/include/llvm-libc-types/errno_t.h
new file mode 100644
index 0000000000000..4ce694959ef2e
--- /dev/null
+++ b/libc/include/llvm-libc-types/errno_t.h
@@ -0,0 +1,26 @@
+//===-- Definition of type errno_t ----------------------------------------===//
+//
+// 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_INCLUDE_LLVM_LIBC_TYPES_ERRNO_T_H
+#define LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_ERRNO_T_H
+
+#include "../llvm-libc-macros/annex-k-macros.h"
+
+// LIBC_HAS_ANNEX_K is used to check whether C11 Annex K (the optional
+// “Bounds-checking interfaces”) is enabled in this libc implementation. Annex K
+// introduces additional types and functions, including `errno_t` (a typedef
+// used by the *_s functions). Since `errno_t` is *not defined* in the standard
+// library unless Annex K is enabled, we must guard any code that uses it with
+// LIBC_HAS_ANNEX_K.
+#ifdef LIBC_HAS_ANNEX_K
+
+typedef int errno_t;
+
+#endif // LIBC_HAS_ANNEX_K
+
+#endif // LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_ERRNO_T_H
More information about the libc-commits
mailing list