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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Petr Hosek (petrhosek)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/84993.diff


9 Files Affected:

- (modified) libc/config/baremetal/api.td (+4) 
- (modified) libc/config/baremetal/arm/headers.txt (+1) 
- (modified) libc/config/baremetal/riscv/headers.txt (+1) 
- (modified) libc/include/CMakeLists.txt (+10) 
- (modified) libc/include/llvm-libc-types/CMakeLists.txt (+1) 
- (added) libc/include/llvm-libc-types/mbstate_t.h (+15) 
- (added) libc/include/uchar.h.def (+16) 
- (modified) libc/spec/spec.td (+2) 
- (modified) libc/spec/stdc.td (+11) 


``````````diff
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,
   ];
 }

``````````

</details>


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


More information about the libc-commits mailing list