[libc-commits] [libc] e25bf70 - [libc] Add an empty definition of mbstate_t (#84993)

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


Author: Petr Hosek
Date: 2024-03-12T21:26:58-07:00
New Revision: e25bf70d50cbf8bdebeacdaf3313486c1b1d0395

URL: https://github.com/llvm/llvm-project/commit/e25bf70d50cbf8bdebeacdaf3313486c1b1d0395
DIFF: https://github.com/llvm/llvm-project/commit/e25bf70d50cbf8bdebeacdaf3313486c1b1d0395.diff

LOG: [libc] Add an empty definition of mbstate_t (#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.

Added: 
    libc/include/llvm-libc-types/mbstate_t.h
    libc/include/uchar.h.def

Modified: 
    libc/config/baremetal/api.td
    libc/config/baremetal/arm/headers.txt
    libc/config/baremetal/riscv/headers.txt
    libc/include/CMakeLists.txt
    libc/include/llvm-libc-types/CMakeLists.txt
    libc/spec/spec.td
    libc/spec/stdc.td

Removed: 
    


################################################################################
diff  --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
index 33b3a03828e9c7..f096cdcbc9a33f 100644
--- a/libc/config/baremetal/api.td
+++ b/libc/config/baremetal/api.td
@@ -66,3 +66,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..540d50975a264d
--- /dev/null
+++ b/libc/include/llvm-libc-types/mbstate_t.h
@@ -0,0 +1,16 @@
+//===-- 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
+
+// TODO: Complete this once we implement functions that operate on this type.
+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 580bd9c8c3c1c6..87bf4435e16724 100644
--- a/libc/spec/spec.td
+++ b/libc/spec/spec.td
@@ -153,6 +153,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 938d3722a0f82d..afe01b1bb68566 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -1284,12 +1284,23 @@ def StdC : StandardSpec<"stdc"> {
       ]
   >;
 
+  HeaderSpec UChar = HeaderSpec<
+      "uchar.h",
+      [], // Macros
+      [ //Types
+        MBStateTType,
+      ],
+      [], // Enumerations
+      []
+  >;
+
   HeaderSpec WChar = HeaderSpec<
       "wchar.h",
       [ // Macros
         Macro<"WEOF">,
       ],
       [ //Types
+        MBStateTType,
         SizeTType,
         WIntType,
         WCharType,
@@ -1324,6 +1335,7 @@ def StdC : StandardSpec<"stdc"> {
     Signal,
     Threads,
     Time,
+    UChar,
     WChar,
   ];
 }


        


More information about the libc-commits mailing list