summaryrefslogtreecommitdiff
path: root/libc/test/src/string
AgeCommit message (Collapse)Author
2025-11-10[libc] add an SVE implementation of strlen (#167259)Schrodinger ZHU Yifan
This PR creates an SVE-based implementation for strlen by translating from the AOR code in tree. Microbenchmark shows improvements against NEON when N>=64. Although both implementations fall behind glibc by a large margin, this may be a good start point to explore SVE implementations. Together with the PR: 1. Added two more tests of strlen with special nul symbols. 2. Added strlen's fuzzer and fix a typo in previous heap fuzzer. ``` === strlen(16 bytes) === libc: 1.56115 ns/call, 9.54499 GiB/s neon: 1.59393 ns/call, 9.34867 GiB/s sve: 1.66097 ns/call, 8.97134 GiB/s === strlen(64 bytes) === libc: 2.06967 ns/call, 28.7991 GiB/s neon: 2.59914 ns/call, 22.9325 GiB/s sve: 2.58628 ns/call, 23.0465 GiB/s === strlen(256 bytes) === libc: 3.74165 ns/call, 63.7202 GiB/s neon: 8.98243 ns/call, 26.5428 GiB/s sve: 7.36426 ns/call, 32.3751 GiB/s === strlen(1024 bytes) === libc: 10.5327 ns/call, 90.5438 GiB/s neon: 34.363 ns/call, 27.7529 GiB/s sve: 26.9329 ns/call, 35.4092 GiB/s === strlen(4096 bytes) === libc: 37.7304 ns/call, 101.104 GiB/s neon: 145.911 ns/call, 26.144 GiB/s sve: 103.208 ns/call, 36.9612 GiB/s === strlen(1048576 bytes) === libc: 9623.4 ns/call, 101.478 GiB/s neon: 36138.2 ns/call, 27.023 GiB/s sve: 26605.6 ns/call, 36.7051 GiB/s ```
2025-11-06[libc] Fix stale char_ptr for find_first_character_wide read (#166594)Sterling-Augustine
On exit from the loop, char_ptr had not been updated to match block_ptr, resulting in erroneous results. Moving all updates out of the loop fixes that. Adjust derefences to always be inside bounds checks.
2025-09-24[libc][NFC] Remove usage of the C keyword `I`. (#160567)lntue
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-09-03[libc] fixed signed char issues in strsep()/strtok()/strtok_r(). (#156705)enh-google
Also add the missing tests for all the related functions (even the ones that were already right), and add the missing bazel build rules.
2025-08-21[libc] fix strsep()/strtok()/strtok_r() "subsequent searches" behavior. ↵enh-google
(#154370) These functions turned out to have the same bug that was in wcstok() (fixed by 4fc9801), so add the missing tests and fix the code in a way that matches wcstok(). Also fix incorrect test expectations in existing tests. Also update the BUILD.bazel files to actually build the strsep() test.
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-24[libc] Don't rely on LIBC_HAS_SANITIZER when enabling null checks. (#150341)Alexey Samsonov
LIBC_HAS_SANITIZER (which is defined if ASan, MSan, or UBSan is enabled) is currently used to implicitly disable null checks, normally enabled via LIBC_ADD_NULL_CHECKS config value. Remove this condition, and rely purely on the config value instead: * LIBC_HAS_SANITIZER will be true even for UBSan modes which doesn't rely on null checks at all (e.g. -fsanitize=alignment) * null checks today (implemented via __builtin_trap) should function normally today even when sanitizer is enabled - trap is still a trap * tests have been migrated to WITH_SIGNAL(-1) which doesn't prescript a particular signal / exit-code, and thus should pass even if sanitizers override the default ones.
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-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-06-04[libc] Expand usage of libc null checks. (#116262)Aly ElAshram
Fixes #111546 --------- Co-authored-by: alyyelashram <150528548+alyyelashram@users.noreply.github.com>
2025-03-14[libc] Fix implicit conversion warnings in tests. (#131362)lntue
2025-03-10[libc] Add `-Wno-sign-conversion` & re-attempt `-Wconversion` (#129811)Vinay Deshmukh
Relates to https://github.com/llvm/llvm-project/issues/119281#issuecomment-2699470459
2025-03-05Revert "[libc] Enable -Wconversion for tests. (#127523)"Augie Fackler
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-04[libc] Enable -Wconversion for tests. (#127523)Vinay Deshmukh
Relates to: #119281
2024-12-10[libc] move bcmp, bzero, bcopy, index, rindex, strcasecmp, strncasecmp to ↵Nick Desaulniers
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-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-01[libc] Remove the #include <stdlib.h> header (#114453)Job Henandez Lara
2024-10-30[libc] fix behavior of strrchr(x, '\0') (#112620)George Burgess IV
`strrchr("foo", '\0')` is defined to point to the end of `foo`, rather than returning NULL. This wasn't caught by tests, since llvm-libc's `ASSERT_STREQ(nullptr, "");` is not an assertion error. While I'm here, refactor the test slightly to check for NULL more specifically. I considered adding fancier `ASSERT`s (and changing the semantics of `ASSERT_STREQ`), but opted for a more local fix by fair dice roll.
2024-10-30libc: strlcpy/strlcat shouldn't bzero the rest of `buf` (#114259)George Burgess IV
When running Bionic's testsuite over llvm-libc, tests broke because e.g., ``` const char *str = "abc"; char buf[7]{"111111"}; strlcpy(buf, str, 7); ASSERT_EQ(buf, {'1', '1', '1', '\0', '\0', '\0', '\0'}); ``` On my machine (Debian w/ glibc and clang-16), a `printf` loop over `buf` gets unrolled into a series of const `printf` at compile-time: ``` printf("%d\n", '1'); printf("%d\n", '1'); printf("%d\n", '1'); printf("%d\n", 0); printf("%d\n", '1'); printf("%d\n", '1'); printf("%d\n", 0); ``` Seems best to match existing precedent here.
2024-10-10[libc] Temporarily disable strerror test on NVPTXJoseph Huber
Summary: This is failing on the NVPTX buildbot, https://lab.llvm.org/buildbot/#/builders/69/builds/6997/. I cannot reproduce it locally so I'm disabling it temporarily so the bot is green.
2024-09-11[libc] Add osutils for Windows and make libc and its tests build on Windows ↵Sirui Mu
target (#104676) This PR first adds osutils for Windows, and changes some libc code to make libc and its tests build on the Windows target. It then temporarily disables some libc tests that are currently problematic on Windows. Specifically, the changes besides the addition of osutils include: - Macro `LIBC_TYPES_HAS_FLOAT16` is disabled on Windows. `clang-cl` generates calls to functions in `compiler-rt` to handle float16 arithmetic and these functions are currently not linked in on Windows. - Macro `LIBC_TYPES_HAS_INT128` is disabled on Windows. - The invocation to `::aligned_malloc` is changed to an invocation to `::_aligned_malloc`. - The following unit tests are temporarily disabled because they currently fail on Windows: - `test.src.__support.big_int_test` - `test.src.__support.arg_list_test` - `test.src.fenv.getenv_and_setenv_test` - Tests involving `__m128i`, `__m256i`, and `__m512i` in `test.src.string.memory_utils.op_tests.cpp` - `test_range_errors` in `libc/test/src/math/smoke/AddTest.h` and `libc/test/src/math/smoke/SubTest.h`
2024-07-16[libc] Add `strerror` and `strerror_k` to the GPU (#99083)Joseph Huber
Summary: The GPU ignores `errno` primarily, but targets want these functions to be defined for certain C standard interfaces. This patch enables them and makes the test function on non-Linux targets.
2024-07-15[libc] Fix warnings emitted by GCC (#98751)OverMighty
Fixes #98709.
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-05-15[libc] Fix typo in test messageJoseph Huber
2024-05-15[libc] Fix GPU test build error (#92235)Jan Patrick Lehr
This fixes a build error on the AMDGPU buildbot introduced in PR https://github.com/llvm/llvm-project/pull/92172
2024-05-14[libc][bug] Fix out of bound write in memcpy w/ software prefetching (#90591)Guillaume Chatelet
This patch adds tests for `memcpy` and `memset` making sure that we don't access buffers out of bounds. It relies on POSIX `mmap` / `mprotect` and works only when FULL_BUILD_MODE is disabled. The bug showed up while enabling software prefetching. `loop_and_tail_offset` is always running at least one iteration but in some configurations loop unrolled prefetching was actually needing only the tail operation and no loop iterations at all.
2024-03-11[libc] Fix forward arm32 builtbot (#84794)Guillaume Chatelet
Introduced by https://github.com/llvm/llvm-project/pull/83441.
2024-03-09[libc] Provide `LIBC_TYPES_HAS_INT64` (#83441)Guillaume Chatelet
Umbrella bug #83182
2024-03-07[libc][c23] add memset_explicit (#83577)Schrodinger ZHU Yifan
2024-02-06[libc] Move libc_errno inside of LIBC_NAMESPACE (#80774)michaelrj-google
Having libc_errno outside of the namespace causes versioning issues when trying to link the tests against LLVM-libc. Most of this patch is just moving libc_errno inside the namespace in tests. This isn't necessary in the function implementations since those are already inside the namespace.
2024-01-26[libc][NFC] Use specific ASSERT macros to test errno (#79573)Guillaume Chatelet
This patch provides specific test macros to deal with `errno`. This will help abstract away the differences between unit test and integration/hermetic tests in #79319. In one case we use `libc_errno` which is a struct, in the other case we deal directly with `errno`.
2024-01-11[libc] Fix buggy AVX2 / AVX512 `memcmp` (#77081)Guillaume Chatelet
Fixes #77080.
2023-12-14[libc] fix msan failure in mempcpy_test (#75532)Nick Desaulniers
Internal builds of the unittests with msan flagged mempcpy_test. ==6862==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x55e34d7d734a in length llvm-project/libc/src/__support/CPP/string_view.h:41:11 #1 0x55e34d7d734a in string_view llvm-project/libc/src/__support/CPP/string_view.h:71:24 #2 0x55e34d7d734a in __llvm_libc_9999_0_0_git::testing::Test::testStrEq(char const*, char const*, char const*, char const*, __llvm_libc_9999_0_0_git::testing::internal::Location) llvm-project/libc/test/UnitTest/LibcTest.cpp:284:13 #3 0x55e34d7d4e09 in LlvmLibcMempcpyTest_Simple::Run() llvm-project/libc/test/src/string/mempcpy_test.cpp:20:3 #4 0x55e34d7d6dff in __llvm_libc_9999_0_0_git::testing::Test::runTests(char const*) llvm-project/libc/test/UnitTest/LibcTest.cpp:133:8 #5 0x55e34d7d86e0 in main llvm-project/libc/test/UnitTest/LibcTestMain.cpp:21:10 SUMMARY: MemorySanitizer: use-of-uninitialized-value llvm-project/libc/src/__support/CPP/string_view.h:41:11 in length What's going on here is that mempcpy_test.cpp's Simple test is using ASSERT_STREQ with a partially initialized char array. ASSERT_STREQ calls Test::testStrEq which constructs a cpp:string_view. That constructor calls the private method cpp::string_view::length. When built with msan, the loop is transformed into multi-byte access, which then fails upon access. I took a look at libc++'s __constexpr_strlen which just calls __builtin_strlen(). Replacing the implementation of cpp::string_view::length with a call to __builtin_strlen() may still result in out of bounds access when the test is built with msan. It's not safe to use ASSERT_STREQ with a partially initialized array. Initialize the whole array so that the test passes.
2023-12-05[reland][libc][NFC] Remove __support/bit.h and use __support/CPP/bit.h ↵Guillaume Chatelet
instead (#73939) (#74446) Same as #73939 but also fix `libc/src/string/memory_utils/op_aarch64.h` that was still using `deferred_static_assert`.
2023-12-05Revert "[libc][NFC] Remove __support/bit.h and use __support/CPP/bit.h ↵Guillaume Chatelet
instead" (#74444) Reverts llvm/llvm-project#73939 This broke libc-aarch64-ubuntu build bot https://lab.llvm.org/buildbot/#/builders/138/builds/56186
2023-12-05[libc][NFC] Remove __support/bit.h and use __support/CPP/bit.h instead (#73939)Guillaume Chatelet
2023-10-06[libc] Enable missing memory tests on the GPU (#68111)Joseph Huber
Summary: There were a few tests that weren't enabled on the GPU. This is because the logic caused them to be skipped as we don't use CPU featured on the host. This also disables the logic making multiple versions of the memory functions.
2023-09-26[libc][NFC] Remove an inappropriate -ffreestanding arg to memory_utils test. ↵Siva Chandra
(#67435)
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-06-30[libc] Improve memcmp latency and codegenGuillaume Chatelet
This is based on ideas from @nafi to: - use a branchless version of 'cmp' for 'uint32_t', - completely resolve the lexicographic comparison through vector operations when wide types are available. We also get rid of byte reloads and serializing '__builtin_ctzll'. I did not include the suggestion to replace comparisons of 'uint16_t' with two 'uint8_t' as it did not seem to help the codegen. This can be revisited in sub-sequent patches. The code been rewritten to reduce nested function calls, making the job of the inliner easier and preventing harmful code duplication. Reviewed By: nafi3000 Differential Revision: https://reviews.llvm.org/D148717
2023-06-21Revert D148717 "[libc] Improve memcmp latency and codegen"Guillaume Chatelet
Once integrated in our codebase the patch triggered a bunch of failing tests. We do not yet understand where the bug is but we revert it to move forward with integration. This reverts commit 5e32765c15ab8df3d2635a2bb5078c5b1d5714d5.
2023-06-14[libc] Enable custom logging in LibcTestGuillaume Chatelet
This patch mimics the behavior of Google Test and allow users to log custom messages after all flavors of ASSERT_ / EXPECT_. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D152630
2023-06-14Revert D152630 "[libc] Enable custom logging in LibcTest"Guillaume Chatelet
Failing buildbot https://lab.llvm.org/buildbot/#/builders/73/builds/49707 This reverts commit 9a7b4c934893d6bc571e1ce8efab2127ae5f4e45.
2023-06-14[libc] Enable custom logging in LibcTestGuillaume Chatelet
This patch mimics the behavior of Google Test and allow users to log custom messages after all flavors of ASSERT_ / EXPECT_. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D152630