1753 Commits

Author SHA1 Message Date
Muhammad Bassiouni
785d69e317
[libc][test] make str_to_float_comparison_test independent of C++ headers. (#133978)
This is an attempt to move away from C++ headers to be able to run the
test without `libcxx`.
closes #129838

cc @lntue @RossComputerGuy
2025-04-09 14:11:02 -07:00
wldfngrs
fdf20941a8
[libc][math] Fix signaling NaN handling for math functions. (#133347)
Add tests for signaling NaNs, and fix function behavior for handling
signaling NaN input.

Fixes https://github.com/llvm/llvm-project/issues/124812
2025-04-08 15:23:38 +02:00
Michael Jones
e8b52acca2
[libc][NFC] replace NULL with nullptr (#134464)
Simple cleanup
2025-04-04 16:55:43 -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
Michael Jones
c0079ba3dd
[libc] Make utimes_test more stable (#134321)
The test for utimes added in #134167 might fail if the file for one test
hasn't been cleaned up by the OS before the second test starts. This
patch makes the tests use different files.
2025-04-03 16:53:55 -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
Abhinav Kumar
51d1c72886
[libc] Added support for fixed-points in `is_signed and is_unsigned`. (#133371)
Fixes #133365

## Changes Done
- Changed the signed checking to 
```cpp
struct is_signed : bool_constant<((is_fixed_point<T> || is_arithmetic_v<T>) && (T(-1) < T(0)))>
```
in ``/libc/src/__support/CPP/type_traits/is_signed.h``. Added check for
fixed-points.
- But, got to know that this will fail for ``unsigned _Fract`` or any
unsigned fixed-point because ``unsigned _Fract`` can’t represent -1 in
T(-1), while ``unsigned int`` can handle it via wrapping.
- That's why I explicity added ``is_signed`` check for ``unsigned``
fixed-points.
- Same changes to ``/libc/src/__support/CPP/type_traits/is_unsigned.h``.
- Added tests for ``is_signed`` and ``is_unsigned``.
2025-04-02 16:41:47 -04:00
lntue
44b87e4206
[libc] Reduce the range of hypotf exhaustive test to be run automatically. (#133944)
The current setup of `hypotf` exhaustive tests might take days to
finish.
2025-04-01 13:29:28 -04:00
lntue
65ad6267e8
[libc] Fix atan2f128 test for aarch64. (#133924) 2025-04-01 11:37:57 -04: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
Joseph Huber
4abe47c6fc
[libc] Enable 'mktime' for the GPU (#133437)
Summary:
This is a dependency on `strftime` which we provide, so we should have
this.
2025-03-28 11:14:51 -05:00
Joseph Huber
9243f99d17
[libc] Add support for C++20 'atomic_ref' type (#132302)
Summary:
C++20 introduced an atomic reference type, which more easily wraps
around the standard way of dealing with atomics. Instead of a dedicated
type, it allows you to treat an existing allocation as atomic.

This has no users yet, but I'm hoping to use it when I start finalizing
my GPU allocation interface, as it will need to handle atomic values
in-place that can't be done with placement new. Hopefully this is small
enough that we can just keep it in-tree until it's needed, but I'll
accept holding it here until it has a user.

I added one extension to allow implicit conversion and CTAD.
2025-03-25 13:28:49 -05:00
Joseph Huber
6aed161cb9
[libc][NFC] Remove incorrect file level dependency in CMake (#132937)
Summary:
CMake doesn't support this type of dependency so it keeps emitting a
warning. Just remove it, because it's not doing anything currently
anyway. If we really wanted this to work you'd need to add a custom
target that has a dependency on the output of a custom command, but that
would only be worhwhile if we ever expected this file to change.
2025-03-25 09:33:25 -05:00
Alexey Samsonov
5a668bdb98
[libc] Migrate sys/epoll tests to use ErrnoCheckingTest. (#132823)
This is similar to PR #132107 but for tests for sys/epoll.h functions.

ErrnoCheckingTest ensures that errno is properly reset at the beginning
of the test case, and is validated at the end of it, so that the manual
code such as the one proposed in PR #131650 would not be necessary.
2025-03-24 13:54:46 -07:00
Roland McGrath
6f4ddefe5b
[libc] Remove extraneous ASSERT_ERRNO_* macro definitions (#132812)
These are no longer meant to be defined in each
framework-specific header, but ZxTest.h wasn't updated.
2025-03-24 12:25:43 -07:00
Tejas Vipin
1f96788701
[libc][math] Fix range and comments in exhaustive hypotf_test (#131769)
`((23U + 127U) << 23) + 1` evaluates to `(2^23)+1` as opposed to `2^24`,
so should instead be `(24U + 127U) << 23`. Additionally, range for both
inputs is inclusive of STOP. The comments have been updated reflecting
these changes.
2025-03-24 12:32:11 -04:00
Harrison Hao
445837a363
[libc][math][c23] Add fmaf16 C23 math function. (#130757)
Implementation of fmaf16 function for 16-bit inputs.
2025-03-23 10:48:56 +08:00
Harrison Hao
ee3e17d67f
[libc][math][c23] Add acoshf16 C23 math function. (#130588)
Implementation of acoshf16 function for 16-bit inputs.
2025-03-22 22:08:34 -04:00
Matheus Izvekov
4527085319
[clang] diagnose invalid member pointer class on instantiation (#132516) 2025-03-22 02:05:40 -03:00
lntue
17b5d6b242
[libc] Temporarily disable the type trait test affected by issue 132494. (#132501)
This test causes clang to crash due to #132494.
2025-03-21 21:57:37 -04:00
lntue
a17b03f0e4
[libc][math] Implement fast pass for double precision atan function. (#132333)
Implement fast pass for double precision `atan` using range reduction
modulo 1/64 and degree-9 Taylor polynomial.
Relative error is bounded by 2^-66.
2025-03-21 14:12:06 -04:00
Alexey Samsonov
4c36c425ec
[libc] Migrate sys/socket tests to use ErrnoCheckingTest. (#132107)
Also use ErrnoSetterMatcher to verify the function return values and
verify/clear out errno values. Fix the bug in ErrnoSetterMatcher error
reporting machinery to properly convert errno values into errno names to
make error messages easier to debug.
2025-03-19 15:33:20 -07:00
Alexey Samsonov
2f7ad891a7
[libc] Migrate unistd tests to use ErrnoCheckingTest. (#132067)
Use ErrnoCheckingTest harness added in
d039af33096c0a83b03475a240d5e281e2271c44 for all unistd tests that
verify errno values. Stop explicitly setting it to zero in test code, as
harness does it.

It also verifies that the errno is zero at the end of each test case, so
update the ASSERT_ERRNO_EQ and ASSERT_ERRNO_FAILURE macro to clear out
its value after the verification (similar to how ErrnoSetterMatcher
does).

Update the CMake and Bazel rules for those tests. In the latter case,
remove commented out tests that are currently unsupported in Bazel,
since they get stale quickly.
2025-03-19 13:29:52 -07:00
Connector Switch
2d09028771
[libc] Fix size_t and unsigned long mismatch on riscv32 in test. (#132028)
Fix regression:
https://github.com/llvm/llvm-project/pull/131431#issuecomment-2735029529
2025-03-19 22:30:51 +08:00
Connector Switch
af7c8c475a
[libc] Implement search/lsearch (#131431)
ref:
- https://man7.org/linux/man-pages/man3/lsearch.3.html
- https://pubs.opengroup.org/onlinepubs/009696699/functions/lsearch.html
2025-03-19 08:40:59 +08:00
Alexey Samsonov
d039af3309
[libc] Create ErrnoCheckingTest harness to simplify errno tests. (#131703)
See the discussion in PR
https://github.com/llvm/llvm-project/pull/131650 on why we need to clear
the errno at the beginning of some tests, and outlining the various solutions.

Introduce ErrnoCheckingTest base class and use it for unlink_test as an example.
2025-03-18 12:30:53 -07:00
OverMighty
1bb8b656a9
[libc][math] Fix incorrect logic in fputil::generic::add_or_sub (#116129)
Fixes incorrect logic that went unnoticed until the function was tested
with output and input types that have the same underlying floating-point
format.
2025-03-18 15:04:18 +01:00
Petr Hosek
1fbfef9b8a
[libc] Templatize the scanf Reader interface (#131037)
This allows specializing the implementation for different targets
without including unnecessary logic and is similar to #111559 which did
the same for printf Writer interface.
2025-03-17 23:51:24 -07:00
lntue
d0a0de50f7
[libc] Fix implicit conversion warnings in tests. (#131362) 2025-03-14 14:24:11 -04:00
Joseph Huber
598e882ee8
[libc] Template the writing mode for the writer class (#111559)
Summary:
Currently we dispatch the writing mode off of a runtime enum passed in
by the constructor. This causes very unfortunate codegen for the GPU
targets where we get worst-case codegen because of the unused function
pointer for `sprintf`. Instead, this patch moves all of this to a
template so it can be masked out. This results in no dynamic stack and
uses 60 VGPRs instead of 117. It also compiles about 5x as fast.
2025-03-12 13:51:44 -05:00
Connector Switch
ab22f652a4
[libc] implement strings/str{n}casecmp_l (#130407)
ref:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp_l.html

This patch introduces the `strcasecmp_l` function. At present, the
locale parameter is ignored, making it a stub implementation. This is
consistent with how other locale-related functions, such as `islower_l`,
are treated in our codebase as well as in
[musl](https://github.com/bminor/musl/blob/master/src/string/strcasecmp.c)
and
[bionic](https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/bionic/strings_l.cpp).

---------

Co-authored-by: Michael Jones <michaelrj@google.com>
2025-03-12 10:49:04 +08:00
Connector Switch
426caf1182
[libc] add locale proxy header (#130621)
Address review comments in #130407.

This patch is already covered by existing locale test cases.
2025-03-11 08:46:29 +08:00
Vinay Deshmukh
257e483715
[libc] Add -Wno-sign-conversion & re-attempt -Wconversion (#129811)
Relates to
https://github.com/llvm/llvm-project/issues/119281#issuecomment-2699470459
2025-03-10 11:57:09 -04:00
Ishaan Verma
735afc8ceb
[libc] Added type-generic macros for fixed-point functions (#129371)
Adds macros `absfx`, `countlsfx` and `roundfx` .
ref:  #129111
2025-03-09 00:11:34 -05:00
Connector Switch
a5588b6d20
[libc] implement strings/ffs (#129892)
This patch adds the `strings/ffs` function.
ref: https://pubs.opengroup.org/onlinepubs/9799919799/functions/ffs.html
Closes: #122054.
2025-03-08 09:31:18 +08:00
Alexey Samsonov
d90423e310
[libc][bazel] Minor cleanup to remove unused dependencies. (#130348)
* strcpy doesn't need to depend on memcpy
* qsort_test_helper has been generalized and doesn't need to depend on
qsort.

This is a small cleanup to unblock the work outlined in #130327.
2025-03-07 13:31:18 -08:00
Connector Switch
dd9a2f0677
[libc] first_trailing_one(0) should be 0. (#130155)
Fix this minor bug. See more context at #129892.
2025-03-08 00:11:43 +08:00
Augie Fackler
da61b0ddc5 Revert "[libc] Enable -Wconversion for tests. (#127523)"
This reverts commit 1e6e845d49a336e9da7ca6c576ec45c0b419b5f6 because it
changed the 1st parameter of adjust() to be unsigned, but libc itself
calls adjust() with a negative argument in align_backward() in
op_generic.h.
2025-03-05 16:42:40 -05:00
Vinay Deshmukh
1e6e845d49
[libc] Enable -Wconversion for tests. (#127523)
Relates to: #119281
2025-03-04 10:24:35 -05:00
Michael Jones
64ae0a102f
[libc] implement l64a (#129099)
Adds l64a, which generates the base 64 string expected by a64l.
2025-02-27 12:48:39 -08:00
lntue
4fd762caa6
[libc] Fix sqrtf128 smoke test for riscv32. (#129094) 2025-02-27 13:55:22 -05:00
Krishna Pandey
f6bfa33cdb
[libc][stdfix] Implement fixed point bitsfx functions in llvm libc (#128413)
Fixes #113359

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-02-27 13:05:27 -05:00
Michael Jones
8beec9fc48
[libc] implement a64l (#128758)
Implement the posix function a64l.
Standard:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/a64l.html
2025-02-25 13:57:13 -08:00
wldfngrs
3e284554a8
[libc][math][c23] Add acosf16() function (#127731)
- Implementation of acosf16 (inverse cosine) function for 16-bit inputs.
- Exhaustive tests across the 16-bit input range.
2025-02-23 19:46:46 +01:00
lntue
8ea6b735a6
[libc] Fix alignment issue for HermeticTestUtils.cpp. (#128426)
Full build precommit bots were failing due to mis-alignment of atomics
in hermetic tests. This PR enforces the alignment for the bump allocator
of hermetic test framework.

Fixes https://github.com/llvm/llvm-project/issues/128185.
2025-02-23 13:41:51 -05:00
Joseph Huber
559cb6ba63 [libc] Fix scanf dependencies on the GPU build
Summary:
The GPU build doesn't have `file` as a struct but does use these
targets. We need to add an escape for this.
2025-02-22 13:14:20 -06:00
Michael Jones
3fad640f06
[libc] Skip scanf internals when no file available (#128097)
A temporary fix based on discussions in #128079

Currently, baremetal targets are failing to build because the scanf
internals require FILE* (either from the system's libc or our libc).
Normally we'd just turn off the broken entrypoint, but since the scanf
internals are built separately that doesn't work. This patch adds extra
conditions to building those internals, which we can hopefully remove
once we have a proper way to build scanf for embedded.
2025-02-21 12:26:23 -08:00