William Huynh
fd432151a6
[libc] Fix bugs found when testing with all headers ( #144049 )
...
Fixes a couple of bugs found when building. The PR to enable the headers
can be found here: #144114 .
- math.yaml: float128 guard
- wchar.yaml: __restrict keyword order
2025-06-13 10:26:40 -07:00
Uzair Nawaz
b184672ec7
[libc] Implemented wmemmove ( #142245 )
...
Implemented wmemmove and added tests
2025-06-13 16:48:24 +00:00
Michael Jones
5a6a4b6ba6
[libc] Implement perror ( #143624 )
...
The perror function writes an error message directly to stderr. This
patch adds an implementation, tests, and header generation details.
2025-06-12 10:45:47 -07:00
Uzair Nawaz
6311f039b2
[libc] Build fixes for widechar characterconverter ( #143805 )
...
Build fixes for wchar CharacterConverter class
2025-06-12 17:34:45 +00:00
lntue
82f19674bf
[libc] Update size_t and ssize_t definitions to use __SIZE_TYPE__ and __PTRDIFF_TYPE__ respectively. ( #143921 )
...
The current definition of `ssize_t` does not have the same bit width as
`size_t` on 32-bit platforms.
2025-06-12 13:11:42 -04:00
W. Turner Abney
4039fdb7ba
[libc] add ioctl ( #141393 )
...
Closes #85275
Closes #90317
Updates #97191
---------
Co-authored-by: Joseph Huber <huberjn@outlook.com >
Co-authored-by: Michael Jones <michaelrj@google.com >
2025-06-12 09:20:32 -07:00
William
117e78fe50
[libc] Add NULL macro definitions to header files ( #142764 )
...
By the C standard, <locale.h>, <stddef.h> <stdio.h>, <stdlib.h>,
<string.h>, <time.h>, and <wchar.h> require NULL to be defined.
2025-06-11 09:51:34 -07:00
William
a75fc765d3
[libc] Add definitions to embedded AArch32/AArch64 ( #142597 )
...
Add `CLOCKS_PER_SEC` and the older `CLK_TCK`. Allows the user to define
a `__CLK_TCK` to override if necessary.
Also add an extra column for embedded AArch64 in `time.rst`
2025-06-06 16:05:14 -04:00
sribee8
22dd9a2483
[libc] wmemchr implementation ( #142640 )
...
Implemented wmemchr and tests.
Fixes : #121183
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-06-03 17:05:14 -07:00
sribee8
2ff2a076cc
[libc] wcsncpy implementation ( #142237 )
...
Implemented wcsncpy and tests for the function.
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-06-03 16:37:14 -07:00
sribee8
3887c23059
[libc] wcscat implementation ( #142243 )
...
Implemented wcscat and tests.
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-06-03 09:58:08 -07:00
Michael Jones
cc68367bb9
[libc][obvious] fix wchar yaml formatting ( #142506 )
...
The yaml ended up with a typo, possibly due to merge issues. This patch
fixes it.
2025-06-02 17:00:23 -07:00
Uzair Nawaz
c8741851d1
[libc] Implemented wcsncmp ( #142429 )
...
Implemented wcsncmp and added tests
2025-06-02 16:05:47 -07:00
sribee8
e3d1a33b7e
[libc] wcsstr implementation ( #142440 )
...
Implemented wcsstr and tests.
fixes #124348
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-06-02 16:05:12 -07:00
sribee8
9422abf9eb
[libc] wcsncat implementation ( #142431 )
...
Implemented wcsncat and tests.
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-06-02 15:20:10 -07:00
Uzair Nawaz
dabe983e7e
[libc] Implemented wcsrchr ( #142436 )
...
fixes #124347
Implemented wcsrchr and added tests
2025-06-02 15:18:44 -07:00
Uzair Nawaz
62af2a5ae2
[libc] Implemented wcscmp ( #142423 )
...
Implemented wcscmp and added tests
2025-06-02 15:16:14 -07:00
Uzair Nawaz
c80c452525
[libc] Implemented wmempcpy ( #142067 )
...
Implemented wmempcpy and added tests
2025-06-02 15:00:46 -07:00
sribee8
e38375310e
[libc] wcscpy implementation ( #142228 )
...
Implemented wcscpy as well as tests for the function.
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-06-02 11:20:25 -07:00
wldfngrs
573545c712
[libc][math][c23] Add atanf16() function ( #141612 )
...
- Implementation of atan (tan inverse) function for 16-bit inputs.
- Exhaustive tests across the 16-bit input range
2025-06-01 13:36:16 +02:00
sribee8
339851e140
[libc][obvious] Fixed wchar.yaml ( #142238 )
...
Changed __restricted to __restrict for wmemcpy.
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-05-30 16:41:11 -07:00
sribee8
226d06ba43
[libc] wmemcpy implementation ( #142070 )
...
Implemented wmemcpy and tests for the function.
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-05-30 14:23:18 -07:00
Uzair Nawaz
d721d4e280
[libc] Implemented wcspbrk ( #142040 )
...
Implemented wcspbrk and added tests
2025-05-30 14:12:22 -07:00
sribee8
d4791f56f3
[libc] wcsspn implementation ( #142034 )
...
Implemented wcsspn as well as tests for the function.
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-05-30 12:52:43 -07:00
sribee8
a8c6a5017d
[libc] wmemcmp implementation ( #141880 )
...
Implemented wmemcmp as well as tests for the function.
Fixes Issue #141857
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-05-29 13:34:23 -07:00
Uzair Nawaz
6cf53da79d
[libc] Implemented wmemset and added tests ( #141691 )
...
Implemented and tests the wmemset function in libc.
2025-05-29 10:31:49 -07:00
sribee8
cfba7718d2
WCSChr Implementation ( #141690 )
...
implemented wcschr and tests
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com >
2025-05-28 14:08:03 -07:00
Mikhail R. Gadelha
36b4ffeb7e
[libc] Enable utimes function for riscv ( #139181 )
...
RV32 uses SYS_utimensat_time64 instead of SYS_utimensat but the call is
the same.
2025-05-13 18:59:49 -03:00
Mikhail R. Gadelha
66bb445d5c
[libc] Enable poll function for riscv ( #139180 )
...
RV32 uses SYS_ppoll_time64 instead of SYS_ppoll, but the call is the
same.
2025-05-13 18:59:28 -03:00
lntue
3b62a3369a
[libc] Add struct entry definition in addition to ENTRY according to POSIX. ( #139773 )
2025-05-13 15:48:30 -04:00
Tristan Ross
865fb9c1a5
[libc][uefi] add crt1 ( #132150 )
...
Adds `crt1.o` for the UEFI platform in the LLVM C library. This makes
things start to become useful.
2025-05-09 09:02:33 -07:00
lntue
78cc822aa6
[libc][math] Implement double precision acos correctly rounded for all rounding modes. ( #138308 )
...
We reduce computation of `acos` to `asin` as follow:
When `|x| < 0.5`:
```math
acos(x) = \frac{\pi}{2} - asin(x).
```
For `0.5 <= |x| < 1`, let
```math
u = \frac{1 - \left| x \right|}{2},
```
then
```math
acos(x) = \begin{cases}
2 \cdot asin \left( \sqrt{u} \right) &, 0.5 \leq x < 1 \\
\pi - 2 \cdot asin \left( \sqrt{u} \right) &, -1 < x \leq 0.5
\end{cases}
```
2025-05-08 23:23:09 -04:00
enh-google
e79dc76b5f
stdlib.yaml: qsort_r() is in POSIX 2024 (aka issue 8). ( #138572 )
2025-05-06 09:36:10 -04:00
Schrodinger ZHU Yifan
a1803ea063
[libc] implement sigsetjmp/siglongjmp for riscv ( #137992 )
...
See https://godbolt.org/z/jo7s6j7sq for compiled code.
```c++
#if __riscv_xlen == 64
#define STORE(A, B, C) "sd " #A ", %c[" #B "](" #C ")\n\t"
#define LOAD(A, B, C) "ld " #A ", %c[" #B "](" #C ")\n\t"
#elif __riscv_xlen == 32
#define STORE(A, B, C) "sw " #A ", %c[" #B "](" #C ")\n\t"
#define LOAD(A, B, C) "lw " #A ", %c[" #B "](" #C ")\n\t"
#else
#error "Unsupported RISC-V architecture"
#endif
namespace LIBC_NAMESPACE_DECL {
[[gnu::naked]]
LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf, int)) {
// clang-format off
asm("beqz a1, .Lnosave\n\t"
STORE(ra, retaddr, a0)
STORE(s0, extra, a0)
"mv s0, a0\n\t"
"call %c[setjmp]\n\t"
"mv a1, a0\n\t"
"mv a0, s0\n\t"
LOAD(s0, extra, a0)
LOAD(ra, retaddr, a0)
"tail %c[epilogue]\n"
".Lnosave:\n\t"
"tail %c[setjmp]"
// clang-format on
::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)),
[extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp),
[epilogue] "i"(sigsetjmp_epilogue)
: "a0", "a1", "s0");
}
```
2025-05-04 16:21:48 -04:00
Schrodinger ZHU Yifan
9ebaa9d483
[libc] implement aarch64 sigsetjmp ( #136706 )
...
- **[libc][aarch64] implement sigsetjmp**
On top of https://github.com/llvm/llvm-project/pull/136072
See also https://github.com/llvm/llvm-project/issues/137055 for remarks
on naked attributes.
```c++
//===-- Implementation of setjmp ------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "src/setjmp/sigsetjmp.h"
#include "hdr/offsetof_macros.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/setjmp/setjmp_impl.h"
#include "src/setjmp/sigsetjmp_epilogue.h"
namespace LIBC_NAMESPACE_DECL {
[[gnu::naked]]
LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf, int)) {
asm(R"(
cbz w1, %c[setjmp]
str x30, [x0, %c[retaddr]]
str x19, [x0, %c[extra]]
mov x19, x0
bl %c[setjmp]
mov w1, w0
mov x0, x19
ldr x30, [x0, %c[retaddr]]
ldr x19, [x0, %c[extra]]
b %c[epilogue])" ::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)),
[extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp),
[epilogue] "i"(sigsetjmp_epilogue)
: "x0", "x1", "x19", "x30");
}
} // namespace LIBC_NAMESPACE_DECL
```
2025-04-29 16:37:25 -04:00
Schrodinger ZHU Yifan
6695976d16
Reland "[libc] build fix for sigsetjmp ( #137047 )" ( #137214 )
...
Reland `sigsetjmp` patches with build fixes.
We wrap every target replying on the epilogue library into conditional
checks.
---------
Co-authored-by: Petr Hosek <phosek@google.com >
2025-04-29 09:28:42 -04:00
Michael Jones
9124e963a3
[libc] Update assert for C23 ( #137402 )
...
Previously the assert macro took one argument named "e", but this led to
possible errors if the caller had commas in their input. C23 changed the
definition of assert to use `__VA_ARGS__` to ensure comma cases are
handled properly. This patch doesn't introduce the enforcement function
mentioned in the standard update, though that may be done in a followup.
Fixes #136184
2025-04-28 15:06:52 -04:00
Krishna Pandey
5ff277462d
[libc][stdfix] Implement idivfx functions in LLVM libc ( #133005 )
...
This PR implements the following 8 functions along with the tests.
```c++
int idivr(fract, fract);
long int idivlr(long fract, long fract);
int idivk(accum, accum);
long int idivlk(long accum, long accum);
unsigned int idivur(unsigned fract, unsigned fract);
unsigned long int idivulr(unsigned long fract, unsigned long fract);
unsigned int idivuk(unsigned accum, unsigned accum);
unsigned long int idivulk(unsigned long accum, unsigned long accum);
```
ref: https://www.iso.org/standard/51126.html
Fixes #129125
---------
Signed-off-by: krishna2803 <kpandey81930@gmail.com >
2025-04-25 07:58:16 -04:00
Harrison Hao
accee2b553
[libc][math][c23] Add atanhf16 C23 math function. ( #132612 )
...
Implementation of atanhf16 function for 16-bit inputs.
Closes: https://github.com/llvm/llvm-project/issues/132209
2025-04-25 07:53:52 -04:00
Anton
851f7c7421
[libc][math][c23] Add acospif16() function ( #134664 )
...
Addresses #132211 #132754
Part of #95250
2025-04-24 18:03:24 -04:00
gulfemsavrun
0d00b6bc3b
Revert "[libc] build fix for sigsetjmp ( #137047 )" ( #137077 )
...
This reverts commit f07511a0e0 .
This reverts commit 5bb4cf9d91 .
It caused a CMake configuration issue.
2025-04-23 15:49:55 -07:00
Schrodinger ZHU Yifan
5bb4cf9d91
[libc] implement sigsetjmp/siglongjmp for x86-64 ( #136072 )
2025-04-23 14:19:47 -04:00
Tsz Chan
f5c5f9f926
[libc] Implement getitimer and setitimer, add proxy headers for itimerval ( #134773 )
...
#133983
2025-04-14 13:39:42 -07:00
Michael Jones
4c182df633
[libc] Fix suseconds_t definition and utimes_test ( #134326 )
...
The main issue was that the kernel expected `suseconds_t` to be 64 bits
but ours was 32. This caused inconsistent failures since all valid
`suseconds_t` values are less than 1000000 (1 million), and some
configurations caused `struct timeval` to be padded to 128 bits.
Also: forgot to use TEST_FILE instead of FILE_PATH in some places.
2025-04-04 12:53:46 -07:00
Aditya Tejpaul
d33ae41c62
[libc] Implemented utimes (Issue #133953 ) ( #134167 )
...
This pull request implements the `utimes` command in libc ([Issue
#133953 ](https://github.com/llvm/llvm-project/issues/133953 )).
- [x] Add the implementation of `utimes` in `/src/sys/time`.
- [x] Add tests for `utimes` in `/test/src/sys/time`.
- [x] Add `utimes` to
[entrypoints.txt](https://github.com/llvm/llvm-project/blob/main/libc/config/linux/x86_64/entrypoints.txt )
for at least x86_64 and whatever you're building on
- [x] Add `utimes` to
[include/sys/time.yaml](https://github.com/llvm/llvm-project/blob/main/libc/include/sys/time.yaml )
2025-04-03 16:19:12 -07:00
Connector Switch
b738b82699
[libc] Combine the function prototype int (*compar)(const void *, const void *) ( #134238 )
...
Closes #134118 .
2025-04-04 00:36:23 +08:00
lntue
8741412bdf
[libc][math] Implement a fast pass for atan2f128 with 1ULP error using DyadicFloat<128>. ( #133150 )
...
Part of https://github.com/llvm/llvm-project/issues/131642 .
2025-04-01 10:57:32 -04:00
Tejas Vipin
8078665bca
[libc][math][c23] Add hypotf16 function ( #131991 )
...
Implement hypot for Float16 along with tests.
2025-03-31 10:06:28 -04:00
Tejas Vipin
d22e35be17
[libc][math][c23] Add asinhf16 function ( #131351 )
...
Implement asinh for Float16 along with tests. Closes #131001
2025-03-29 13:54:52 +01:00
Mohamed Emad
4840895467
[libc] implement memalignment ( #132493 )
...
This patch adds the `memalignment` function to LLVM-libc, following its
description in [WG14 N3220,
§7.24.2.1](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf#page=387 ).
- [x] Add the implementation of `memalignment` in
[`/src/stdlib`](https://github.com/llvm/llvm-project/tree/main/libc/src/stdlib )
- [x] Add tests for `memalignment` in
[`/test/src/stdlib`](https://github.com/llvm/llvm-project/tree/main/libc/test/src/stdlib )
- [x] Add `memalignment` to
[`entrypoints.txt`](https://github.com/llvm/llvm-project/blob/main/libc/config/linux/x86_64/entrypoints.txt )
for at least x86_64 and whatever you're building on
- [x] Add `memalignment` to
[`include/stdlib.yaml`](https://github.com/llvm/llvm-project/blob/main/libc/include/stdlib.yaml )
Closes #132300
---------
Co-authored-by: Joseph Huber <huberjn@outlook.com >
2025-03-28 16:07:57 -07:00