Skip to content

Commit 68236e5

Browse files
committed
Add basic char*_t support for libc
- Define C23 char8_t - Define C11 char16_t - Define C11 char32_t
1 parent 38a2051 commit 68236e5

File tree

9 files changed

+69
-1
lines changed

9 files changed

+69
-1
lines changed

libc/config/baremetal/api.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,10 @@ def TimeAPI : PublicAPI<"time.h"> {
8585
}
8686

8787
def UCharAPI : PublicAPI<"uchar.h"> {
88-
let Types = ["mbstate_t"];
88+
let Types = [
89+
"mbstate_t",
90+
"char8_t",
91+
"char16_t",
92+
"char32_t",
93+
];
8994
}

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(TARGET_PUBLIC_HEADERS
2929
libc.include.time
3030
libc.include.unistd
3131
libc.include.wchar
32+
libc.include.uchar
3233

3334
libc.include.arpa_inet
3435

libc/include/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@ add_gen_header(
603603
DEPENDS
604604
.llvm_libc_common_h
605605
.llvm-libc-types.mbstate_t
606+
.llvm-libc-types.char8_t
607+
.llvm-libc-types.char16_t
608+
.llvm-libc-types.char32_t
606609
)
607610

608611
add_gen_header(

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ add_header(tcflag_t HDR tcflag_t.h)
9090
add_header(struct_termios HDR struct_termios.h DEPENDS .cc_t .speed_t .tcflag_t)
9191
add_header(__getoptargv_t HDR __getoptargv_t.h)
9292
add_header(wchar_t HDR wchar_t.h)
93+
add_header(char8_t HDR char8_t.h)
94+
add_header(char16_t HDR char16_t.h)
95+
add_header(char32_t HDR char32_t.h)
9396
add_header(wint_t HDR wint_t.h)
9497
add_header(sa_family_t HDR sa_family_t.h)
9598
add_header(socklen_t HDR socklen_t.h)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Definition of clock_t type ----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES_CHAR8_T_H
10+
#define LLVM_LIBC_TYPES_CHAR8_T_H
11+
12+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
13+
#include <stdint.h>
14+
typedef uint_least16_t char16_t;
15+
#endif
16+
17+
#endif // LLVM_LIBC_TYPES_CHAR8_T_H
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Definition of clock_t type ----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES_CHAR8_T_H
10+
#define LLVM_LIBC_TYPES_CHAR8_T_H
11+
12+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
13+
#include <stdint.h>
14+
typedef uint_least32_t char32_t;
15+
#endif
16+
17+
#endif // LLVM_LIBC_TYPES_CHAR8_T_H
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===-- Definition of clock_t type ----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES_CHAR8_T_H
10+
#define LLVM_LIBC_TYPES_CHAR8_T_H
11+
12+
#if !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
13+
typedef unsigned char char8_t;
14+
#endif
15+
16+
#endif // LLVM_LIBC_TYPES_CHAR8_T_H

libc/spec/spec.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def SizeTType : NamedType<"size_t">;
6565
def SizeTPtr : PtrType<SizeTType>;
6666
def RestrictedSizeTPtr : RestrictedPtrType<SizeTType>;
6767

68+
def Char8TType : NamedType<"char8_t">;
69+
def Char16TType : NamedType<"char16_t">;
70+
def Char32TType : NamedType<"char32_t">;
6871
def WCharType : NamedType<"wchar_t">;
6972
def WIntType : NamedType<"wint_t">;
7073

libc/spec/stdc.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,9 @@ def StdC : StandardSpec<"stdc"> {
13961396
[], // Macros
13971397
[ //Types
13981398
MBStateTType,
1399+
Char8TType,
1400+
Char16TType,
1401+
Char32TType,
13991402
],
14001403
[], // Enumerations
14011404
[]

0 commit comments

Comments
 (0)