Commit Graph

1657 Commits

Author SHA1 Message Date
wldfngrs
ecf4f95c4f [libc][math][c23] Add tanf16 function (#121018)
- Implementation of tan for 16-bit floating point inputs.
- Exhaustive tests across the 16-bit input range
2025-01-12 23:46:53 -05: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
Schrodinger ZHU Yifan
73dd730fb9 [libc] implement sys/uio/writev (#122233)
implement sys/uio/writev according to POSIX standard. This vectorized IO
API is needed by many logging libraries to achieve atomic logging
multiple strings.
2025-01-10 12:49:00 +08:00
Nick Desaulniers
9426fdd4cb [libc][test] fix memory leak pt.2 (#122384)
These were created with operator new (see `Test::createCallable`), so operator
delete should be used instead of free().

Fixes: #122369
Fixes: #122378
2025-01-09 14:46:52 -08:00
Nick Desaulniers
3caa68a021 [libc][test] fix memory leak (#122378)
Looks like the smart pointer I removed was being used to free the underlying
object.

Fixes: #122369
2025-01-09 14:15:31 -08:00
Nick Desaulniers
0efb376c20 [libc][test] remove C++ stdlib includes (#122369)
These make cross compiling the test suite more difficult, as you need
the
sysroot to contain these headers and libraries cross compiled for your
target.
It's straightforward to stick with the corresponding C headers.
2025-01-09 13:40:54 -08:00
Michael Jones
f9c2377fb6 [libc][NFC] Cleanup time.h (#122027)
While working on strftime I noticed some constants were being defined in
unexpected places. One thing led to another, and I ended up doing a
major cleanup of the time functions.

What's included:
All uses of <time.h> in /src and /test removed (except for LibcTest.cpp)
The various time constants have been moved to time_constants.h, and the
`time_constants` namespace.
struct tm gets its own type indirection header now.
2025-01-08 12:28:50 -08:00
Joseph Huber
7cb6e6bced [libc] Fix sort test failing on NVPTX
Summary:
This test uses too much stack and crashes, make the buffer `static` to
push it to `.bss`. This shouldn't change behavior because the tests are
all run single threaded.
2025-01-06 09:04:31 -06:00
Schrodinger ZHU Yifan
de7f531106 [libc][fuzz] workaround gcc's constexpr capture issue in sort fuzzer (#121684)
Fix the build problem at
https://lab.llvm.org/buildbot/#/builders/131/builds/13255
2025-01-05 09:12:18 -08:00
Lukas Bergdoll
a738d81cd2 [libc] Improve qsort (with build fix) (#121482) 2025-01-05 06:10:41 +08:00
Roland McGrath
70c9152f99 [libc] Fix non-calls to cpp::is_complex_type_same (#121257)
Some uses were not actually calls, just references to the name.
2024-12-30 14:35:31 -08:00
Schrodinger ZHU Yifan
0b96f1cf68 Revert "[libc] Improve qsort" (#121303)
Reverts llvm/llvm-project#120450
2024-12-29 16:03:53 -05:00
Lukas Bergdoll
d2e71c92b8 [libc] Improve qsort (#120450) 2024-12-29 14:55:44 -05: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
Alexey Samsonov
6ecedb05b0 [libc] Make a couple of math smoke tests more robust. (#120808)
Make sure to clear out all FE_ALL_EXCEPT bits both before and after
invoking function under test -- otherwise the very first check for the
exception bits in the unit test may fail due to bits set prior to test
invocation.
2024-12-20 16:06:20 -08:00
Nick Desaulniers
1d06157b9e [libc] fix -Wgcc-compat (#120303)
I don't quite recall why I added those in the first place. These tests build
without diagnostics for both clang and GCC with this fix.

Fixes: #114653
2024-12-17 13:30:20 -08:00
Shourya Goel
c98e79d856 [libc][complex] Implement different flavors of the cproj function (#119722)
Refer section 7.3.9.5 of ISO/IEC 9899:2023
2024-12-18 02:04:50 +05:30
Tristan Ross
7477b61b24 [libc] Add unistd overlay (#119312)
Reverts the revert #119295 of #118882 by expanding #118882 with
additional fixes which made CI unhappy.
2024-12-17 10:40:22 -08:00
Petr Hosek
51a0919412 [libc] Exclude FreeListHeap test and fuzzer on GPU (#120137)
FreeListHeap uses the _end symbol which conflicts with the _end symbol
defined by GPU start.cpp files so for now we exclude the test and the
fuzzer on GPU.
2024-12-16 13:28:42 -08:00
Petr Hosek
7bf3137c39 [libc] Breakup freelist_malloc into separate files (#119806)
This better matches the structure we use for the rest of libc.
2024-12-16 10:30:27 -08:00
Schrodinger ZHU Yifan
f75c84674c [libc] fix atomic and apply an explicit check on unique object representations (#119715) 2024-12-16 12:04:52 -05:00
wldfngrs
6a865b6d3d [libc][math][c23] Add cosf16 function (#118785) 2024-12-15 18:58:54 +01:00
lntue
4eec286b51 [libc] Add MPFR testing infra for float128. (#119499) 2024-12-13 09:32:38 -05:00
Petr Hosek
379cc44f56 Revert "[libc] Breakup freelist_malloc into separate files" (#119749)
Reverts llvm/llvm-project#98784 which broke libc builders.
2024-12-12 13:28:30 -08:00
Petr Hosek
4e2a9e50f6 [libc] Breakup freelist_malloc into separate files (#98784)
This better matches the structure we use for the rest of libc.
2024-12-12 11:24:36 -08:00
Caslyn Tonelli
36c7d147fc [libc][test] Adjust header paths in tests (#119623)
Since `index_test.cpp` and `rindex_test.cpp` now reside in /strings,
adjust some header paths accordingly.

Link: #118899
2024-12-11 15:02:47 -08:00
Nick Desaulniers
1d7d0051f9 [libc] move src/network to src/arpa/inet (#119273)
So that docgen can find our implementations.

Fixes: #119272
2024-12-10 08:59:39 -08:00
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
Shourya Goel
78c2b6d483 [libc][complex] Implement different flavors of the conj function (#118671)
Refer section 7.3.9.4 of ISO/IEC 9899:2023
2024-12-10 10:05:11 +05:30
Schrodinger ZHU Yifan
9a06fb7e5c [libc][time][windows] implement clock_getres (#118931) 2024-12-09 22:00:01 -05:00
Roland McGrath
3d94a20230 [libc] Fix multiply-defined global functions in ctype tests (#119055)
For whatever reason, each ctype test contains its own copy of
some identical helper source code.  These local helpers were
defined with external linkage for no apparent reason.  This leads
to multiple definition errors when linking these tests together.

This change moves each file's local helper code into an anonymous
namespace so it has internal linkage.  It's notable that the libc
test code does not follow the most common norm of gtest-style
code where all the `TEST(...)` cases themselves are defined
inside an anonymous namespace (along with whatever other local
helpers they use); whether libc's tests should follow that usual
convention can be addressed holistically in future discussion.

The replacement of numerous cut&paste'd copies of identical
helper code with sharing the source code in some usual fashion is
also left for later cleanup.

This change only makes the test code not straightforwardly have
multiple definition errors that prevent linking a test executable
at all.
2024-12-09 11:18:00 -08:00
Roland McGrath
1a781e9ea6 [libc] Add missing casts in StrtolTest (#119054)
The a0c4f854ca change replaced the
local int_to_b36_char function returning `char` with uses of the
__support function of the same name that returns `int`.  The uses
of the old local function lacked the casts that all other uses of
the shared function of the same name had.  Add them.
2024-12-09 11:17:24 -08:00
Schrodinger ZHU Yifan
170467eeab [libc] fix 32bit riscv atomic tests (#119087)
This patch fixes test build failures on rv32 platforms. For non-integral
data, it always limits the size and align to be the same as platform
pointer layout. This should avoid the emitting of call to external
`libatomic` symbols.
2024-12-08 22:29:26 -05:00
Schrodinger ZHU Yifan
39451e45f5 [libc][CPP] clean up and generalize atomic implementation (#118996) 2024-12-06 12:47:19 -05:00
Schrodinger ZHU Yifan
e6cf5d2863 Reapply "[libc][windows] start time API implementation (#117775)" (#118886) 2024-12-05 18:21:03 -05:00
Joseph Huber
9fd052a122 Revert "[libc][windows] start time API implementation (#117775)"
This reverts commit 0adff0af20.

Breaks the GPU build
2024-12-05 14:43:06 -06:00
Schrodinger ZHU Yifan
0adff0af20 [libc][windows] start time API implementation (#117775)
Add a `clock_gettime` emulation layer and use it to implement the `time`
entrypoint.

For windows, the monotonic clock is emulated using `QPC`.
The realtime clock is emulated using `GetSystemTimePreciseAsFileTime`.
2024-12-05 14:08:27 -05:00
Schrodinger ZHU Yifan
245f26a3d3 [libc] revert all process_mrelease changes (#118650)
Revert as its test is unstable.
https://github.com/llvm/llvm-project/issues/118057
2024-12-05 11:58:37 -05:00
Michael Jones
a0c4f854ca [libc] Change ctype to be encoding independent (#110574)
The previous implementation of the ctype functions assumed ASCII.
This patch changes to a switch/case implementation that looks odd, but
actually is easier for the compiler to understand and optimize.
2024-12-03 12:36:04 -08: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
wldfngrs
cd04653c4e [libc][math][c23] Add sinf16 C23 math function (#116674)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-12-03 21:08:46 +01:00
Petr Hosek
b8daa45a56 [libc] Implement timespec_get (#116102)
`timespec_get` is C standard counterpart to POSIX `clock_gettime`. On
Linux we simply use `clock_gettime`. On baremetal we introduce a new
external API `__llvm_libc_timespec_get_utc` that should be implemented
by the vendor.
2024-12-02 14:29:49 -08:00
Joseph Huber
a6ef0debb1 [libc][NFC] Rename RPC opcodes to better reflect their usage
Summary:
RPC_ is a generic prefix here, use LIBC_ to indicate that these are
opcodes used to implement the C library
2024-12-02 15:35:08 -06:00
Schrodinger ZHU Yifan
cf478bf744 [libc] always clean up child process to avoid hanging ninja (#118049) 2024-11-29 00:17:09 -05:00
Schrodinger ZHU Yifan
819b155c2a [libc] skip test and return ENOSYS when processm_release unavailable (#117951) 2024-11-27 20:52:16 -05:00
Omar Hossam
d2b482b0ef [libc] (reland #117503) Implement process_mrelease (#117851)
This PR implements process_mrelease.
A previous PR was merged #117503, but failed on merge due to an issue in
the tests. Namely the failing tests were comparing against return type
as opposed to errno. This is fixed in this PR.
2024-11-27 20:15:17 -05: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
lntue
3372303188 Revert "[libc] Implement process_mrelease." (#117807)
Reverts llvm/llvm-project#117503
2024-11-26 18:07:30 -05:00
Omar Hossam
36a46d85e7 [libc] Implement process_mrelease. (#117503)
This PR addresses #110124.
2024-11-26 17:40:06 -05:00
Schrodinger ZHU Yifan
c71418574f [libc] suppress more clang-cl warnings (#117718)
- migrate more `-O3` to `${libc_opt_high_flag}`
- workaround a issue with `LLP64` in test. The overflow testing is
guarded by a constexpr but the literal overflow itself will still
trigger warnings.

Notice that for math smoke test, for some reasons, the
`${libc_opt_high_flag}` will be passed into `lld-link` which confuses
the linker so there are still some warnings leftover there. I can
investigate more when I have time.
2024-11-26 15:15:58 -05:00