[libc-commits] [libc] [libc] Add en empty definition of mbstate_t (PR #84993)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Tue Mar 12 16:27:10 PDT 2024


https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/84993

We expect to eventually provide a complete implementation, but having an empty definition is necessary to unblock the use of libc++ in embedded environments.

See #84884 for more details.

>From ed16ccfa9e7046dfb3a564a00eccf0e9b7f2d442 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Tue, 12 Mar 2024 16:04:56 -0700
Subject: [PATCH] [libc] Add en empty definition of mbstate_t

We expect to eventually provide a complete implementation, but having an
empty definition is necessary to unblock the use of libc++ in embedded
environments.

See #84884 for more details.
---
 libc/config/baremetal/api.td                |  4 ++++
 libc/config/baremetal/arm/headers.txt       |  1 +
 libc/config/baremetal/riscv/headers.txt     |  1 +
 libc/include/CMakeLists.txt                 | 10 ++++++++++
 libc/include/llvm-libc-types/CMakeLists.txt |  1 +
 libc/include/llvm-libc-types/mbstate_t.h    | 15 +++++++++++++++
 libc/include/uchar.h.def                    | 16 ++++++++++++++++
 libc/spec/spec.td                           |  2 ++
 libc/spec/stdc.td                           | 11 +++++++++++
 9 files changed, 61 insertions(+)
 create mode 100644 libc/include/llvm-libc-types/mbstate_t.h
 create mode 100644 libc/include/uchar.h.def

diff --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
index a132d8308122f7..337e5103a0cdf3 100644
--- a/libc/config/baremetal/api.td
+++ b/libc/config/baremetal/api.td
@@ -65,3 +65,7 @@ def StdlibAPI : PublicAPI<"stdlib.h"> {
 def StringAPI : PublicAPI<"string.h"> {
   let Types = ["size_t"];
 }
+
+def UCharAPI : PublicAPI<"uchar.h"> {
+  let Types = ["mbstate_t"];
+}
diff --git a/libc/config/baremetal/arm/headers.txt b/libc/config/baremetal/arm/headers.txt
index 68d7017fda8027..962981f8a2087d 100644
--- a/libc/config/baremetal/arm/headers.txt
+++ b/libc/config/baremetal/arm/headers.txt
@@ -13,4 +13,5 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.string
     libc.include.strings
     libc.include.sys_queue
+    libc.include.uchar
 )
diff --git a/libc/config/baremetal/riscv/headers.txt b/libc/config/baremetal/riscv/headers.txt
index 68d7017fda8027..962981f8a2087d 100644
--- a/libc/config/baremetal/riscv/headers.txt
+++ b/libc/config/baremetal/riscv/headers.txt
@@ -13,4 +13,5 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.string
     libc.include.strings
     libc.include.sys_queue
+    libc.include.uchar
 )
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 34d6839fd789a9..b2cb10459c53e3 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -582,6 +582,15 @@ add_gen_header(
     .llvm-libc-types.tcflag_t
 )
 
+add_gen_header(
+  uchar
+  DEF_FILE uchar.h.def
+  GEN_HDR uchar.h
+  DEPENDS
+    .llvm_libc_common_h
+    .llvm-libc-types.mbstate_t
+)
+
 add_gen_header(
   wchar
   DEF_FILE wchar.h.def
@@ -589,6 +598,7 @@ add_gen_header(
   DEPENDS
     .llvm_libc_common_h
     .llvm-libc-macros.wchar_macros
+    .llvm-libc-types.mbstate_t
     .llvm-libc-types.size_t
     .llvm-libc-types.wint_t
     .llvm-libc-types.wchar_t
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index e4f23b2a781305..7fef976d7b3250 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -39,6 +39,7 @@ add_header(uid_t HDR uid_t.h)
 add_header(imaxdiv_t HDR imaxdiv_t.h)
 add_header(ino_t HDR ino_t.h)
 add_header(jmp_buf HDR jmp_buf.h)
+add_header(mbstate_t HDR mbstate_t.h)
 add_header(mode_t HDR mode_t.h)
 add_header(mtx_t HDR mtx_t.h DEPENDS .__futex_word .__mutex_type)
 add_header(nlink_t HDR nlink_t.h)
diff --git a/libc/include/llvm-libc-types/mbstate_t.h b/libc/include/llvm-libc-types/mbstate_t.h
new file mode 100644
index 00000000000000..a4625491e43314
--- /dev/null
+++ b/libc/include/llvm-libc-types/mbstate_t.h
@@ -0,0 +1,15 @@
+//===-- Definition of mbstate_t type --------------------------------------===//
+//
+// 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_TYPES_MBSTATE_T_H
+#define LLVM_LIBC_TYPES_MBSTATE_T_H
+
+typedef struct {
+} mbstate_t;
+
+#endif // LLVM_LIBC_TYPES_MBSTATE_T_H
diff --git a/libc/include/uchar.h.def b/libc/include/uchar.h.def
new file mode 100644
index 00000000000000..7e62d43e9cc483
--- /dev/null
+++ b/libc/include/uchar.h.def
@@ -0,0 +1,16 @@
+//===-- C standard library header uchar.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_UCHAR_H
+#define LLVM_LIBC_UCHAR_H
+
+#include <__llvm-libc-common.h>
+
+%%public_api()
+
+#endif // LLVM_LIBC_UCHAR_H
diff --git a/libc/spec/spec.td b/libc/spec/spec.td
index 998f37fb26deed..cf9d1ff0bb7ee7 100644
--- a/libc/spec/spec.td
+++ b/libc/spec/spec.td
@@ -148,6 +148,8 @@ def EntryType : NamedType<"ENTRY">;
 def EntryTypePtr : PtrType<EntryType>;
 def EntryTypePtrPtr : PtrType<EntryTypePtr>;
 
+def MBStateTType : NamedType<"mbstate_t">;
+
 class Macro<string name> {
   string Name = name;
 }
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index cfebc60a0a9a8e..956f777a86d9b4 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -1249,6 +1249,16 @@ def StdC : StandardSpec<"stdc"> {
       ]
   >;
 
+  HeaderSpec UChar = HeaderSpec<
+      "uchar.h",
+      [], // Macros
+      [ //Types
+        MBStateTType,
+      ],
+      [], // Enumerations
+      []
+  >;
+
   HeaderSpec WChar = HeaderSpec<
       "wchar.h",
       [ // Macros
@@ -1289,6 +1299,7 @@ def StdC : StandardSpec<"stdc"> {
     Signal,
     Threads,
     Time,
+    UChar,
     WChar,
   ];
 }



More information about the libc-commits mailing list