summaryrefslogtreecommitdiff
path: root/libc/test/src/stdlib
AgeCommit message (Collapse)Author
2025-11-17[libc] Move mbtowc, mbstowcs and inverse functions to stdlib.h (#168455)Alexey Samsonov
These functions should be declared in `stdlib.h`, not `wchar.h`, as confusing as it is. Move them to the proper header file and matching directories in src/ and test/ trees. This was discovered while testing libc++ build against llvm-libc, which re-declares functions like mbtowc in std-namespace in `<cstdlib>` header, and then uses those functions in its locale implementation.
2025-11-14Revert "[libc][test] split exit tests into two separate tests" (#168102)Schrodinger ZHU Yifan
Reverts llvm/llvm-project#166355
2025-11-14[libc][test] split exit tests into two separate tests (#166355)Shreeyash Pandey
_Exit(3) is a fairly simple syscall wrapper whereas exit(3) calls atexit-registered functions + whole lot of stuff that require support for sync primitives. Splitting the tests allows testing the former easily (especially for new port projects) --------- Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-11-06[libc] Disable overflow test in strfromtest on riscv32 (#166719)Marcell Leleszi
Looks like https://github.com/llvm/llvm-project/pull/166517 is breaking libc-riscv32-qemu-yocto-fullbuild-dbg build due to failing overflow test for strfrom. https://lab.llvm.org/buildbot/#/changes/58668 ``` int result = func(buff, sizeof(buff), "%.2147483647f", 1.0f); EXPECT_LT(result, 0); ASSERT_ERRNO_FAILURE(); ``` ``` [ RUN ] LlvmLibcStrfromdTest.CharsWrittenOverflow /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/test/src/stdlib/StrfromTest.h:493: FAILURE Expected: result Which is: 0 To be less than: 0 Which is: 0 /home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/test/src/stdlib/StrfromTest.h:494: FAILURE Expected: 0 Which is: 0 To be not equal to: static_cast<int>(libc_errno) Which is: 0 [ FAILED ] LlvmLibcStrfromdTest.CharsWrittenOverflow Ran 8 tests. PASS: 7 FAIL: 1 ``` At first glance it seem like there is some kind of overflow in internal::strfromfloat_convert on 32bit archs because the other overflow test case is passing for snprintf. Interestingly, it passes on all other buildbots, including libc-arm32-qemu-debian-dbg. This issue likely wasn't introduced by https://github.com/llvm/llvm-project/pull/166517 and was probably already present, so I'm not reverting the change just disabling the test case on riscv32 until I can debug properly.
2025-11-05[libc] Add printf error handling (with fixes #2) (#166517)Marcell Leleszi
https://github.com/llvm/llvm-project/issues/159474 Another try of trying to land https://github.com/llvm/llvm-project/pull/166382 - Fix some leftover tests checking for specific errnos - Guard errno checking tests to not run on the GPU @michaelrj-google
2025-11-05[libc] Migrate ctype_utils to use char instead of int where applicable. ↵Alexey Samsonov
(#166225) Functions like isalpha / tolower can operate on chars internally. This allows us to get rid of unnecessary casts and open a way to creating wchar_t overloads with the same names (e.g. for isalpha), that would simplify templated code for conversion functions (see 315dfe5865962d8a3d60e21d1fffce5214fe54ef). Add the int->char converstion to public entrypoints implementation instead. We also need to introduce bounds check on the input argument values - these functions' behavior is unspecified if the argument is neither EOF nor fits in "unsigned char" range, but the tests we've had verified that they always return false for small negative values. To preserve this behavior, cover it explicitly.
2025-11-04Revert commit d8e5698 and 15b19c7 (#166498)Kewen Meng
2025-11-04[libc] Add printf error handling (with fixes) (#166382)Marcell Leleszi
https://github.com/llvm/llvm-project/issues/159474 Resubmitting https://github.com/llvm/llvm-project/pull/162876 with fixes as it broke some buildbots: - Fix comparisons of integer expressions of different signedness - Not check for specific errnos in tests, as they might not be available on all platforms
2025-11-03Revert "[libc] Add printf error handling" (#166232)Kewen Meng
2025-11-03[libc] Add printf error handling (#162876)Marcell Leleszi
[#159474](https://github.com/llvm/llvm-project/issues/159474) - All printf variants set errno and consistently return -1 on error, instead of returning various predefined error codes - Return value overflow handling is added
2025-09-22[libc] Add -Wextra for libc tests (#153321)Vinay Deshmukh
RE apply https://github.com/llvm/llvm-project/pull/133643/commits#top
2025-09-05[libc] Use anonymous namespace for test helper code (#157203)Roland McGrath
Tests can be at top-level or inside an anonymous namespace, doesn't matter. But putting their helper code inside anonymous namespaces both makes the code compatible with compiling using -Wmissing-declarations and might let the compiler optimize the test good a bit better.
2025-08-12Revert "[libc] Add -Wextra for libc tests" (#153169)William Huynh
Reverts llvm/llvm-project#133643
2025-08-12[libc] Add -Wextra for libc tests (#133643)Vinay Deshmukh
* Relates to: https://github.com/llvm/llvm-project/issues/119281
2025-07-23[libc][NFC] Add stdint.h proxy header to fix dependency issue with ↵lntue
<stdint.h> includes. (#150303) https://github.com/llvm/llvm-project/issues/149993
2025-06-17Fix/reapply "[libc] Migrate stdio tests to ErrnoCheckingTest. (#144134)Alexey Samsonov
This reverts commit 92a116c4ef822950f8c57eaa5164c844c73a1f7e with a fix for fgets test - convert nullptr to fgets return type (char*), since the matcher is pedantic.
2025-06-13Revert "Fix/reapply "[libc] Migrate stdio tests to ErrnoCheckingTest."" ↵Alexey Samsonov
(#144129) Reverts llvm/llvm-project#143972 - matcher seems to be pedantic for fgets tests, reverting to verify and fix.
2025-06-13Fix/reapply "[libc] Migrate stdio tests to ErrnoCheckingTest." (#143972)Alexey Samsonov
This reverts commit a93e55e57ed00a55f822c64e3520c7c732b58480 and fixes build and test failures: * Proper include added to setvbuf_test.cpp * fgetc/fgetc_unlocked/fgets tests are ported to ErrnoSetterMatcher and are made more precise. This fixes inconsistencies between expectations in regular and GPU builds - ErrnoSetterMatcher is configured to omit errno matching on GPUs, as fgetc implementation on GPU doesn't set errno, in contrast to Linux.
2025-06-11Revert "[libc] Migrate stdio tests to ErrnoCheckingTest." (#143829)Alexey Samsonov
Reverts llvm/llvm-project#143802. Follow-up fix 3c7af175e51c3ab08ac3c442146c2b822f38c01e wasn't robust enough and itself got reverted.
2025-06-11[libc] Migrate stdio tests to ErrnoCheckingTest. (#143802)Alexey Samsonov
Reduce the direct use of libc_errno in stdio unit tests by adopting ErrnoCheckingTest where appropriate. Also removes the libc_errno.h inclusions from stdlib.h tests that were accidentally added in d87eea35fac5a34a841c637db8908128409a184e
2025-06-11[libc] Move libc_errno.h to libc/src/__support and make ↵lntue
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[libc] Reduce direct use of errno in src/stdlib and src/__support tests. ↵Alexey Samsonov
(#143767) * Get rid of libc_errno assignments in str_to_* __support tests, since those API have been migrated to return error in a struct instead. * Migrate tests for atof and to strto* functions from <stdlib.h> and for strdup from <string.h> to use ErrnoCheckingTest harness.
2025-05-28[libc] Implement efficient 'malloc' on the GPU (#140156)Joseph Huber
Summary: This is the big patch that implements an efficient device-side `malloc` on the GPU. This is the first pass and many improvements will be made later. The scheme revolves around using a global reference counted pointer to hand out access to a dynamically created and destroyed slab interface. The slab is simply a large bitfield with one bit for each slab. All allocations are the same size in a slab, so different sized allocations are done through different slabs. Allocation is thus searching for or creating a slab for the desired slab, reserving space, and then searching for a free bit. Freeing is clearing the bit and then releasing the space. This interface allows memory to dynamically grow and shrink. Future patches will have different modes to allow fast first-time-use as well as a non-RPC version.
2025-03-28[libc] implement `memalignment` (#132493)Mohamed Emad
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-14[libc] Fix implicit conversion warnings in tests. (#131362)lntue
2025-03-07[libc][bazel] Minor cleanup to remove unused dependencies. (#130348)Alexey Samsonov
* strcpy doesn't need to depend on memcpy * qsort_test_helper has been generalized and doesn't need to depend on qsort. This is a small cleanup to unblock the work outlined in #130327.
2025-02-27[libc] implement l64a (#129099)Michael Jones
Adds l64a, which generates the base 64 string expected by a64l.
2025-02-25[libc] implement a64l (#128758)Michael Jones
Implement the posix function a64l. Standard: https://pubs.opengroup.org/onlinepubs/9799919799/functions/a64l.html
2025-02-04[libc] Alternative algorithm for decimal FP printf (#123643)Simon Tatham
The existing options for bin→dec float conversion are all based on the Ryū algorithm, which generates 9 output digits at a time using a table lookup. For users who can't afford the space cost of the table, the table-lookup subroutine is replaced with one that computes the needed table entry on demand, but the algorithm is otherwise unmodified. The performance problem with computing table entries on demand is that now you need to calculate a power of 10 for each 9 digits you output. But if you're calculating a custom power of 10 anyway, it's easier to just compute one, and multiply the _whole_ mantissa by it. This patch adds a header file alongside `float_dec_converter.h`, which replaces the whole Ryū system instead of just the table-lookup routine, implementing this alternative simpler algorithm. The result is accurate enough to satisfy (minimally) the accuracy demands of IEEE 754-2019 even in 128-bit long double. The new float128 test cases demonstrate this by testing the cases closest to the 39-digit rounding boundary. In my tests of generating 39 output digits (the maximum number supported by this algorithm) this code is also both faster and smaller than the USE_DYADIC_FLOAT version of the existing Ryū code.
2025-01-24[libc] Use the NVIDIA device allocator for GPU malloc (#124277)Joseph Huber
Summary: This is a blocker on another patch in the OpenMP runtime. The problem is that NVIDIA truly doesn't handle RPC-based allocations very well. It cannot reliably update the MMU while a kernel is running and it will usually deadlock if called from a separate thread due to internal use of TLS. This patch just removes the definition of `malloc` and `free` for NVPTX. The result here is that they will be undefined, which is the cue for the `nvlink` linker to define them for us. So, as far as `libc` is concerned it still implements malloc.
2025-01-06[libc] Fix sort test failing on NVPTXJoseph Huber
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-05[libc][fuzz] workaround gcc's constexpr capture issue in sort fuzzer (#121684)Schrodinger ZHU Yifan
Fix the build problem at https://lab.llvm.org/buildbot/#/builders/131/builds/13255
2025-01-05[libc] Improve qsort (with build fix) (#121482)Lukas Bergdoll
2024-12-29Revert "[libc] Improve qsort" (#121303)Schrodinger ZHU Yifan
Reverts llvm/llvm-project#120450
2024-12-29[libc] Improve qsort (#120450)Lukas Bergdoll
2024-12-16[libc] Breakup freelist_malloc into separate files (#119806)Petr Hosek
This better matches the structure we use for the rest of libc.
2024-12-09[libc] Add missing casts in StrtolTest (#119054)Roland McGrath
The a0c4f854cad2b97e44a1b58dc1fd982e1c4d60f3 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-03[libc] Change ctype to be encoding independent (#110574)Michael Jones
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-11-12[libc][i386] FPBit support for 96b long double (#115084)Nick Desaulniers
`long double` is haunted on most architectures, but it is especially so on i386-linux-gnu. While have 80b of significant data, on i386-linux-gnu this type has 96b of storage. Fixes for supporting printf family of conversions for `long double` on i386-linux-gnu. This allows the libc-stdlib-tests and libc_stdio_unittests ninja target tests to pass on i386-linux-gnu. Fixes: #110894 Link: #93709 Co-authored-by: Michael Jones <michaelrj@google.com>
2024-11-07[libc] Add the `src/stdlib/_Exit.h` header to `at_quick_exit_test.cpp` and ↵Job Henandez Lara
`atexit_test.cpp` (#115351) Hello, I merged this https://github.com/llvm/llvm-project/pull/114904 a few mins ago and the tests failed because i did not add the header `src/stdlib/_Exit.h` in `at_quick_exit_test.cpp` and `atexit_test.cpp`. I ran both builds/tests and everything was good. thanks
2024-11-07[libc] Remove _Exit proxy func header and use LIBC_NAMESPACE::_Exit in tests ↵Job Henandez Lara
(#114904) This improves/fixes this pr https://github.com/llvm/llvm-project/pull/114718. In this PR we removed the _Exit proxy func because it was not needed. Instead we used `LIBC_NAMESPACE::_Exit`
2024-11-03[libc] Add proxy headers to handle memory allocation associated with the ↵Job Henandez Lara
header `#include <stdlib.h> (#114690) This finishes the work from https://github.com/llvm/llvm-project/pull/114453 by adding proxy headers for `malloc`, `realloc`, `free` and `aligned_alloc`.
2024-11-01[libc] Remove the #include <stdlib.h> header (#114453)Job Henandez Lara
2024-10-02[libc] Enable dyadic float for float printf (#110765)Michael Jones
Dyadic floats were an existing option for float to string conversion, but it had become stale. This patch fixes it up as well as adding proper config options and test support. Due to the test changes this is a followup to #110759
2024-08-12[NFC][libc] Clarifies underscores in n-char-sequence. (#102193)Mark de Wever
The C standard specifies n-char-sequence: digit nondigit n-char-sequence digit n-char-sequence nondigit nondigit is specified as one of: _ a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z This means nondigit includes the underscore character. This patch clarifies this status in the comments and the test. Note C17 specifies n-char-sequence for NaN() as optional, and an empty sequence is not a valid n-char-sequence. However the current comment has the same effect as using the pedantic wording. So I left that part unchanged.
2024-07-16[libc][stdlib] Implement heap sort. (#98582)lntue
2024-07-12[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)Petr Hosek
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini
declaration" (#98593) Reverts llvm/llvm-project#98075 bots are broken
2024-07-11[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)Petr Hosek
This is a part of #97655.
2024-06-26[libc] Make 'rand()' thread-safe using atomics instead of TLS (#96692)Joseph Huber
Summary: Currently, we implement the `rand` function using thread-local storage. This is somewhat problematic because not every target supports TLS, and even more do not support non-zero initializers on TLS. The C standard states that the `rand()` function need not be thread, safe. However, many implementations provide thread-safety anyway. There's some confusing language in the 'rationale' section of https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html, but given that `glibc` uses a lock, I think we should make this thread safe as well. it mentions that threaded behavior is desirable and can be done in the two ways: 1. A single per-process sequence of pseudo-random numbers that is shared by all threads that call rand() 2. A different sequence of pseudo-random numbers for each thread that calls rand() The current implementation is (2.) and this patch moves it to (1.). This is beneficial for the GPU case and more generic support. The downside is that it's slightly slower to do these atomic operations, the fast path will be two atomic reads and an atomic write.