aboutsummaryrefslogtreecommitdiff
path: root/libcxx/test/std/strings
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 Hristov2-0/+243
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-15[Clang] Add warnings when mixing different charN_t types (#138708)cor3ntin1-2/+2
charN_t represent code units of different UTF encodings. Therefore the values of 2 different charN_t objects do not represent the same characters. In order to avoid comparing apples and oranges, we add new warnings to warn on: - Implicit conversions - Comparisons - Other cases involving arithmetic conversions We only produce the warning if we cannot establish the comparison would be safe through constant evaluation. The new `-Wimplicit-unicode-conversion` warning is enabled by default. Note that this PR intentionally doesn;t touches char/wchar_t, but it would be worth considering also warning on extending the new warnings to these types (in a follow up) Additionally most arithmetic operations on charN_t don't really make sense (ie what does it mean to addition code units), so we could add warnings for that. Fixes #138526
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. Jiang2-12/+46
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-03-05[libc++] Add missed `constexpr` to `erase(_if)` in `<string>` (#129666)A. Jiang2-8/+22
`std::erase(_if)` for `basic_string` were made `constexpr` in C++20 by cplusplus/draft@2c1ab9775cc53e848a1efff4f9976455538994d4 as follow-up changes of P0980R1. This patch implements the missed changes that were not tracked in a specific paper.
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
2025-01-16[libc++][Android] XFAIL some tests for mblen/towctrans/wctrans (#116147)Ryan Prichard1-0/+5
These functions weren't added until API 26 (Android 8.0), but libc++ is supported for API 21 and up. These APIs are undeclared as of r.android.com/3216959.
2024-12-21[libc++][C++03] Use `__cxx03/` headers in C++03 mode (#109002)Nikolas Klauser2-0/+4
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-31[libc++] Granularize <cstddef> includes (#108696)Nikolas Klauser5-6/+11
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-10-12[libc++][RFC] Always define internal feature test macros (#89178)Nikolas Klauser1-1/+1
Currently, the library-internal feature test macros are only defined if the feature is not available, and always have the prefix `_LIBCPP_HAS_NO_`. This patch changes that, so that they are always defined and have the prefix `_LIBCPP_HAS_` instead. This changes the canonical use of these macros to `#if _LIBCPP_HAS_FEATURE`, which means that using an undefined macro (e.g. due to a missing include) is diagnosed now. While this is rather unlikely currently, a similar change in `<__configuration/availability.h>` caught a few bugs. This also improves readability, since it removes the double-negation of `#ifndef _LIBCPP_HAS_NO_FEATURE`. The current patch only touches the macros defined in `<__config>`. If people are happy with this approach, I'll make a follow-up PR to also change the macros defined in `<__config_site>`.
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-09-16[libc++][modules] Don't error when including <wchar.h> or <wctype.h> without ↵Louis Dionne4-4/+4
wide character support (#108639) Instead, make the headers empty like we do for all the other carve-outs.
2024-09-12[libc++][modules] Refactor poisoned_hash_helper (#108296)Louis Dionne2-15/+15
The poisoned_hash_helper header was relying on an implicit forward declaration of std::hash located in <type_traits>. When we improve the modularization of the library, that causes issues, in addition to being a fundamentally non-portable assumption in the test suite. It turns out that the reason for relying on a forward declaration is to be able to test that std::hash is *not* provided if we don't include any header that provides it. But testing that is actually both non-portable and not really useful. Indeed, what harm does it make if additional headers provide std::hash specializations? That would certainly be conforming -- the Standard never requires an implementation to avoid providing a declaration when a given header is included, instead it mandates what *must* be provided for sure. In that spirit, it would be conforming for e.g. `<cstddef>` to define the hash specializations if that was our desire. I also don't read https://wg21.link/P0513R0 as going against that statement. Hence, this patch just removes that test which doesn't carry its weight. Fixes #56938
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-24[libc++][spaceship] Implements X::iterator container requirements. (#99343)Mark de Wever1-0/+85
This implements the requirements for the container iterator requirements for array, deque, vector, and `vector<bool>`. Implements: - LWG3352 strong_equality isn't a thing Implements parts of: - P1614R2 The Mothership has Landed Fixes: https://github.com/llvm/llvm-project/issues/62486
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-06-02[libc++] [test] Cleanup compile-only tests (#94121)Stephan T. Lavavej4-8/+0
I noticed that these tests had empty `main` functions. Dropping them and renaming the tests to `MEOW.compile.pass.cpp` will slightly improve test throughput.
2024-05-22[NFC][libc++][test] Removes C++98 support. (#92930)Mark de Wever1-1/+1
Libc++ has no separate C++98 support, it uses C++03 instead. This removes some obsolete c++98 markers in the test. Thanks to @StephanTLavavej for spotting this.
2024-04-30[libc++] Some tests are missing include for `numeric_limits` (#90345)Alex Guteniev1-0/+1
Noticed while attempting microsoft/STL#4634
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-12-05[libc++][test] Fix simple warnings (#74186)Stephan T. Lavavej6-12/+12
Found while running libc++'s tests with MSVC's STL. This fixes 3 kinds of warnings: - Add void-casts to fix `-Wunused-variable` warnings. - Avoid sign/truncation warnings in `ConvertibleToIntegral.h`. - Add `TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED` to avoid mixing preprocessor and runtime tests. - Cleanup: Add `TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED` for consistency.
2023-11-29[libc++] Add initial support for picolibcMichael Platings1-0/+3
Picolibc is a C Standard Library that is commonly used in embedded environments. This patch adds initial support for this configuration along with pre-commit CI. As of this patch, the test suite only builds the tests and nothing is run. A follow-up patch will make the test suite actually run the tests. Differential Revision: https://reviews.llvm.org/D154246
2023-11-27[libc++][test] Cleanup typos and unnecessary semicolons (#73435)Stephan T. Lavavej1-1/+1
I've structured this into a series of commits for even easier reviewing, if that helps. I could easily split this up into separate PRs if desired, but as this is low-risk with simple edits, I thought one PR would be easiest. * Drop unnecessary semicolons after function definitions. * Cleanup comment typos. * Cleanup `static_assert` typos. * Cleanup test code typos. + There should be no functional changes, assuming I've changed all occurrences. * ~~Fix massive test code typos.~~ + This was a real problem, but needed more surgery. I reverted those changes here, and @philnik777 is fixing this properly with #73444. * clang-formatting as requested by the CI.