Skip to content

Commit 0353252

Browse files
[libc] add inttypes header
Add inttypes.h to llvm libc. As its first functions strtoimax and strtoumax are included. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D108736
1 parent dc94761 commit 0353252

19 files changed

+235
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ set(TARGET_LIBC_ENTRYPOINTS
4545
libc.src.string.strtok
4646
libc.src.string.strtok_r
4747

48+
# inttypes.h entrypoints
49+
libc.src.inttypes.strtoimax
50+
libc.src.inttypes.strtoumax
51+
4852
# stdlib.h entrypoints
4953
libc.src.stdlib.atoi
5054
libc.src.stdlib.atol

libc/config/linux/aarch64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
22
libc.include.ctype
33
libc.include.errno
44
libc.include.fenv
5+
libc.include.inttypes
56
libc.include.math
67
libc.include.stdlib
78
libc.include.string

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ set(TARGET_LIBC_ENTRYPOINTS
4545
libc.src.string.strtok
4646
libc.src.string.strtok_r
4747

48+
# inttypes.h entrypoints
49+
libc.src.inttypes.strtoimax
50+
libc.src.inttypes.strtoumax
51+
4852
# stdlib.h entrypoints
4953
libc.src.stdlib.atoi
5054
libc.src.stdlib.atol

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
22
libc.include.assert_h
33
libc.include.ctype
44
libc.include.errno
5+
libc.include.inttypes
56
libc.include.math
67
libc.include.signal
78
libc.include.stdio

libc/config/windows/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ set(TARGET_LIBC_ENTRYPOINTS
4545
libc.src.string.strtok
4646
libc.src.string.strtok_r
4747

48+
# inttypes.h entrypoints
49+
libc.src.inttypes.strtoimax
50+
libc.src.inttypes.strtoumax
51+
4852
# stdlib.h entrypoints
4953
libc.src.stdlib.atoi
5054
libc.src.stdlib.atol

libc/include/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ add_gen_header(
3333
.llvm_libc_common_h
3434
)
3535

36+
add_gen_header(
37+
inttypes
38+
DEF_FILE inttypes.h.def
39+
GEN_HDR inttypes.h
40+
DEPENDS
41+
.llvm_libc_common_h
42+
)
43+
3644
add_gen_header(
3745
math
3846
DEF_FILE math.h.def

libc/include/inttypes.h.def

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- C standard library header inttypes.h ------------------------------===//
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_INTTYPES_H
10+
#define LLVM_LIBC_INTTYPES_H
11+
12+
#include <__llvm-libc-common.h>
13+
#include <stdint.h>
14+
15+
%%public_api()
16+
17+
#endif // LLVM_LIBC_INTTYPES_H

libc/spec/spec.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def ConstVoidPtr : ConstType<VoidPtr>;
5454
def SizeTType : NamedType<"size_t">;
5555
def LongDoublePtr : PtrType<LongDoubleType>;
5656

57+
def IntMaxTType : NamedType<"intmax_t">;
58+
def UIntMaxTType : NamedType<"uintmax_t">;
59+
5760
// _Noreturn is really not a type, but it is convenient to treat it as a type.
5861
def NoReturn : NamedType<"_Noreturn void">;
5962

libc/spec/stdc.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,19 @@ def StdC : StandardSpec<"stdc"> {
489489
]
490490
>;
491491

492+
HeaderSpec IntTypes = HeaderSpec<
493+
"inttypes.h",
494+
[], // Macros
495+
[], // Types
496+
[], // Enumerations
497+
[
498+
FunctionSpec<"imaxabs", RetValSpec<IntMaxTType>, [ArgSpec<IntMaxTType>]>,
499+
FunctionSpec<"imaxdiv", RetValSpec<IntMaxTType>, [ArgSpec<IntMaxTType>, ArgSpec<IntMaxTType>]>,
500+
FunctionSpec<"strtoimax", RetValSpec<IntMaxTType>, [ArgSpec<ConstCharRestrictedPtr>, ArgSpec<CharRestrictedPtrPtr>, ArgSpec<IntType>]>,
501+
FunctionSpec<"strtoumax", RetValSpec<UIntMaxTType>, [ArgSpec<ConstCharRestrictedPtr>, ArgSpec<CharRestrictedPtrPtr>, ArgSpec<IntType>]>,
502+
]
503+
>;
504+
492505
HeaderSpec Errno = HeaderSpec<
493506
"errno.h",
494507
[
@@ -653,6 +666,7 @@ def StdC : StandardSpec<"stdc"> {
653666
String,
654667
StdIO,
655668
StdLib,
669+
IntTypes,
656670
Signal,
657671
Threads,
658672
Time,

libc/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_subdirectory(__support)
33
add_subdirectory(ctype)
44
add_subdirectory(errno)
55
add_subdirectory(fenv)
6+
add_subdirectory(inttypes)
67
add_subdirectory(math)
78
add_subdirectory(string)
89
add_subdirectory(stdlib)

0 commit comments

Comments
 (0)