aboutsummaryrefslogtreecommitdiff
path: root/libcxx/test/std/strings/basic.string
AgeCommit message (Collapse)AuthorFilesLines
5 days[libc++] Fold __search_substring into _Traits::find in case the second ↵Nikolas Klauser1-0/+17
string has length 1 (#160076) Apple M4: ``` Benchmark Baseline Candidate Difference % Difference ----------------------------------------------------------- ---------- ----------- ------------ -------------- BM_string_literal/1024 16.99 16.79 -0.21 -1.21 BM_string_literal/128 3.44 3.34 -0.10 -2.88 BM_string_literal/16 1.80 1.69 -0.11 -5.93 BM_string_literal/2048 38.44 38.38 -0.07 -0.17 BM_string_literal/256 5.77 5.65 -0.12 -2.02 BM_string_literal/32 2.03 1.92 -0.11 -5.44 BM_string_literal/4096 73.92 73.74 -0.18 -0.25 BM_string_literal/512 9.49 9.41 -0.08 -0.84 BM_string_literal/64 2.59 2.45 -0.14 -5.38 BM_string_literal/8 1.79 1.69 -0.11 -5.90 BM_string_literal/8192 132.09 131.81 -0.28 -0.21 ```
5 days[libc++][string] P3044R2: sub-`string_view` from `string` (#147095)Hristo Hristov1-0/+123
Implements [P3044R2](https://wg21.link/P3044R2) Note: `substr.pass.cpp` is refactored to accommodate the test of `basic_string_view`'s `subview` which is an alias of `substr` without changing the test cases. Closes #148140 # References - https://github.com/cplusplus/draft/pull/7975 - https://wg21.link/string.substr - https://wg21.link/string.view.ops --------- Co-authored-by: Hristo Hristov <zingam@outlook.com> Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-09-09[libc++][NFC] Inline function in string.cons/copy_alloc.pass.cpp that is ↵Nikolas Klauser1-11/+5
used only once (#157429) This makes the test a bit easier to understand.
2025-09-05[libc++][C++03] cherry-pick #125423 (#156824)Nikolas Klauser2-4/+0
2025-09-04[libc++][NFC] Use llvm.org/PR to link to bug reports (#156288)Nikolas Klauser2-3/+3
We've built up quite a few links directly to github within the code base. We should instead use `llvm.org/PR<issue-number>` to link to bugs, since that is resilient to the bug tracker changing in the future. This is especially relevant for tests linking to bugs, since they will probably be there for decades to come. A nice side effect is that these links are significantly shorter than the GH links, making them much less of an eyesore. This patch also replaces a few links that linked to the old bugzilla instance on llvm.org.
2025-06-05[libc++] Fix `basic_string::shrink_to_fit` for constant evaluation (#142712)A. Jiang1-1/+1
Currently, when the string shrink into the SSO buffer, the `__rep_.__s` member isn't activated before the `traits_type::copy` call yet, so internal `__builtin_memmove` call writing to the buffer causes constant evaluation failure. The existing test coverage seems a bit defective and doesn't cover this case - `shrink_to_fit` is called on the copy of string after erasure, not the original string object. This PR reorders the `__set_short_size` call, which starts the lifetime of the SSO buffer, before the copy operation. Test coverage is achieved by calling `shrink_to_fit` on the original erased string.
2025-05-19[libc++] Optimize std::getline (#121346)Nikolas Klauser1-80/+56
``` ----------------------------------------------- Benchmark old new ----------------------------------------------- BM_getline_string 318 ns 32.4 ns ```
2025-05-06[libc++][NFC] Remove a bunch of redundant ASan existence checks (#128504)Nikolas Klauser1-0/+1
There are currently lots of `_LIBCPP_HAS_ASAN` and `__libcpp_is_constant_evaluated()` checks which aren't needed, since it is centrally checked inside `__debug_utils/sanitizers.h`.
2025-04-13[libc++][test] Test `nasty_string` in C++20 (#135338)A. Jiang2-2/+2
It seems that we can only rely on C++20 features and make `nasty_string` also tested for MSVC STL.
2025-04-09[libc++] P3247R2: Deprecate `is_trivial(_v)` (#130573)A. Jiang1-6/+24
Requirements on character-like types are updated unconditionally, because `basic_string` does requires the default-constructibility. It might be possible to make `basic_string_view` support classes with non-public trivial default constructor, but this doesn't seem sensible. libcxxabi's `ItaniumDemangle.h` is also updated to avoid deprecated features.
2025-04-05[libc++] Bump OS version for macOS backdeployment CI jobs (#131883)Louis Dionne2-6/+6
In 0547e573c555, I introduced backdeployment testing on macOS using Github-provided builders. This was done by basically building libc++ on a slightly older macOS (like macOS 13) and then running against the system library on that machine. However, that created a dependency that libc++ must keep working on macOS 13, which doesn't support the latest-released Xcode. This patch solves that problem by moving the deployment testing to a newer version of macOS which supports the latest-released version of Xcode. Sadly, that also reduces the backdeployment coverage we have since we're not actually testing on older OSes, but is necessary to satisfy the documented libc++ support policy. In the future, we could improve the situation by providing a Lit configuration that allows compiling (but not running) all the tests, building the tests on a supported macOS, and then shipping those tests on an older backdeployment target in order to run them against the system library. Since that requires significant engineering, this isn't done at this time.
2025-02-25[libc++] Make .verify.cpp tests more robust against changing headers (#128703)Nikolas Klauser1-5/+3
This is fixes the tests for the frozen headers, but is an improvement either way.
2025-02-23[libc++] Fix basic_string not allowing max_size() elements to be stored ↵Nikolas Klauser8-35/+132
(#125423) Without this patch `basic_string` cannot be properly resized to be `max_size()` elements in size, even if an allocation is successful. `__grow_by` allocates one less element than required, resulting in an out-of-bounds access. At the same time, `max_size()` has an off-by-one error, since there has to be space to store the null terminator, which is currently ignored.
2025-02-22[libc++] Fix shrink_to_fit to swap buffer only when capacity is strictly ↵Peng Liu1-17/+14
smaller (#127321) The current implementation of the `shrink_to_fit()` function of `basic_string` swaps to the newly allocated buffer when the new buffer has the same capacity as the existing one. While this is not incorrect, it is truly unnecessary to swap to an equally-sized buffer. With equal capacity, we should keep using the existing buffer and simply deallocate the new one, avoiding the extra work of copying elements. The desired behavior was documented in the following comment within the function: https://github.com/llvm/llvm-project/blob/61ad08792a86e62309b982189a600f4342a38d91/libcxx/include/string#L3560-L3566 However, the existing implementation did not exactly conform to this guideline, which is a QoI matter. This PR modifies the `shrink_to_fit()` function to ensure that the buffer is only swapped when the new allocation is strictly smaller than the existing one. When the capacities are equal, the new buffer will be discarded without copying the elements. This is achieved by including the `==` check in the above conditional logic.
2025-02-07[libc++] Refactor strings operator+ testsNikolas Klauser5-227/+134
This avoids duplicating the test data for all the different tests.
2025-02-06Reapply "[libc++] Simplify the implementation of reserve() and ↵Nikolas Klauser1-0/+9
shrink_to_fit() (#113453)" (#125888) The capacity is now passed correctly and a test for this path is added. Since we changed the implementation of `reserve(size_type)` to only ever extend, it doesn't make a ton of sense anymore to have `__shrink_or_extend`, since the code paths of `reserve` and `shrink_to_fit` are now almost completely separate. This patch splits up `__shrink_or_extend` so that the individual parts are in `reserve` and `shrink_to_fit` depending on where they are needed. This reverts commit 59f57be94f38758616b1339b293b43af845571af.
2025-01-25[libc++][test] Improves C++ Standard filtering. (#89499)Mark de Wever1-1/+1
Adds a new lit directive to improve C++ Standard filtering. This is based on the [Discourse](https://discourse.llvm.org/t/rfc-improving-c-standard-filtering-in-the-lit-tests/78474) discussion.
2025-01-21[libc++] Fix input-only range handling for `basic_string` (#116890)A. Jiang2-0/+44
By calling `std::move` for related functions when the iterator is possibly input-only. Also slightly changes the conditions of branch for contiguous iterators to avoid error. Fixes #116502
2024-12-21[libc++][C++03] Use `__cxx03/` headers in C++03 mode (#109002)Nikolas Klauser1-0/+2
This patch implements the forwarding to frozen C++03 headers as discussed in https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc. In the RFC, we initially proposed selecting the right headers from the Clang driver, however consensus seemed to steer towards handling this in the library itself. This patch implements that direction. At a high level, the changes basically amount to making each public header look like this: ``` // inside <vector> #ifdef _LIBCPP_CXX03_LANG # include <__cxx03/vector> #else // normal <vector> content #endif ``` In most cases, public headers are simple umbrella headers so there isn't much code in the #else branch. In other cases, the #else branch contains the actual implementation of the header.
2024-12-05[libc++][test] Refactor increasing_allocator (#115671)Peng Liu1-27/+4
The increasing_allocator<T> class, originally introduced to test shrink_to_fit() for std::vector, std::vector<bool>, and std::basic_string, has duplicated definitions across several test files. Given the potential utility of this class for capacity-related tests in various sequence containers, this patch refactors the definition of increasing_allocator<T> into a single, reusable location.
2024-11-04 [libcxx] Add testing configuration for GPU targets (#104515)Joseph Huber1-0/+4
Summary: The GPU runs these tests using the files built from the `libc` project. These will be placed in `include/<triple>` and `lib/<triple>`. We use the `amdhsa-loader` and `nvptx-loader` tools, which are also provided by `libc`. These launch a kernel called `_start` which calls `main` so we can pretend like GPU programs are normal terminal applications. We force serial exeuction here, because `llvm-lit` runs way too many processes in parallel, which has a bad habit of making the GPU drivers hang or run out of resources. This allows the compilation to be run in parallel while the jobs themselves are serialized via a file lock. In the future this can likely be refined to accept user specified architectures, or better handle including the root directory by exposing that instead of just `include/<triple>/c++/v1/`. This currently fails ~1% of the tests on AMDGPU and ~3% of the tests on NVPTX. This will hopefully be reduced further, and later patches can XFAIL a lot of them once it's down to a reasonable number. Future support will likely want to allow passing in a custom architecture instead of simply relying on `-mcpu=native`.
2024-10-30[libc++][test] Augment `test_alloc` in `deallocate_size.pass.cpp` (#113638)A. Jiang1-2/+19
Making it meet the requirements for allocator since C++11. Fixes #113609. This PR doesn't make it meet the C++03 allocator requirements, because that would make the type too verbose and libc++ has backported many C++11 features to the C++03 mode. Drive-by: Removes the `TEST_CONSTEXPR_CXX14` on `allocate`/`dealocate` which is never in effect (and causes IFNDR-ness before C++23), since these functions modify the namespace-scoped variable `allocated_`.
2024-09-30[libc++][string] Add regression test for sized new/delete bug (#110210)Vitaly Buka1-0/+66
This is regression test for #90292. Allocator used in test is very similar to test_allocator. However, reproducer requires size_type of the string to be 64bit, but test_allocator uses 32bit. 32bit size_type makes `sizeof(string::__long)` to be 16, but the alignment issue fixed with #90292 is only triggered with default `sizeof(string::__long)` which is 24. Fixes #92128. --------- Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-08-20[libc++] Fix several double-moves in the code base (#104616)Louis Dionne1-6/+4
This patch hardens the "test iterators" we use to test algorithms by ensuring that they don't get double-moved. As a result of this hardening, the tests started reporting multiple failures where we would double-move iterators, which are being fixed in this patch. In particular: - Fixed a double-move in pstl.partition - Add coverage for begin()/end() in subrange tests - Fix tests for ranges::ends_with and ranges::contains, which were incorrectly calling begin() twice on the same subrange containing non-copyable input iterators. Fixes #100709
2024-08-06[libc++] Implements LWG3130. (#101889)Mark de Wever3-0/+18
This adds addressof at the required places in [input.output]. Some of the new tests failed since string used operator& internally. These have been fixed too. Note the new fstream tests perform output to a basic_string instead of a double. Using a double requires num_get specialization num_get<CharT, istreambuf_iterator<CharT, char_traits_operator_hijacker<CharT>> This facet is not present in the locale database so the conversion would fail due to a missing locale facet. Using basic_string avoids using the locale. As a drive-by fixes several bugs in the ofstream.cons tests. These tested ifstream instead of ofstream with an open mode. Implements: - LWG3130 [input.output] needs many addressof Closes #100246.
2024-08-01[libc++][NFC] Avoid opening namespace std in the tests (#94160)Nikolas Klauser1-3/+1
This also adds a few FIXMEs where we use UB in the tests.
2024-07-23[libc++][string] Fixes shrink_to_fit. (#97961)Mark de Wever1-0/+41
This ensures that shrink_to_fit does not increase the allocated size. Partly addresses #95161
2024-07-22[libc++][hardening] Use bounded iterators in std::vector and std::string ↵David Benjamin1-2/+3
(#78929) ~~NB: This PR depends on #78876. Ignore the first commit when reviewing, and don't merge it until #78876 is resolved. When/if #78876 lands, I'll clean this up.~~ This partially restores parity with the old, since removed debug build. We now can re-enable a bunch of the disabled tests. Some things of note: - `bounded_iter`'s converting constructor has never worked. It needs a friend declaration to access the other `bound_iter` instantiation's private fields. - The old debug iterators also checked that callers did not try to compare iterators from different objects. `bounded_iter` does not currently do this, so I've left those disabled. However, I think we probably should add those. See https://github.com/llvm/llvm-project/issues/78771#issuecomment-1902999181 - The `std::vector` iterators are bounded up to capacity, not size. This makes for a weaker safety check. This is because the STL promises not to invalidate iterators when appending up to the capacity. Since we cannot retroactively update all the iterators on `push_back()`, I've instead sized it to the capacity. This is not as good, but at least will stop the iterator from going off the end of the buffer. There was also no test for this, so I've added one in the `std` directory. - `std::string` has two ambiguities to deal with. First, I opted not to size it against the capacity. https://eel.is/c++draft/string.require#4 says iterators are invalidated on an non-const operation. Second, whether the iterator can reach the NUL terminator. The previous debug tests and the special-case in https://eel.is/c++draft/string.access#2 suggest no. If either of these causes widespread problems, I figure we can revisit. - `resize_and_overwrite.pass.cpp` assumed `std::string`'s iterator supported `s.begin().base()`, but I see no promise of this in the standard. GCC also doesn't support this. I fixed the test to use `std::to_address`. - `alignof.compile.pass.cpp`'s pointer isn't enough of a real pointer. (It needs to satisfy `NullablePointer`, `LegacyRandomAccessIterator`, and `LegacyContiguousIterator`.) `__bounded_iter` seems to instantiate enough to notice. I've added a few more bits to satisfy it. Fixes #78805
2024-07-18[libc++][strings] P2591R5: Concatenation of strings and string views (#88389)Hristo Hristov1-0/+216
Implemented: https://wg21.link/P2591R5 - https://eel.is/c++draft/string.syn - https://eel.is/c++draft/string.op.plus --------- Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-06-28[libc++] Clean up and update deployment target features (#96312)Louis Dionne3-12/+7
This patch removes many annotations that are not relevant anymore since we don't support or test back-deploying to macOS < 10.13. It also cleans up raw usage of target triples to identify versions of dylibs shipped on prior versions of macOS, and uses the target-agnostic Lit features instead. Finally, it reorders both the Lit backdeployment features and the corresponding availability macros in the library in a way that makes more sense, and reformulates the Lit backdeployment features in terms of when a version of LLVM was introduced instead of encoding the system versions on which it hasn't been introduced yet. Although one can be derived from the other, encoding the negative form is extremely error-prone. Fixes #80901
2024-06-21[libc++] Fix deployment target Lit features (#94791)Louis Dionne3-4/+4
We were not making any distinction between e.g. the "Apple-flavored" libc++ built from trunk and the system-provided standard library on Apple platforms. For example, any test that would be XFAILed on a back-deployment target would unexpectedly pass when run on that deployment target against the tip of trunk Apple-flavored libc++. In reality, that test would be expected to pass because we're running against the latest libc++, even if it is Apple-flavored. To solve this issue, we introduce a new feature that describes whether the Standard Library in use is the one provided by the system by default, and that notion is different from the underlying standard library flavor. We also refactor the existing Lit features to make a distinction between availability markup and the library we're running against at runtime, which otherwise limit the flexibility of what we can express in the test suite. Finally, we refactor some of the back-deployment versions that were incorrect (such as thinking that LLVM 10 was introduced in macOS 11, when in reality macOS 11 was synced with LLVM 11). Fixes #82107
2024-01-25[ASan][libc++] Correct (explicit) annotation size (#79292)Tacet1-0/+18
A quick examination suggests that the current code in the codebase does not lead to incorrect annotations. However, the intention is for the object after the function to be annotated in a way that only its contents are unpoisoned and the rest is poisoned. This commit makes it explicit and avoids potential issues in future. In addition, I have implemented a few tests for a function that helped me identify the specific argument value. Notice: there is no known scenario where old code results in incorrect annotation.
2024-01-24Unconditionally lower std::string's alignment requirement from 16 to 8. (#68925)Eric1-0/+6
Unconditionally change std::string's alignment to 8. This change saves memory by providing the allocator more freedom to allocate the most efficient size class by dropping the alignment requirements for std::string's pointer from 16 to 8. This changes the output of std::string::max_size, which makes it ABI breaking. That said, the discussion concluded that we don't care about this ABI break. and would like this change enabled universally. The ABI break isn't one of layout or "class size", but rather the value of "max_size()" changes, which in turn changes whether `std::bad_alloc` or `std::length_error` is thrown for large allocations. This change is the child of PR #68807, which enabled the change behind an ABI flag.
2023-12-14[libc++][test] Enhance ADDITIONAL_COMPILE_FLAGS, use ↵Stephan T. Lavavej1-1/+1
TEST_MEOW_DIAGNOSTIC_IGNORED sparingly (#75317) This is the last PR that's needed (for now) to get libc++'s tests working with MSVC's STL. The ADDITIONAL_COMPILE_FLAGS machinery is very useful, but also very problematic for MSVC, as it doesn't understand most of Clang's compiler options. We've been dealing with this by simply marking anything that uses ADDITIONAL_COMPILE_FLAGS as FAIL or SKIPPED, but that creates significant gaps in test coverage. Fortunately, ADDITIONAL_COMPILE_FLAGS also supports "features", which can be slightly enhanced to send Clang-compatible and MSVC-compatible options to the right compilers. This patch adds the gcc-style-warnings and cl-style-warnings Lit features, and uses that to pass the appropriate warning flags to tests. It also uses TEST_MEOW_DIAGNOSTIC_IGNORED for a few local suppressions of MSVC warnings.
2023-12-13[ASan][libc++] std::basic_string annotations (#72677)Tacet88-0/+569
This commit introduces basic annotations for `std::basic_string`, mirroring the approach used in `std::vector` and `std::deque`. Initially, only long strings with the default allocator will be annotated. Short strings (_SSO - short string optimization_) and strings with non-default allocators will be annotated in the near future, with separate commits dedicated to enabling them. The process will be similar to the workflow employed for enabling annotations in `std::deque`. **Please note**: these annotations function effectively only when libc++ and libc++abi dylibs are instrumented (with ASan). This aligns with the prevailing behavior of Memory Sanitizer. To avoid breaking everything, this commit also appends `_LIBCPP_INSTRUMENTED_WITH_ASAN` to `__config_site` whenever libc++ is compiled with ASan. If this macro is not defined, string annotations are not enabled. However, linking a binary that does **not** annotate strings with a dynamic library that annotates strings, is not permitted. Originally proposed here: https://reviews.llvm.org/D132769 Related patches on Phabricator: - Turning on annotations for short strings: https://reviews.llvm.org/D147680 - Turning on annotations for all allocators: https://reviews.llvm.org/D146214 This PR is a part of a series of patches extending AddressSanitizer C++ container overflow detection capabilities by adding annotations, similar to those existing in `std::vector` and `std::deque` collections. These enhancements empower ASan to effectively detect instances where the instrumented program attempts to access memory within a collection's internal allocation that remains unused. This includes cases where access occurs before or after the stored elements in `std::deque`, or between the `std::basic_string`'s size (including the null terminator) and capacity bounds. The introduction of these annotations was spurred by a real-world software bug discovered by Trail of Bits, involving an out-of-bounds memory access during the comparison of two strings using the `std::equals` function. This function was taking iterators (`iter1_begin`, `iter1_end`, `iter2_begin`) to perform the comparison, using a custom comparison function. When the `iter1` object exceeded the length of `iter2`, an out-of-bounds read could occur on the `iter2` object. Container sanitization, upon enabling these annotations, would effectively identify and flag this potential vulnerability. This Pull Request introduces basic annotations for `std::basic_string`. Long strings exhibit structural similarities to `std::vector` and will be annotated accordingly. Short strings are already implemented, but will be turned on separately in a forthcoming commit. Look at [a comment](https://github.com/llvm/llvm-project/pull/72677#issuecomment-1850554465) below to read about SSO issues at current moment. Due to the functionality introduced in [D132522](https://github.com/llvm/llvm-project/commit/dd1b7b797a116eed588fd752fbe61d34deeb24e4), the `__sanitizer_annotate_contiguous_container` function now offers compatibility with all allocators. However, enabling this support will be done in a subsequent commit. For the time being, only strings with the default allocator will be annotated. If you have any questions, please email: - advenam.tacet@trailofbits.com - disconnect3d@trailofbits.com
2023-12-12Add `std::basic_string` test cases (#74830)Tacet22-0/+113
Extend `std::basic_string` tests to cover more buffer situations and length in general, particularly non-SSO cases after SSO test cases (changing buffers). This commit is a side effect of working on tests for ASan annotations. Related PR: https://github.com/llvm/llvm-project/pull/72677
2023-11-26[libc++][test] Fix unused and nodiscard warnings (#73437)Stephan T. Lavavej3-18/+12
Found while running libc++'s test suite with MSVC's STL. This is structured into a series of commits for easier reviewing; I could also split this into smaller PRs if desired. * Add void-casts for `invoke_r` calls to fix MSVC STL `[[nodiscard]]` warnings. + Our rationale is that if someone is calling `invoke_r<NonVoidType>`, it sure looks like they care about the return value. * Add `[[maybe_unused]]` to silence `-Wunused-parameter` warnings. + This happens because the parameters are used within `LIBCPP_ASSERT`, which vanishes for MSVC's STL. This also motivates the following changes. * Add `[[maybe_unused]]` to fix `-Wunused-variable` warnings. * Always void-cast `debug_comparisons` to fix `-Wunused-variable` warnings. + As this was already unused with a void-cast in one `_LIBCPP_HARDENING_MODE` branch, I'm simply lifting it next to the variable definition. * Add `[[maybe_unused]]` to fix `-Wunused-local-typedef` warnings.
2023-11-25[libc++] Removes basic_string::reserve(). (#73354)Mark de Wever3-3/+23
Implements: - P2870R3 Remove basic_string::reserve() --------- Co-authored-by: philnik777 <nikolasklauser@berlin.de>
2023-10-26[libc++] Optimize string operator[] for known large inputs (#69500)Ilya Tocar1-0/+21
If we know that index is larger than SSO size, we know that we can't be in SSO case, and should access the pointer. This removes extra check from operator[] for inputs known at compile time to be larger than SSO.
2023-10-12[libc++] Check formatting with clang-format 17 (#68928)Louis Dionne1-132/+135
This updates the clang-format we use in libc++ to 17. This is necessary to start running the generated-files checks in GitHub Actions (in #68920). In fact this is a pre-existing issue regardless of #68920 -- right now our ignore_format.txt job disagrees with the LLVM-wide clang-format job.
2023-09-28[libc++][NFC] Simplify checks for static assertions in .verify.cpp tests ↵Louis Dionne1-3/+3
(#67559) We don't neeed to handle both spellings anymore since we don't support Clang 15 anymore.
2023-09-27[libc++] Refactor string unit tests to ease addition of new allocatorsLouis Dionne127-3803/+2670
While doing this, I also found a few tests that were either clearly incorrect (e.g. testing the wrong function) or that lacked basic test coverage like testing std::string itself (e.g. the test was only checking std::basic_string with a custom allocator). In these cases, I did a few conservative drive-by changes. Differential Revision: https://reviews.llvm.org/D140550 Co-authored-by: Brendan Emery <brendan.emery@esrlabs.com>
2023-09-24[libcxx] Don't deallocate non-pointer data in string assignment. (#67200)James Y Knight1-0/+1
Previously, assignment to a std::basic_string type with a _custom_ allocator could under certain conditions attempt to interpret part of the target string's "short" string-content as if it was a "long" data pointer, and attempt to deallocate a garbage value. This is a serious bug, but code in which it might happen is rare. It required: 1. the basic_string must be using a custom allocator type which sets the propagate_on_container_copy_assignment trait to true (thus, it does not affect the default allocator, nor most custom allocators). 2. the allocator for the target string must compare not equal to the allocator for the source string (many allocators always compare equal). 3. the source of the copy must currently contain a "long" string, and the assignment-target must currently contain a "short" string. Finally, the issue would've typically been innocuous when the bytes misinterpreted as a pointer were all zero, as deallocating a nullptr is typically a no-op. This is why existing test cases did not exhibit an issue: they were all zero-length strings, which do not have data in the bytes interpreted as a pointer.
2023-09-01[libc++] Fix Lit config in `string.io`.Konstantin Varlamov1-3/+3
This file was accidentally formatted by D140612, resulting in incorrect syntax.
2023-09-01[libc++] Apply clang formatting to all string unit testsBrendan Emery222-42416/+41448
This applies clang-format to the std::string unit tests in preparation for landing https://reviews.llvm.org/D140550. Differential Revision: https://reviews.llvm.org/D140612
2023-07-05[libc++][ranges] Implement the changes to `basic_string` from P1206 ↵varconst7-0/+1315
(`ranges::to`): - add the `from_range_t` constructors and the related deduction guides; - add the `insert_range`/`assign_range`/etc. member functions. (Note: this patch is split from https://reviews.llvm.org/D142335) Differential Revision: https://reviews.llvm.org/D149832
2023-06-13[libc++] Mark slow tests as unsupported on GCCLouis Dionne3-0/+6
Some tests in our test suite are unbelievably slow on GCC due to the use of the always_inline attribute. See [1] for more details. This patch introduces the GCC-ALWAYS_INLINE-FIXME lit feature to disable tests that are plagued by that issue. At the same time, it moves several existing tests from ad-hoc `UNSUPPORTED: gcc-12` markup to the new GCC-ALWAYS_INLINE-FIXME feature, and marks the slowest tests reported by the CI as `UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME`. [1]: https://discourse.llvm.org/t/rfc-stop-supporting-extern-instantiations-with-gcc/71277/1 Differential Revision: https://reviews.llvm.org/D152736
2023-05-25[NFC][Py Reformat] Reformat python files in libcxx/libcxxabiTobias Hieta1-2/+2
This is an ongoing series of commits that are reformatting our Python code. Reformatting is done with `black`. If you end up having problems merging this commit because you have made changes to a python file, the best way to handle that is to run git checkout --ours <yourfile> and then reformat it with black. If you run into any problems, post to discourse about it and we will try to help. RFC Thread below: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style Reviewed By: #libc, kwk, Mordante Differential Revision: https://reviews.llvm.org/D150763
2023-05-23[libc++] Updates C++2b to C++23.Mark de Wever1-2/+2
During the ISO C++ Committee meeting plenary session the C++23 Standard has been voted as technical complete. This updates the reference to c++2b to c++23 and updates the __cplusplus macro. Note since we use clang-tidy 16 a small work-around is needed. Clang knows -std=c++23 but clang-tidy not so for now force the lit compiler flag to use -std=c++2b instead of -std=c++23. Reviewed By: #libc, philnik, jloser, ldionne Differential Revision: https://reviews.llvm.org/D150795
2023-03-30[libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_libLouis Dionne2-3/+3
The use_system_cxx_lib Lit feature was only used for back-deployment testing. However, one immense hole in that setup was that we didn't have a proper way to test Apple's own libc++ outside of back-deployment, which was embodied by the fact that we needed to define _LIBCPP_DISABLE_AVAILABILITY when testing (see change in libcxx/utils/libcxx/test/params.py). This led to the apple-system testing configuration not checking for availability markup, which is obviously quite bad since the library we ship actually has availability markup. Using stdlib=<VENDOR>-libc++ instead to encode back-deployment restrictions on tests is simpler and it makes it possible to naturally support tests such as availability markup checking even in the tip-of-trunk Apple-libc++ configuration. Differential Revision: https://reviews.llvm.org/D146366