420 Commits

Author SHA1 Message Date
William Huynh
0425a5df4d
[libc] Add hooks for extra options in running hermetic tests (#147931)
Part of #145349. These hooks are required downstream in order to run
hermetic tests. See https://github.com/arm/arm-toolchain/pull/420 for
more context on how this PR will be used.
2025-07-15 11:43:51 +01:00
Amy Huang
bc2cc8b56e
Change binary path in libc test cmake file from relative to absolute (#148315)
For some reason cmake usually turns this path into an absolute path, but
sometimes
it doesn't do it and stays as a relative path, which means the command
will fail.
Specify it as an absolute path always so this doesn't happen any more.
2025-07-12 14:43:52 -07:00
William Huynh
baf35d7a82
[libc] Fix bug in LIBC_CONF_ERRNO_MODE being undefined (#144896)
A typo, set() instead of list() would cause the build to not define
LIBC_CONF_ERRNO_MODE, which would cause the wrong configuration to be
used.
2025-06-19 14:50:07 -04:00
William Huynh
473dea9b0b
[libc] Output all headers with LIBC_CONF_OUTPUT_ALL_HEADERS (#144114)
Following discussion from
https://discourse.llvm.org/t/missing-declarations-in-header-files/86678,
we decided to add a flag to output all headers. Requires #144049.

- Allows outputting all headers
- Minor whitespace change for alignment

---------

Co-authored-by: Michael Jones <michaelrj@google.com>
2025-06-13 14:37:25 -07:00
lntue
d87eea35fa
[libc] Move libc_errno.h to libc/src/__support and make LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187)
This is the first step in preparation for:
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-06-11 16:25:27 -04:00
Joseph Huber
525726a520
[libc] Cleanup unimplemented math functions (#143173)
Summary:
This patch cleans up the leftoever files that were either implemented or
are still unimplemented stubs.
2025-06-06 12:27:13 -05:00
lntue
6d3b72aa6e
[libc] Pass config flags to unit tests. (#142085) 2025-05-30 10:00:14 -04:00
Aly ElAshram
bfd7024b0d
[LibC] Refactor arm64 to aarch64 for darwin. (#141509)
Fixes [#141505](https://github.com/llvm/llvm-project/issues/141505)

The main intention behind this PR is to update the
LibCTargetArchitecture for arm64 to use the implementation of aarch64
architecture and not arm32.

This is a historical issue , and is a blocker to issue #138407. 

The intended fix is to set the `LibCTargetArchitecture` to aarch64 when
it matches arm64 , this in turn would help us run darwin/aarch64
specific code on our MacOs pipeline in the git actions.

Methods used to search and find "darwin/arm" directories was  

1. "find . -type d -path "*/libc/*/darwin/arm" in a linux terminal to
check for arm specifically
2. "find . -type d -path "*/libc/*/darwin/*" to ensure there are no
directories that are named "*arm*" where star is a wildcard for any
character.
2025-05-29 23:41:34 -04:00
Mikhail R. Gadelha
ebdf2e06ff
[libc] Add missing dependency for test target (#138423)
It seems we were missing a dependency when adding a new test target,
e.g., test libc.test.src.math.sqrt_test.__unit__ would create a
custom target in the form of:

```
  add_custom_target(
    libc.test.src.__support.FPUtil.dyadic_float_test.__unit__
    COMMAND  ${LIBC_UNITTEST_ENV} ${CMAKE_CROSSCOMPILING_EMULATOR} libc.test.src.__support.FPUtil.dyadic_float_test.__unit__.__build__
    COMMENT Running unit test libc.test.src.__support.FPUtil.dyadic_float_test.__unit__ )
``` 

but it wouldn't set that it depends on
libc.test.src.__support.FPUtil.dyadic_float_test.__unit__.__build__
being built.

For some reason, it would break the rv32 buildbot, as it would try to
run a test but the __build__ is nowhere to be found, since it wasn't
built in the first place.
2025-05-03 18:10:13 -03:00
Joseph Huber
21dcf6bcd1 [libc] Make sure we use the right linker for bitcode linking
Summary:
We need to use the default arguments to ensure this uses the right
linker for the toolchain given cross-compiling contexts.
2025-04-30 16:25:28 -05:00
Joseph Huber
a5cdbef5f0 Revert "[LLVM] Replace use of LLVM_RUNTIMES_TARGET with LLVM_DEFAULT_TARGET_TRIPLE (#136208)"
This reverts commit 2e145f11c0bcfa2052416d96d682c75f33971a8c.

Somehow causes some static assertions to fail?
2025-04-22 08:08:51 -05:00
Joseph Huber
2e145f11c0
[LLVM] Replace use of LLVM_RUNTIMES_TARGET with LLVM_DEFAULT_TARGET_TRIPLE (#136208)
Summary:
For purposes of determining the triple, it's more correct to use
`LLVM_DEFAULT_TARGET_TRIPLE`.
2025-04-22 07:59:54 -05:00
Vinay Deshmukh
77f0708b9d
[libc]: Remove -Wglobal-constructors for libc tests (#131485)
* Relates to: https://github.com/llvm/llvm-project/issues/119281
* Removes `-Wglobal-constructors` as per:
https://github.com/llvm/llvm-project/pull/131485#pullrequestreview-2728020622
2025-04-15 19:24:07 -05:00
Joseph Huber
2f41fa387d
[AMDGPU] Fix code object version not being set to 'none' (#135036)
Summary:
Previously, we removed the special handling for the code object version
global. I erroneously thought that this meant we cold get rid of this
weird `-Xclang` option. However, this also emits an LLVM IR module flag,
which will then cause linking issues.
2025-04-10 11:31:21 -05:00
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
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
Shilei Tian
f1ac2afe21
Reapply "[AMDGPU] Use COV6 by default (#118515)" (#130963)
This reverts commit 68bcba6d7a1cc18996c0bcb7c62267c62d2040d0.
2025-03-21 15:26:45 -04: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
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
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
Alexey Samsonov
ab0e6fcaad
[libc][cmake] Clean up dead code in add_gen_header (#128753)
DATA_FILES CMake argument never existed in the new YAML-based hdrgen
version of add_gen_header function, and thus its uses added in
b1fd6f0996a9d6e6ebfa0cc3df0fe499c5ccdf65 were always dead code.

Remove them to clean up the function implementation.

Co-authored-by: Alexey Samsonov <samsonov@google.com>
2025-02-25 10:58:44 -08:00
Joseph Huber
9bfe48695e
[libc] Initial support for parsing SPIR-V for GPU libc (#128570)
Summary:
Some day we'd like to support this, add some initial support for parsing
the triple so it will at least attempt to build.
2025-02-24 15:18:53 -06:00
Joseph Huber
d1dde17ab0 [libc] Fix failing NVPTX tests due to removed internal LLVM option
Summary:
This was removed but forgot to remove it in this one place. So it
errors.
2025-02-20 15:23:40 -06:00
Joseph Huber
3d9409f5bc
[NVPTX] Make ctor/dtor lowering always enabled in NVPTX (#126544)
Summary:
Currently we conditionally enable NVPTX lowering depending on the
language (C/C++/OpenMP). Unfortunately this causes problems because this
option is only present if the backend was enabled, which causes this to
error if you try to make LLVM-IR.

This patch instead makes it the only accepted lowering. The reason we
had it as opt-in before is because it is not handled by CUDA. So, this
pach also introduces diagnostics to prevent *all* creation of
device-side global constructors and destructors. We already did this for
variables, now we do it for attributes as well.

This inverts the responsibility of blocking this from the backend to the
langauage like it should be given that support for this is language
dependent.
2025-02-10 14:25:44 -06:00
Petr Hosek
6dbe542290
[libc] Use ${libc_opt_high_flag} instead of -O3 (#123233)
This is preferable since `${libc_opt_high_flag}` will be set correctly
for the compiler used.
2025-02-07 13:36:06 -08:00
Vinay Deshmukh
dee20925e7
[libc][test] -Wimplicit-fallthrough, -Wwrite-strings and non-GCC warnings (#124036)
* Enabled `-Wimplicit-fallthrough`
* Enabled `-Wwrite-strings`
* Enabled non-GCC warnings
* Fix non-GCC to mean `clang`
* Move `-Wstrict-prototypes` to common section

See:
https://github.com/llvm/llvm-project/pull/122835#discussion_r1924109264

Relates to #119281
2025-02-07 12:50:26 -08:00
lntue
46c4845244
[libc][cmake] Do not overwrite SKIP_FLAG_EXPANSION_*. (#125762)
So that users can set these manually if needed.
2025-02-05 14:01:25 -05:00
Roland McGrath
648981f913
[libc] Build with -Wdeprecated, fix some warnings (#125373)
While GCC's -Wdeprecated is on by default and doesn't do much,
Clang's -Wdeprecated enables many more things.  More apply in
C++20, so switch a test file that tickled one to using that.  In
future, C++20 should probably be made the baseline for compiling
all the libc code.
2025-02-01 18:22:18 -08:00
lntue
bcf306e0eb
[libc] Update include directory for libcMPCWrapper target when LIBC_MPC_INSTALL_PATH is set. (#124810) 2025-01-29 15:19:25 -05:00
Shourya Goel
7f37b34d31
[libc][complex] Testing infra for MPC (#121261)
This PR aims to add the groundwork to test the precision of libc complex
functions against MPC. I took `cargf` as a test to verify that the infra
works fine.
2025-01-28 11:01:16 +05:30
Joseph Huber
7b1becd940
[libc] Add CMake cache file for the GPU build (#124589)
Summary:
This introduces libc cache files and adds one for building the GPU
support. The cache files will set defaults for these arguments which can
be overridden if the user needs to. They also serve as documentation for
how the builid is expected to look.
2025-01-27 11:46:35 -06:00
lntue
b11529bfa2
[libc] Use -fno-math-errno to for __builtin_fma* to generate fma instructions. (#124200)
Fixes https://github.com/llvm/llvm-project/issues/123387
2025-01-23 20:38:53 -05:00
Nick Desaulniers
e2d9e999a2
[libc] fix -Wextra-semi (#123783)
Found while trying to consolidate our command line flags between tests and
underlying object files.

    error: extra ';' after member function definition [-Werror,-Wextra-semi]

Link: #119281
2025-01-21 13:18:23 -08:00
Nick Desaulniers
091adb8807
[libc][cmake] move _get_{common|hermetic}_test_compile_options to LLVMLibCTestRules.cmake (#122549)
They're only used in that file, which is more appropriate than
LLVMLibCCompileOptionRules.cmake since they're strictly related to tests.

Remove unused flags param from _get_hermetic_test_compile_options, and flags
that were already set by a prior call to _get_common_test_compile_options.
2025-01-14 08:36:04 -08:00
Roland McGrath
5e4b41c1d5
[libc] Add compile tests for each public header (#122527)
This adds a test that consists of compiling `#include <...>`,
pretty much alone, for each public header file in each different
language mode (`-std=...` compiler switch) with -Werror and many
warnings enabled.

There are several headers that have bugs when used alone, and
many more headers that have bugs in certain language modes.  So
for now, compiling the new tests is gated on the cmake switch
-DLLVM_LIBC_BUILD_HEADER_TESTS=ON.  When all the bugs are fixed,
the switch will be removed so future regressions don't land.
2025-01-11 17:24:37 -08:00
Roland McGrath
cdbba15c6c
[libc] Add --write-if-changed switch to hdrgen/main.py (#122037)
This avoids touching the output file when it hasn't changed.  The
cmake build integration now uses this so that touching a .yaml or
.h.def file in ways that don't affect the generated header output
won't cause unnecessary recompilations.
2025-01-08 11:00:31 -08:00
Roland McGrath
6ad0dcf67f
[libc] Revamp hdrgen command line and build integration (#121522)
This adds a new main command-line entry point for hdrgen, in the
new main.py.  This new interface is used for generating a header.
The old ways of invoking yaml_to_classes.py for other purposes
are left there for now, but `--e` is renamed to `--entry-point`
for consistency with the new CLI.

The YAML schema is expanded with the `header_template` key where
the corresponding `.h.def` file's path is given relative to where
the YAML file is found.  The build integration no longer gives
the `.h.def` path on the command line.  Instead, the script now
emits a depfile that's used by the cmake rules to track that.
The output file is always explicit in the script command line
rather than sometimes being derived from a directory path.
2025-01-07 15:56:12 -08:00
Roland McGrath
9abcca5e25
[libc] Move hdrgen into utils/ subdirectory (#121256) 2024-12-30 15:36:53 -08:00
Shourya Goel
abd9102344
[libc][complex] add cfloat16 and cfloat128 compiler flags (#121140)
Proper fix for the temporary fix in #114696
2024-12-26 12:50:07 +05:30
Nick Desaulniers
431ea2d076
[libc] move bcmp, bzero, bcopy, index, rindex, strcasecmp, strncasecmp to strings.h (#118899)
docgen relies on the convention that we have a file foo.cpp in
libc/src/\<header\>/. Because the above functions weren't in libc/src/strings/
but rather libc/src/string/, docgen could not find that we had implemented
these.

Rather than add special carve outs to docgen, let's fix up our sources for
these 7 functions to stick with the existing conventions the rest of the
codebase follows.

Link: #118860
Fixes: #118875
2024-12-10 08:58:45 -08:00
lntue
4dcc2f5db9
[libc] Replace LLVM_COMPILER_IS_GCC_COMPATIBLE with a local check. (#119164) 2024-12-08 23:52:52 -05:00
Nick Desaulniers
06c831d7fb
[libc] rename newhdrgen to just hdrgen (#118545)
Link: #117208
Fixes: #117254
2024-12-04 08:48:12 -08:00
Shilei Tian
68bcba6d7a Revert "[AMDGPU] Use COV6 by default (#118515)"
This reverts commit 410cbe3cf28913cca2fc61b3437306b841d08172 because some
buildbots are not ready yet.
2024-12-03 20:17:06 -05:00
Shilei Tian
410cbe3cf2
[AMDGPU] Use COV6 by default (#118515) 2024-12-03 19:38:35 -05:00
Nick Desaulniers
e0ae7793fc
[libc] delete hdrgen (#117220)
Thanks to the effort of @RoseZhang03 and @aaryanshukla under the
guidance of
@michaelrj-google and @amykhuang, we now have newhdrgen and no longer
have a
dependency on TableGen and thus LLVM in order to start bootstrapping a
full
build.

This PR removes:
- LIBC_HDRGEN_EXE; the in tree newhdrgen is the only hdrgen that can be
used.
- LIBC_USE_NEW_HEADER_GEN; newhdrgen is the default and only option.
- LIBC_HDRGEN_ONLY; there is no need to have a distinct build step for
old
  hdrgen.
- libc-api-test and libc-api-test-tidy build targets.
- Deletes all .td files.

It does not rename newhdrgen to just hdrgen. Will follow up with a
distinct PR
for that.

Link: #117209
Link: #117254
Fixes: #117208
2024-12-03 12:34:26 -08:00
Joseph Huber
38049dc8ee
[libc] Handle differing wavefront sizes correctly in the AMDHSA loader (#117788)
Summary:
The AMDGPU backend can handle wavefront sizes of 32 and 64, with the
native hardware preferring one or the other. The user can override the
hardware with `-mwavefrontsize64` or `-mwavefrontsize32` which
previously wasn't handled. We need to know the wavefront size to know
how much memory to allocate and how to index the RPC buffer. There isn't
a good way to do this with ROCm so we just use the LLVM support for
offloading to check this from the image.
2024-11-27 10:04:00 -06:00
Joseph Huber
6de97e9a67 [libc] Allow NVPTX targets to build in debug mode
Summary:
This previously did not work, but recent improvements to the NVPTX
backend allow this to work now.
2024-11-25 09:11:58 -06:00
Nick Desaulniers
e083a33478
[libc][cmake] make i386 distinct from x86_64 (#114477)
Configured via:

    $ cmake ../runtimes -G Ninja -DLLVM_ENABLE_LLD=ON \
      -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libc" \
      -DLIBC_TARGET_TRIPLE=i386-linux-gnu -DCMAKE_C_COMPILER=clang \
      -DCMAKE_CXX_COMPILER=clang++

Link: #93709
2024-11-01 08:31:05 -07:00