5157 Commits

Author SHA1 Message Date
Michael Kruse
afb80bddf1
[Runtimes] Introduce variables containing resource dir paths (#177953)
Introduce common infrastructure for runtimes that determines compiler
resource path locations. These variables introduced are:

 * RUNTIMES_OUTPUT_RESOURCE_DIR
 * RUNTIMES_INSTALL_RESOURCE_PATH
 
That contain the location for the compiler resource path (typically
`lib/clang/<version>`) in the build tree and the install tree (the
latter relative to CMAKE_INSTALL_PREFIX).

Additionally, define

 * RUNTIMES_OUTPUT_RESOURCE_LIB_DIR
 * RUNTIMES_INSTALL_RESOURCE_LIB_PATH

as for the location of clang/flang version-locked libraries (typically
`lib${LLVM_LIBDIR_SUFFIX}/<targer-triple>`, but also depends on `APPLE`
and `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR`). This code is moved from
flang-rt and initially becomes its only user.

Refactored out of #171610 as requested
[here](https://github.com/llvm/llvm-project/pull/171610#discussion_r2687382481).

Extracted `get_runtimes_target_libdir_common` from compiler-rt as
requested
[here](https://github.com/llvm/llvm-project/pull/171610#discussion_r2689565634).
 
Added TODO comments to all runtimes as requested
[here](https://github.com/llvm/llvm-project/pull/171610#issuecomment-3789598635).
2026-04-02 10:32:14 +00:00
Zorojuro
a599a06e7c
[libc] Indentation consistency in CMake (#190120)
This PR just fixes the indentation/style for the whole CMake file for
consistency.
No other changes.
c698f55b0245ffbaae55c7f854fadba33df16e9d
2026-04-02 08:51:52 +01:00
lntue
d52daeac79
[libc] Fix the remaining long double issue in shared_math_test.cpp. (#190098) 2026-04-01 22:47:29 -04:00
lntue
096f9d0aa8
[libc] Initial support so that libc-shared-tests can be built with pp64le (#188882) 2026-04-01 20:55:44 -04:00
Zorojuro
52fb23eef8
[libc][math] Remove static from log1pf implementation (#190042)
Reflecting changes according to
823e3e0017
2026-04-01 19:01:44 -04:00
lntue
e87ea848b7
Reapply "[libc] Finetune libc.src.__support.OSUtil.osutil dependency." (#190033) (#190065)
This reverts commit 84f23eb3113f2e75d1a2e45db1b5c570a5d2f4c5 and fix GPU
builds.
2026-04-01 18:38:32 -04:00
Jan Patrick Lehr
84f23eb311
Revert "[libc] Finetune libc.src.__support.OSUtil.osutil dependency." (#190033)
Reverts llvm/llvm-project#189501

Buildbot failure on libc for GPU buildbots
2026-04-01 22:02:27 +02:00
Joseph Huber
75333a0981
[libc] Install the RPC headers so they can be used without LLVM source (#189996)
Summary:
The RPC headers are completely freestanding and can be installed and
used. This just places them in the standard compiler install directory
along with everything else. We put it under `shared/` so the usage
matches with using the upstream version. People using the installed
version will need to manuall `-isystem` into the include directory, but
this is part for the course for these LLVM extra headers.
2026-04-01 14:15:59 -05:00
lntue
35ceec6a78
[libc] Finetune libc.src.__support.OSUtil.osutil dependency. (#189501)
Several key targets unconditionally depend on `OSUtil.osutil` target,
causing errors when it is unnecessarily linked, or not available. This
PR fine-tuning the dependency on `OSUtil.osutil` to cleanly decouple
those targets, and gracefully skip targets that need `osutil`. Main
changes include:

* Make `LIBC_COPT_USE_C_ASSERT` to a cmake config, allowing
`LIBC_ASSERT` to use system's `assert` and not depending on `osutil`.
* Adjust cmake dependency for the following targets:
  - libc.src.__support.libc_assert
  - libc.src.__support.time.*
  - libc.src.time.linux.*
  - libc.src.unistd.*
  - LibcTest
* Give an option for `TestLogger` to use system's `fprintf` instead of
`osutil`.
2026-04-01 14:59:02 -04:00
Joseph Huber
b5745e1e28
[libc] Support basic 'complex.h' functionality on GPUs (#189999)
Summary:
This PR adds the basic complex functions needed by some targets. This is
an attempt to provide the standard interface needed by
'https://github.com/llvm/llvm-project/pull/187831'
2026-04-01 13:27:24 -05:00
Schrodinger ZHU Yifan
c6b25b4df3
[libc] separate raw_rwlock and unix_rwlock to make it internally usable (#189773) 2026-04-01 10:09:18 -04:00
lntue
ec45f95799
[libc] Add libc_set_definition and libc_add_definition to properly pass definitions to MSVC. (#189664) 2026-03-31 13:15:13 -04:00
Schrodinger ZHU Yifan
5a89da7d13
[libc][signal] cleanup sigaction implementation (#189512) 2026-03-31 09:43:50 -04:00
Schrodinger ZHU Yifan
10ea3deb87
[libc][syscall] lift raise to syscall wrapper (#189507) 2026-03-31 09:33:14 -04:00
Michael Jones
7b52dd6ad9
[libc][NFC] Add LIBC_INLINE and cleanup wchar internals (#188856)
Some of the functions were missing LIBC_INLINE and some of the variable
names were less descriptive than I liked. This PR fixes both as well as
cleaning up dependencies.
2026-03-30 23:03:06 +00:00
Schrodinger ZHU Yifan
74c4243225
[libc][tsearch] add tsearch functions (#172625) 2026-03-30 17:51:36 -04:00
Zorojuro
15a7c45163
[libc][math][c23] Add asinbf16 math function (#184170)
Co-authored-by: bassiounix <muhammad.m.bassiouni@gmail.com>
2026-03-30 21:29:55 +02:00
Joseph Huber
a6ffdb595f
[Clang] Improve scan in gpuintrin.h (#189381)
Summary:
Right now the scan checks to avoid the unspecified behavior in
`clzg(0)`. This is used as the source to the shuffle instruction, but
the argument is discarded at zero anyway. So, we simply pass unspecified
behavior to shuffle and then discard it. This should be fine. The scan
routines are expected to be optimal.

Also renames `sum` to `add`.
2026-03-30 14:16:21 -05:00
lntue
6ae395a875
[libc][NFC] Guard long double type in shared_math_tests. (#189373)
Skip long double tests when long double is double-double.
Also adjust constant literals.
2026-03-30 10:05:16 -04:00
Mohamed Emad
1bb03026b6
[libc][math][c23] implement double-precision asinpi (#188158)
Implement the double precision version of the asinpi c23 math function
2026-03-29 10:18:07 -04:00
Shikhar Soni
f0ce26d06d
[libc][math][c23] Add log2p1f16 C23 math function (#186754)
Signed-off-by: Shikhar Soni <shikharish05@gmail.com>
2026-03-28 11:34:42 -04:00
Alexey Samsonov
ae63230c23
[libc] Remove more header template files (#189066)
Get rid of several .h.def files which were used to ensure that the
macro definitions from llvm-libc-macro would be included in the public
header. Replace this logic with YAML instead - add entries to the
"macros" list that point to the correct "macro_header" to ensure it
would be included.

For C standard library headers, list several standard-define macros
to document their availability. For POSIX/Linux headers, only reference
a handful of macro, since more planning is needed to decide how to
represent platform-specific macro in YAML.
2026-03-27 16:06:39 -07:00
Jeff Bailey
d6ff5e7778
[libc][docs] Parse inline macro_value from YAML in docgen (#189118)
The docgen script was previously hardcoded to assume all implemented
macros must be placed in a *-macros.h header. This updates docgen to
read inline macro_value properties directly from the source YAML files,
correctly recognizing them as implemented.
2026-03-27 22:19:29 +00:00
Jeff Bailey
0aba82eb70
[libc] Add missing POSIX macros to cpio.h (#188840)
Define the POSIX cpio.h header and its standard macros in the libc build
system. Configure the macros directly in the YAML specification to allow
automated header generation without a custom definition template.
2026-03-27 22:08:13 +00:00
Alexey Samsonov
ead9ac8331
[libc] Remove header templates from several C standard headers. (#188878)
Switches the following headers to hdrgen-produced ones by referencing
some macro from C standard and the file containing the declarations in
corresponding YAML files:

* limits.h (referenced _WIDTH / _MAX / _MIN families).
* locale.h (referenced LC_ family).
* time.h (referenced CLOCKS_PER_SEC).
* wchar.h (referenced WEOF).
2026-03-27 17:55:37 +00:00
Jeff Bailey
030ef70908
[libc][docs] Document libc-shared-tests ninja target (#189062)
Added a brief description of the libc-shared-tests target to the
Building and Testing page.

This target allows running tests for shared standalone components like
math primitives without the full libc runtime.
2026-03-27 17:39:38 +00:00
Petter Berntsson
2af95b2fa2
[libc][docs] Fix POSIX basedefs links for nested headers (#188738)
Fix broken POSIX basedefs links for nested headers in llvm-libc docs.

The docgen script currently emits paths like `sys/wait.h.html`, but the
Open Group uses `sys_wait.h.html`, for example:
-
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_wait.h.html

This updates nested-header link generation while leaving flat headers
unchanged.
2026-03-27 17:30:43 +00:00
Michael Jones
166f996c44
[libc][bazel] Add generation for public headers (#184889)
Previously there was a single rule for stdbit, this PR adds generated
header targets for the rest of the linux headers. It also adds a
cc_library
for all of the public headers which also includes the types and macros
headers.
2026-03-27 09:44:32 -07:00
Jeff Bailey
b2f5992412
[libc][docs][NFC] Document cross-compilation testing with QEMU (#188838)
Added a "Building and Testing with an Emulator" section to
full_cross_build.rst using riscv64 and qemu-riscv64 as the example.
Outlined necessary CMake flags for cross-compiling with Clang, including
CMAKE_C_COMPILER_TARGET, CMAKE_CXX_COMPILER_TARGET, and
LLVM_ENABLE_LLD=ON. Switched from CMAKE_SYSROOT to LIBC_KERNEL_HEADERS
and added the gcc-riscv64-linux-gnu package dependency to ensure sysroot
issues on Debian-based systems are avoided while retaining access to
cross-compiler runtime objects.

Explained the self-hosted libc-hermetic-tests target as the required
target for executing tests during a standalone cross build, since the
standard check-libc tests are not hermetic.

Refactored existing CMake examples in full_cross_build.rst to use -S and
-B flags instead of cd and mkdir.

Removed prompt characters from code blocks and separated host
environment setup into explicit code blocks for easier copy-pasting.
Also removed the initial 'cd llvm-project' directory changes to reduce
boilerplate.

Added a cross-reference to the new emulator section in
build_and_test.rst.
2026-03-27 15:14:38 +00:00
Anonmiraj
e06b5e53a2
[libc][math] Implement C23 half precision erfc function (#180930)
Add support for the half-precision complementary error function
`erfcf16``, using a Sollya generated polynomial implementation with
proper handling of special cases.

Extend the MPFR utilities with erfc support to allow tests.

closes: #180927
2026-03-27 10:42:03 -04:00
lntue
924a4ada31
[libc] Guard long double shared math functions against double-double. (#188909) 2026-03-27 01:51:17 -04:00
Jeff Bailey
ecfcdd6e2a
[libc] Fix check-libc-lit running tests during build (#188081)
Updated check-libc-lit to depend only on build-only targets. Added
libc-integration-tests-build to track integration test executables and
updated LLVMLibCTestRules.cmake to populate it.

Removed incorrect dependencies on execution suites in include and
integration tests that were introduced in #184366.
2026-03-26 21:00:28 +00:00
Alexey Samsonov
968b6aaef1
[libc][hdrgen] Print __BEGIN_C_DECLS / __END_C_DECLS conditionally. (#188830)
Clean up the `%public_api` printer code slightly - get rid of explicit
`\n` and ensure we only print `__BEGIN_C_DECLS` and `__END_C_DECLS` if
the generated header actually contains functions or objects to declare.

I've noticed that after 27ba9e2a44c11f8123528c350227db2c9a707c8f landed,
generated errno.h header has two blocks of `__BEGIN_C_DECLS` /
`__END_C_DECLS`: an empty one was generated automatically from
`%public_api` section that was intended to only add the `errno_t` type
declaration.
2026-03-26 20:02:34 +00:00
Zorojuro
a9c6f38e8d
[libc] Fixes all guard comments of libc (#188701)
This PR intends to fix ALL the wrong guard comments for libc


Script used:
[guard_checker](https://github.com/Sukumarsawant/guard_checker/blob/main/check_headers.py)
2026-03-26 15:23:49 -04:00
Joseph Huber
3a56470a0e
[libc] Increase the maximum RPC port size for future hardware (#188756)
Summary:
We store the locks in local device memory for performance and
simplicity. The number here needs to correspond to the maximum occupancy
so that we never have a situation where a GPU thread is blocking another
GPU thread.

The number now is sufficient for most hardware, but modern compute chips
like the MI300x are already pushing ~12000 resident waves. This has ABI
impliciations so I'd like to bump it up sooner rather than later. The
ABI change is within what OpenMP expects, LLVM major versions, and it
will be caught statically so there's no risk of silent corruption (size
doesn't match).
2026-03-26 10:17:52 -05:00
Joseph Huber
cc4727ae3b
[LLVM] Replace use of LLVM_RUNTIMES_TARGET with LLVM_DEFAULT_TARGET_TRIPLE (#188303)
Summary:
This PR primarily changes using `LLVM_RUNTIMES_TARGET` to
`LLVM_DEFAULT_TARGET_TRIPLE`. The reason is that the default target
triple is the true cross-compiling architecture we are using, while the
runtimes_target can contain multilib strings like `+debug` or similar.

Additionally add the proper path handling to the OpenMP / Offload
libraries.
2026-03-26 08:52:32 -05:00
Jeff Bailey
9e6bd128f2
[libc][doc] Remove ToC incompatible with Furo (#188720)
Thanks to @Sukumarsawant for spotting this!
2026-03-26 13:42:03 +00:00
lntue
5a2fedf91d
[libc][msvc] Re-enable __builtin_is_constant_evaluated for MSVC. (#188663) 2026-03-25 23:21:53 -04:00
lntue
67113d9d2f
[libc] Allow LLVM_LIBC_FUNCTION macro to take another parameter for function alias. (#187154) 2026-03-25 18:25:54 -04:00
Zorojuro
9a8b8153be
[libc] Fix all guard comments for cos and Acos functions (#188612)
This PR intends to fix all the wrong guard comments for cos and Acos
function
2026-03-25 17:40:46 -04:00
Jeff Bailey
4bfc9bd4cf
[libc][docs] Add guide for implementing a function (#188499)
Added implementing_a_function.rst providing a checklist for adding a new
function to LLVM-libc.

Updated dev/index.rst to include the new guide in the toctree.
2026-03-25 20:43:49 +00:00
lntue
2c24f02924
[libc][math] Switch log1pf to use the same log_eval from inverse hyperbolic functions. (#188388)
- Switch log1pf to use the same log_eval from inverse hyperbolic
functions.
- Optimize log_eval to use the same range reduction scheme as double
precision log
- Reduce the table size needed for log range reduction.
- This lower the overall latency of log1pf and inverse hyperbolic
functions.
2026-03-25 16:41:54 -04:00
Ilya Tokar
267b0ea6e8
[libc][x86] add MEMCPY_X86_USE_NTA_STORES to config (#188321)
Add LIBC_CONF_COPT_MEMCPY_X86_USE_NTA_STORES to cmake/bazel/json config.
2026-03-25 15:14:27 -04:00
Jeff Bailey
4dbcc3f029
[libc] implement fflush(NULL) support (#188217)
Implement support for flushing all open streams when fflush is called
with a NULL pointer.

* Added a global linked list to track all open File objects.
* Updated File class to include prev/next pointers and list management
methods.
* Implemented POSIX requirement for fflush to sync seekable input
streams back to the host environment.
* Updated Linux-specific file creation to register new files in the
global list.
* Fixed a memory safety bug in create_file_from_fd using delete instead
of free.
* Added unit test for fflush(NULL).
* Added explanatory comments to fflush.cpp and file.cpp.
2026-03-25 14:51:57 +00:00
Victor Campos
2baa2cdce9
[libc] Follow up on Annex K's rsize_t (#187707)
- Fix header guard name.
- Define `__STDC_WANT_LIB_EXT1__` in `hdr/types/rsize_t.h` so that the
type is available for internal use.
- In accordance to the standard, make `stdio.h`, `stdlib.h`, `string.h`,
`time.h` and `wchar.h` define the type. It should already be available
in `stddef.h` as it's provided by Clang, not LLVM libc.
2026-03-25 13:16:34 +00:00
Victor Campos
27ba9e2a44
[libc] Define Annex K's errno_t in specified headers (#187700)
- Change `errno.h.def` to include a placeholder where hdrgen emits the
public API, which contains the `errno_t` definition.
- Make headers `stdio.h`, `stdlib.h`, `string.h` and `time.h` also
define `errno_t` as specified in the standard.
2026-03-25 12:30:19 +00:00
Fabio D'Urso
5999c53e32
[libc] Declare free_sized and free_aligned_sized in stdlib.h / malloc.h (#188364) 2026-03-25 11:48:07 +01:00
Jeff Bailey
458d3a8f05
[libc] Fix unused variable warning in utimes.cpp (#188347) (#188448)
Moved the declaration of 'ret' inside the SYS_utimes block to prevent an
unused variable warning on the libc-riscv32-qemu-yocto-fullbuild-dbg
builder, which doesn't define SYS_utimes.
2026-03-25 09:54:30 +00:00
Jakob Koschel
952dc12124
Force to inline syscall_impl on all platforms (#186849)
With currently only LIBC_INLINE, we just hint the compiler to inline the
function which however in practice is not always the case.

Since we added `[[gnu::always_inline]]` on linux/x86_64 it makes sense
to do it on all platforms consistently and add a comment explaining why
we need it.
2026-03-25 09:55:37 +01:00
Jeff Bailey
4c4c1db7c6
[libc] Add utimensat syscall wrapper and entrypoint (#188347)
Implemented the utimensat syscall for Linux and added the entrypoint to
sys/stat.h.

* Added utimensat syscall wrapper to OSUtil
* Updated utimes to use the utimensat wrapper
* Added utimensat unit tests to sys/stat
* Configured entrypoints for x86_64, riscv, and aarch64
2026-03-25 07:53:29 +00:00