Skip to content

Add basic char*_t support for libc (partial WG14 N2653) #90360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion libc/config/baremetal/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,10 @@ def TimeAPI : PublicAPI<"time.h"> {
}

def UCharAPI : PublicAPI<"uchar.h"> {
let Types = ["mbstate_t"];
let Types = [
"mbstate_t",
"char8_t",
"char16_t",
"char32_t",
];
}
2 changes: 2 additions & 0 deletions libc/config/linux/aarch64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ set(TARGET_PUBLIC_HEADERS
libc.include.threads
libc.include.time
libc.include.unistd
libc.include.wchar
libc.include.uchar

libc.include.sys_ioctl
# Disabled due to epoll_wait syscalls not being available on this platform.
Expand Down
9 changes: 9 additions & 0 deletions libc/config/linux/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ def WCharAPI : PublicAPI<"wchar.h"> {
];
}

def UCharAPI : PublicAPI<"uchar.h"> {
let Types = [
"mbstate_t",
"char8_t",
"char16_t",
"char32_t",
];
}

def SysRandomAPI : PublicAPI<"sys/random.h"> {
let Types = ["size_t", "ssize_t"];
}
Expand Down
2 changes: 2 additions & 0 deletions libc/config/linux/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ set(TARGET_PUBLIC_HEADERS
libc.include.string
libc.include.strings
libc.include.search
libc.include.wchar
libc.include.uchar

# Disabled due to epoll_wait syscalls not being available on this platform.
# libc.include.sys_epoll
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.time
libc.include.unistd
libc.include.wchar
libc.include.uchar

libc.include.arpa_inet

Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.time
libc.include.unistd
libc.include.wchar
libc.include.uchar

libc.include.arpa_inet

Expand Down
2 changes: 1 addition & 1 deletion libc/docs/c23.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ Additions:

* mbrtoc8
* c8rtomb
* char*_t
* char*_t |check|
3 changes: 3 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ add_gen_header(
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.mbstate_t
.llvm-libc-types.char8_t
.llvm-libc-types.char16_t
.llvm-libc-types.char32_t
)

add_gen_header(
Expand Down
15 changes: 15 additions & 0 deletions libc/include/llvm-libc-types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ add_header(tcflag_t HDR tcflag_t.h)
add_header(struct_termios HDR struct_termios.h DEPENDS .cc_t .speed_t .tcflag_t)
add_header(__getoptargv_t HDR __getoptargv_t.h)
add_header(wchar_t HDR wchar_t.h)
add_header(char8_t HDR char8_t.h)
add_header(
char16_t
HDR
char16_t.h
DEPENDS
libc.include.llvm-libc-macros.stdint_macros
)
add_header(
char32_t
HDR
char32_t.h
DEPENDS
libc.include.llvm-libc-macros.stdint_macros
)
add_header(wint_t HDR wint_t.h)
add_header(sa_family_t HDR sa_family_t.h)
add_header(socklen_t HDR socklen_t.h)
Expand Down
17 changes: 17 additions & 0 deletions libc/include/llvm-libc-types/char16_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Definition of char16_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_CHAR16_T_H
#define LLVM_LIBC_TYPES_CHAR16_T_H

#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#include "../llvm-libc-macros/stdint-macros.h"
typedef uint_least16_t char16_t;
#endif

#endif // LLVM_LIBC_TYPES_CHAR16_T_H
17 changes: 17 additions & 0 deletions libc/include/llvm-libc-types/char32_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Definition of char32_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_CHAR32_T_H
#define LLVM_LIBC_TYPES_CHAR32_T_H

#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#include "../llvm-libc-macros/stdint-macros.h"
typedef uint_least32_t char32_t;
#endif

#endif // LLVM_LIBC_TYPES_CHAR32_T_H
17 changes: 17 additions & 0 deletions libc/include/llvm-libc-types/char8_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Definition of char8_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_CHAR8_T_H
#define LLVM_LIBC_TYPES_CHAR8_T_H

#if !defined(__cplusplus) && defined(__STDC_VERSION__) && \
__STDC_VERSION__ >= 202311L
typedef unsigned char char8_t;
#endif

#endif // LLVM_LIBC_TYPES_CHAR8_T_H
3 changes: 3 additions & 0 deletions libc/spec/spec.td
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def SizeTType : NamedType<"size_t">;
def SizeTPtr : PtrType<SizeTType>;
def RestrictedSizeTPtr : RestrictedPtrType<SizeTType>;

def Char8TType : NamedType<"char8_t">;
def Char16TType : NamedType<"char16_t">;
def Char32TType : NamedType<"char32_t">;
def WCharType : NamedType<"wchar_t">;
def WIntType : NamedType<"wint_t">;

Expand Down
3 changes: 3 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,9 @@ def StdC : StandardSpec<"stdc"> {
[], // Macros
[ //Types
MBStateTType,
Char8TType,
Char16TType,
Char32TType,
],
[], // Enumerations
[]
Expand Down