4123 Commits

Author SHA1 Message Date
Alexey Samsonov
07504afc42
[libc] Stop depending on .cpp files in libcxx_shared_headers library. (#133999)
Fix two instances of libcxx_shared_headers depending on .cpp files (in
Bazel build):

* Don't depend on exit syscall in LIBC_ASSERT implementation. This
dependency is not used, since LIBC_ASSERT always uses system <assert.h>
in the overlay mode, which is the only mode supported by Bazel.
* Don't depend on libc_errno in str-to-float and str-to-integer
conversions. We only need the ERANGE value, which can be obtained from
the proxy header instead.
2025-04-01 16:23:19 -07: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
Mikhail R. Gadelha
091051fb7f
[libc] Add myself as maintainer of the riscv port (#133757)
Co-authored-by: Joseph Huber <huberjn@outlook.com>
2025-03-31 20:13:44 -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
Michael Jones
6cc208cd3c
[libc] Add maintainers file (#133471)
Based on #133297 by jhuber.

LLVM-libc needs a maintainers file, this patch adds an initial set.
The file is based on `clang/maintainers.rst` and
https://llvm.org/docs/DeveloperPolicy.html#maintainers.
2025-03-28 16:50:19 -07: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
Qinkun Bao
91d2ecf0d5
[NFC] Fix some typos in libc and mlir comments (#133374) 2025-03-28 15:52:37 -04: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
772173f548
[Clang][AMDGPU] Remove special handling for COV4 libraries (#132870)
Summary:
When we were first porting to COV5, this lead to some ABI issues due to
a change in how we looked up the work group size. Bitcode libraries
relied on the builtins to emit code, but this was changed between
versions. This prevented the bitcode libraries, like OpenMP or libc,
from being used for both COV4 and COV5. The solution was to have this
'none' functionality which effectively emitted code that branched off of
a global to resolve to either version.

This isn't a great solution because it forced every TU to have this
variable in it. The patch in
https://github.com/llvm/llvm-project/pull/131033 removed support for
COV4 from OpenMP, which was the only consumer of this functionality.
Other users like HIP and OpenCL did not use this because they linked the
ROCm Device Library directly which has its own handling (The name was
borrowed from it after all).

So, now that we don't need to worry about backward compatibility with
COV4, we can remove this special handling. Users can still emit COV4
code, this simply removes the special handling used to make the OpenMP
device runtime bitcode version agnostic.
2025-03-28 07:35:16 -05:00
Jesse D
f76254d9b2
[libc] Fix implicit conversion error in DyadicFloat::as_mantissa_type(). (#133383)
This is the same fix that was recently applied to
as_mantissa_type_rounded(), but for as_mantissa_type().
2025-03-28 08:31:17 -04:00
Michael Jones
3a5d77608b
[libc] Update headers on aarch64 (#133180)
The entrypoints for aarch64 are mostly up to date, but the headers are
not. This patch fixes that, and also makes explicit the dependency from
OSUtils/linux on sys/syscalls.h
2025-03-27 09:05:24 -07:00
Joseph Huber
d0aa1f9c43
[Clang] Make --lto-partitions only default for HIP (#133164)
Summary:
The default behavior for LTO on other targets does not specify the
number of LTO partitions. Recent changes made this default to 8 on
AMDGPU which had some issues with the `libc` project. The option to
disable this is HIP only so I think for now we should restrict this just
to HIP.

I'm definitely on board with getting some more parallelism here, but I
think it should probably be restricted to just offloading languages. The
new driver goes through the `--target=amdgcn-amd-amdhsa` for its output,
which means we'd need to forward the default somehow.
2025-03-27 07:34:57 -05:00
Schrodinger ZHU Yifan
7b130f4aa8
[libc][CPP] correct cmpxchg failure ordering inference (#133127)
See https://en.cppreference.com/w/cpp/atomic/atomic/compare_exchange.
The failure order should be inferred from the success order if it is not
explicitly specified.
2025-03-26 15:29:08 -04:00
Joseph Huber
0106e5ad91 [libc] Temporarily disable LTO flags for AMDGPU crt1.o
Summary:
Some recent changes seem to have introduced a bug that breaks this. Turn
it off while I triage it.
2025-03-26 12:55:43 -05:00
Joseph Huber
e376f3129a [libc] Make RPC allocation size query constexpr
Summary:
Let this be used for a static array.
2025-03-26 09:21:43 -05:00
Amy Huang
69274839c3
Change check for "shift > Type::BITS" to avoid offset greater than total bits. (#133016)
nexttowardf16_test is resulting in calling shift and for some reason not
meeting the invariant where offset is less than bits. Change the if
statement to directly check if shift - 1 meets the conditions.
2025-03-25 23:41:35 -04:00
Connector Switch
7a5ce55124
[libc] Add VISIT enum for search.h (#132746)
This patch introduces the `VISIT` enum for tree search. Existing tests
ensure the correct generation of headers.
2025-03-26 10:00:32 +08:00
Michael Jones
c995db3e34
[libc] Add exceptional values for sinhf16/coshf16 (#133002)
The rounding of the result when using an FMA instruction for hyperbolic
sin/cos on float16 was off by 1 bit for a few cases. This patch adds
extra exceptional cases to handle these.
2025-03-25 16:29:48 -07: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
Paul Kirth
9fb7924966
[libc][time] Fix -Wshorten-64-to-32 warning (#132947)
This breaks builds of libc with top of tree clang under -Werror.
2025-03-25 08:53:08 -07: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
Leslie
ba46c37f9c
[libc] change the return value type of mktime_internal to time_t (#132231)
This pr is to resovle #126948

---------

Co-authored-by: Joseph Huber <huberjn@outlook.com>
2025-03-25 09:09:15 -05:00
Paul Kirth
0aa4c35beb
[libc][__support] Fix -Wimplicit-int-conversion warning (#132839)
Newer versions of clang now warn about these, so use explicit
conversion instead.
2025-03-24 16:47:07 -07: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
Abhinav Kumar
7f52d050ab
[libc] Enable stdfix functions for macOS arm64 targets. (#132674)
Fixes #132673 

Added ```libc.src.stdfix.*``` into
```libc/config/darwin/arm/entrypoints.txt```.

All tests related to ```stdfix``` has passed.
2025-03-24 09:42:31 -04:00
Harrison Hao
ebcf1de065
[libc][math] Disable acoshf16 Test on AArch64 to resolve test failures. (#132580) 2025-03-23 11:19:20 +08: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
Mohamed Emad
adcaf1769d
[libc] [NFC] fix type in docs/uefi/index.rst (#132553)
Closes #132537
2025-03-22 12:16:15 -07: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
Shilei Tian
f1ac2afe21
Reapply "[AMDGPU] Use COV6 by default (#118515)" (#130963)
This reverts commit 68bcba6d7a1cc18996c0bcb7c62267c62d2040d0.
2025-03-21 15:26:45 -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
Joseph Huber
bd6df0fe21
Reapply "[LLVM] Make the GPU loader utilities an LLVM tool (#132096)" (#132277)
Summary:
There were a few issues with the first one, leading to some errors and
warnings. Most importantly, this was building on MSVC which isn't
supported.
2025-03-21 11:05:32 -05:00
Joseph Huber
d4ce57cb98
[libc] Fix unresolved stdio symbols (#132403)
Summary:
We have 'generic' implementations for some functions stdio functions.
The current logic mandates that all generic functions are implemented by
the target. This obviously isn't true and this caused the GPU builds to
fail once baremtal added some extra ones.

This patch changes the logic to always include the generic sources only
if they aren't already defined. This can probably be cleaned up and
formalized later, since this pattern is copied in many places, but for
now this fixes the failing GPU build bots.
2025-03-21 10:06:57 -05:00
Krishna Pandey
902078350e
[libc][math] Add missing parenthesis in sollya command (#132298)
This PR adds the missing opening parenthesis for sollya command comment
in `libc/src/math/generic/cbrtf.cpp#L28`.

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-03-20 21:26:09 -04:00
Petr Hosek
afae7c91e1
[libc] Support for scanf on baremetal (#131043)
This uses the templatized scanf Reader interface introduced in #131037.
2025-03-20 15:54:38 -07:00
Joseph Huber
df2a56767d Revert "[LLVM] Make the GPU loader utilities an LLVM tool (#132096)"
This reverts commit 221b0117fd21d45098ead779a040a4b939a5c84f.

Some build failures requiring TargetParser and some warnings to clean
up.
2025-03-20 14:26:59 -05:00
Joseph Huber
221b0117fd
[LLVM] Make the GPU loader utilities an LLVM tool (#132096)
Summary:
These tools `amdhsa-loader` and `nvptx-loader` are used to execute unit
tests directly on the GPU. We use this for `libc` and `libcxx` unit
tests as well as general GPU experimentation. It looks like this.

```console
> clang++ main.cpp --target=amdgcn-amd-amdhsa -mcpu=native -flto -lc ./lib/amdgcn-amd-amdhsa/crt1.o
> llvm-gpu-loader a.out
Hello World!
```

Currently these are a part of the `libc` project, but this creates
issues as `libc` itself depends on them to run tests. Right now we get
around this by force-including the `libc` project prior to running the
runtimes build so that this dependency can be built first. We should
instead just make this a simple LLVM tool so it's always available.

This has the effect of installing these by default now instead of just
when `libc` was enabled, but they should be relatively small. Right now
this only supports a 'static' configuration. That is, we locate the CUDA
and HSA dependencies at LLVM compile time. In the future we should be
able to provide this by default using `dlopen` and some API.

I don't know if it's required to reformat all of these names since they
used the `libc` naming convention so I just left it for now.
2025-03-20 14:17:41 -05:00
Prashanth
7063419460
[libc][docs] Add dirent implementation status doc and include in CMakeLists (#132151)
These changes tracks `dirent.h` for the implementation status of
functions and macros, with respect to the issue (
https://github.com/llvm/llvm-project/issues/122006 ).
2025-03-20 11:08:44 -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
Krishna Pandey
bda87e0a09
[libc][sched] Implement CPU_ZERO, CPU_ISSET, CPU_SET macros (#131524)
This PR implements the following macros for `sched.h`:
- `CPU_ZERO`
- `CPU_ISSET`
- `CPU_SET`

Fixes #124642

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-03-19 13:44:41 -04:00
Iris
67a01131a8
[libc] Replace __builtin_popcountl with cpp::popcount in sched_getcpucount (#131952)
Closes #128781.
2025-03-19 10:35:50 -04: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