4092 Commits

Author SHA1 Message Date
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
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
Prashanth
592a3ba125
[libc][docs] Add sys/utsname header and documentation for uname function (#131817)
These changes tracks `utsname.h` for the implementation status of
functions and macros, with respect to the issue (
https://github.com/llvm/llvm-project/issues/122006 ).
2025-03-18 16:22:01 -04: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
Roland McGrath
460b9cda81
[libc] Disable dl_iterate_phdr entrypoint for linux fullbuild (#131893)
There are some issues with typedef conflicts between libc headers
and Linux kernel headers arising.  Disable building the new code
for Linux for now.
2025-03-18 12:26:22 -07:00
Roland McGrath
123c0040d4
[libc] Define (stub) dl_iterate_phdr (#131436)
This fleshes out the <link.h> a little more, including the
`struct dl_phdr_info` type and declaring the dl_iterate_phdr
function.  There is only a no-op implementation without tests, as
for the existing dlfcn functions.
2025-03-18 11:38:33 -07:00
Joseph Huber
04ab8a5fba [libc] Fix the GPU build after scanf rework
Summary:
Needs these to be included.
2025-03-18 12:09:30 -05:00
OverMighty
3d083777ef
[libc] Fix compile error in MPFRWrapper when float128 is long double (#131821)
See https://lab.llvm.org/buildbot/#/builders/104/builds/18422.
2025-03-18 12:12:44 -04: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
Prashanth
47f7daab06
[libc][docs] Add glob implementation status doc and include in CMakeLists (#126923)
These changes tracks `glob.h` for the implementation status of functions
and macros, with respect to the issue ( #122006 ) .

cc @nickdesaulniers
2025-03-17 13:05:50 -04:00
Tristan Ross
4e841d7d63
[libc] add uefi docs (#131426)
Adds documentation for the UEFI target since #131246 was merged.
2025-03-16 10:21:19 -07:00
Tristan Ross
bb694998d2
[libc] init uefi (#131246)
Initial UEFI OS target support after the headers. This just defines
enough that stuff might try and compile. Test with:
```
$ cmake -S llvm -B build -G Ninja -DLLVM_RUNTIME_TARGETS=x86_64-unknown-uefi-llvm -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_ENABLE_RUNTIMES=libc -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_LIBC_FULL_BUILD=true -DCMAKE_C_COMPILER_WORKS=true -DCMAKE_CXX_COMPILER_WORKS=true -DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_LIBCXX=true -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-uefi-llvm -DCMAKE_INSTALL_LIBDIR=build/target/lib
$ ninja -C build
```
2025-03-14 20:15:24 -07:00
lntue
d0a0de50f7
[libc] Fix implicit conversion warnings in tests. (#131362) 2025-03-14 14:24:11 -04:00
Joseph Huber
fdb4b89bc0 [libc] Fix memmove macros for unreocognized targets 2025-03-14 10:25:42 -05:00
Joseph Huber
e8117026a9
[libc] Default to byte_per_byte instead of erroring (#131340)
Summary:
Right now a lot of the memory functions error if we don't have specific
handling for them. This is weird because we have a generic
implementation that should just be used whenever someone hasn't written
a more optimized version. This allows us to use the `libc` headers with
more architectures from the `shared/` directory without worrying about
it breaking.
2025-03-14 10:10:53 -05:00
Simon Tatham
80079c9c2f
[libc] Fix new warning in DyadicFloat::as_mantissa_type_rounded (#131148)
The affected line of code converts a float's exponent from `int` to
`size_t`, negating it in the process. Following clang commit
773e88f9d61399c, this provokes a warning, presumably because the
conversion goes wrong if `size_t` is wider than `int` and the input
value is `INT_MIN`: negating it within the `int` type is undefined
behavior, with the likely (though not guaranteed) effect of leaving it
still at `INT_MIN` and then sign-extending that on promotion to
`size_t`.

This fix adds a cast so that the promotion to `size_t` happens _before_
the negation, so that the negative input value will _always_ be
sign-extended, and then the negation will make it positive again.

(I don't believe this case will actually come up. `DyadicFloat` is a
helper system used in processing ordinary float formats, so nothing is
expected to generate an exponent with even a 16-bit absolute value, let
alone 31. But it's as easy to fix it to be robust as it is to just
suppress the warning!)
2025-03-14 11:57:25 +00:00
Connector Switch
bde2636fb5
[libc][NFC] Add the missing angle bracket in wchar.h (#131161) 2025-03-14 11:14:52 +08:00
Joseph Huber
8437b7f558
[libc] Make RPC server handling header only (#131205)
Summary:
This patch moves the RPC server handling to be a header only utility
stored in the `shared/` directory. This is intended to be shared within
LLVM for the loaders and `offload/` handling.

Generally, this makes it easier to share code without weird
cross-project binaries being plucked out of the build system. It also
allows us to soon move the loader interface out of the `libc` project so
that we don't need to bootstrap those and can build them in LLVM.
2025-03-13 19:23:21 -05:00
PiJoules
662bd4ca47
[stdio][baremetal] Fix templating for print functions (#131232)
This addresses build errors from https://github.com/llvm/llvm-project/pull/111559.
2025-03-13 15:30:45 -07:00
Simon Tatham
6fea340023
[libc] Fix non-templated uses of printf_core::Writer (#131149)
Commit 598e882ee88a1e3 turned `Writer` into a template, and updated most
of the call sites that use it. But not all. The alternative FP printf
system in `float_dec_converter_limited.h` wasn't updated, and neither
was `baremetal/printf.cpp` or `baremetal/vprintf.cpp`.

This patch updates `float_dec_converter_limited.h` in the same way that
the previous commit updated `float_dec_converter.h`: propagate the
templatedness through everything in the header, so that anything using a
`Writer` at all has a `write_mode` template parameter to pass on to it.

`printf.cpp` and `vprintf.cpp` are updated in the same way that the
previous commit updated `printf_core/vfprintf_internal.h`: the
`WriteBuffer` has parameter `WriteMode::FLUSH_TO_STREAM`, and `Writer`
picks it up implicitly from that.
2025-03-13 13:37:18 -05:00
Joseph Huber
e8e267ec42
[libc] Remove use of C++ STL features from rpc_server.cpp (#131169)
Summary:
This is done in preparation for making this header only so we can use it
without an object library. This will be a transient interface that
internal LLVM stuff with use. External people can use it too if they go
through the LLVM libc interface for shared stuff but there's no backward
compatibility guarantees.

Patch just cleans it up prior to the move.
2025-03-13 13:24:42 -05:00
Tejas Vipin
b910610eea
[libc][math] Fix Sollya command (#131091)
Fix a minor syntax error in the Sollya command in the comments of
asinhf.
2025-03-13 07:36:06 -04:00
Connector Switch
f291ec692e
[libc] Use proxy header in the locale implementation. (#130982)
Address review comments in
https://github.com/llvm/llvm-project/pull/130621#pullrequestreview-2671843932.

Some unused headers are also removed.
2025-03-13 11:35:41 +08: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
lntue
d578148b7d
[libc][math] Skip checking for exceptional values when LIBC_MATH_SKIP_ACCURATE_PASS is set. (#130811) 2025-03-11 17:13:46 -04:00
PiJoules
313e2ef93e
[libc] Mark fixed point type generic macros as complete (#130805)
These were added in https://github.com/llvm/llvm-project/pull/129371.
2025-03-11 11:03:51 -07:00
lntue
5038e2f814
[libc] Provide more fine-grained control of FMA instruction for ARM targets. (#130700) 2025-03-11 10:17:34 -04: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
lntue
7e292772ad
[libc] Fix implicit conversion warnings. (#130635) 2025-03-10 12:51:38 -04: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