summaryrefslogtreecommitdiff
path: root/libcxx/include
Commit message (Collapse)AuthorAgeFilesLines
* [libc++] Implement P2505R5(Monadic operations for std::expected).yronglin2023-05-182-24/+598
| | | | | | | | Implement P2505R5(https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2505r5.html) Reviewed By: #libc, philnik, ldionne Differential Revision: https://reviews.llvm.org/D140911
* Revert "[libc++] Implement P2505R5(Monadic operations for std::expected)."yronglin2023-05-182-598/+24
| | | | | | | | | | This reverts commit ebc111b08bddca55d5f7e560a20bdb2c913d80cb. Sorry, I forgot to append Phabricator reversion when land D140911, I try to revert this change and reland. Reviewed By: #libc, ldionne, EricWF Differential Revision: https://reviews.llvm.org/D150793
* [libcxx] Fix crash in std::stringstream with payload >= INT_MAXAzat Khuzhin2023-05-171-1/+1
| | | | | | | | | | | | | | | | stringstream does works for payload > INT_MAX, however stringstream::gcount() can break the internal field (__nout_) and this breaks the stringstream itself, and so the program will crash. Fix this, by using __pbump(streamsize) over pbump(int) Note, libstdc++ does not have this bug. Reviewed By: #libc, ldionne, Mordante Spies: arichardson, Mordante, philnik, ldionne, libcxx-commits, mikhail.ramalho Differential Revision: https://reviews.llvm.org/D146294
* [libc++] Implement P2505R5(Monadic operations for std::expected).yronglin2023-05-172-24/+598
| | | | Signed-off-by: yronglin <yronglin777@gmail.com>
* [libc++][ranges] Implement the changes to `deque` from P1206 (`ranges::to`):varconst2023-05-171-11/+220
| | | | | | | | | - 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/D149827
* [libc++] Utilities for implementing stop_tokenHui2023-05-176-0/+364
| | | | | | | | | This change contains three util classes that were out from D145183 to make incremental progress - automic_unique_lock - intrusive_list - intrusive_shared_ptr Differential Revision: https://reviews.llvm.org/D150205
* [libcxx] Add mdspan/extentsChristian Trott2023-05-166-0/+544
| | | | | | | | | | | | | | | | This patch adds std::extents. extents is one of the core classes used by std::mdspan. It describes a multi-dimensional index space with a mix of compile time and runtime sizes. Furthermore, it is templated on the index type used to describe the multi-dimensional index space. The class is designed to be highly optimizable in performance critical code sections, and is fully useable in constant expressions contexts. Testing of this class tends to be somewhat combinatorical, due to the large number of possible corner cases involved in situations where we have both runtime and compile time extents. To add to this, the class is designed to be interoperable (in particular constructible) from arguments which only need to be convertible to the index_type, but are otherwise arbitrary user types. For a larger discussion on the design of this class refer to: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0009r18.html Co-authored-by: Damien L-G <dalg24@gmail.com> Reviewed By: ldionne, #libc Spies: libcxx-commits, H-G-Hristov, tschuett, philnik, arichardson, Mordante, crtrott Differential Revision: https://reviews.llvm.org/D148067
* [libc++] Add C++20 stringstream::view()Piotr Fusik2023-05-161-0/+44
| | | | | | | | Reviewed By: #libc, philnik, Mordante Spies: Mordante, philnik, libcxx-commits Differential Revision: https://reviews.llvm.org/D148641
* [libc++][format] Removes format sources.Mark de Wever2023-05-161-8/+5
| | | | | | | | | | | | | | | | | | | | | The source file is used to anchor the destructor of format_error. When format is moved from experimental to stable this code would move to the dylib. One issue with code in the dylib is that it can't be used in constexpr context. There is a proposal to make format work during constant evaluation P2758 Emitting messages at compile time This paper has initially been received favourable by EWG. Therefore move the code to the header. This also avoids possible availability issues on Mac back deployment targets. Note it is expected that format will no longer be experimental with the next LLVM release. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D150073
* [libc++][PSTL] Implement std::copy{,_n}Nikolas Klauser2023-05-155-44/+59
| | | | | | | | Reviewed By: ldionne, #libc Spies: jloser, libcxx-commits Differential Revision: https://reviews.llvm.org/D149706
* [libc++][NFC] Use angle brackets to include ranges_mismatch.hLouis Dionne2023-05-151-1/+1
|
* [libc++] Removes _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTIONMark de Wever2023-05-151-138/+0
| | | | | | | | This was planned for LLVM 15 but was never done. Reviewed By: #libc, philnik Differential Revision: https://reviews.llvm.org/D150580
* [libc++] Implement ranges::starts_withzijunzhao2023-05-154-0/+105
|
* Revert "[libc++][PSTL] Implement std::copy{,_n}"Nikolas Klauser2023-05-155-59/+44
| | | | | | This reverts commit b049fc0481bc387f57fd61da7239f85ef91096c1. The wrong patch was landed.
* [libc++][PSTL] Implement std::copy{,_n}Nikolas Klauser2023-05-155-44/+59
| | | | | | | | Reviewed By: ldionne, #libc Spies: jloser, libcxx-commits Differential Revision: https://reviews.llvm.org/D149706
* [libc++][PSTL] Implement std::transformNikolas Klauser2023-05-159-44/+215
| | | | | | | | Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D149615
* Revert "[libc++][PSTL] Implement std::transform"Nikolas Klauser2023-05-155-131/+44
| | | | | | This reverts commit cbd9e5454741ebe6b39521fe1a8ed4eed5c2c801. The wrong patch was landed.
* [libc++][PSTL] Implement std::transformNikolas Klauser2023-05-155-44/+131
| | | | | | | | Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D149615
* [libc++] Moves unwrap_reference to type_traits.Mark de Wever2023-05-147-10/+12
| | | | | | | | This was discovered while working on modules. Reviewed By: #libc, philnik Differential Revision: https://reviews.llvm.org/D149351
* [libc++][PSTL] Make the PSTL submodules only have one headerIan Anderson2023-05-131-2/+14
| | | | | | | | Module map generation for the private detail headers is easier done if each private header is by itself in a submodule. Move the __algorithm/pstl_backends into their own submodules. Reviewed By: philnik, #libc Differential Revision: https://reviews.llvm.org/D150503
* [libc++][NFC] Use _LIBCPP_STD_VER instead of ↵Nikolas Klauser2023-05-132-3/+3
| | | | | | | | | | __cpp_lib_atomic_is_always_lock_free Reviewed By: #libc, ldionne, Mordante Spies: Mordante, libcxx-commits Differential Revision: https://reviews.llvm.org/D150421
* [libc++][PSTL] Move the already implemented functions to the new dispatching ↵Nikolas Klauser2023-05-1215-288/+424
| | | | | | | | | | scheme Reviewed By: ldionne, #libc Spies: arichardson, pcwang-thead, libcxx-commits, miyuki Differential Revision: https://reviews.llvm.org/D150277
* [libc++][ranges] Fix `iota_view`'s constructor's incorrect constraintHui2023-05-121-1/+1
| | | | | | One of the overload of the constructors should check Bound is not unreachable_sentinel_t, instead of the Start Differential Revision: https://reviews.llvm.org/D150206
* [NFC][libc++][format] Uses uniform member signatures.Mark de Wever2023-05-1214-167/+179
| | | | | | | | | | | The newer formatters for (tuple, vector<bool>::reference) specify the formatter's parse and format member function. This signature is slightly different from the signature for existing formatters. Adapt the existing formatters to the new style. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D150034
* [libc++][PSTL] Add more specialized backend customization pointsLouis Dionne2023-05-1112-37/+337
| | | | | | | | | | This allows backends to customize arbitrary parallel algorithms, which was requested pretty often. Reviewed By: #libc, ldionne Spies: arichardson, miyuki, crtrott, dalg24, __simt__, philnik, libcxx-commits Differential Revision: https://reviews.llvm.org/D149686
* [libc++][PSTL] Add missing includes to PSTL headersIan Anderson2023-05-108-2/+22
| | | | | | | | | | | Several PSTL headers included by <algorithm> are missing includes for things they use. Switch some quoted includes to angle includes. (Issues found from running `check-cxx` with https://reviews.llvm.org/D144322) Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D150085
* [libc++] Consistently enable __CORRECT_ISO_CPP_WCHAR_H_PROTO in mbstate.Jordan Rupprecht2023-05-102-0/+10
| | | | | | | | | | | | In libc++'s `wchar.h`, before we forward to the system `wchar.h`, we set `__CORRECT_ISO_CPP_WCHAR_H_PROTO` to ensure it defines the correct signature (e.g. `extern "C++" const wchar_t *wmemchr` and not `extern wchar_t *wmemchr`). After D148542, there are cases where we include the system `wchar.h` from within `__mbstate_t.h` without setting that, and so we get a function type mismatch if we transitively include `wchar.h` through multiple headers in a modules-enabled build. Consistently setting it here resolves those build errors. Alternative 1: we could put this in `__config` instead. I chose to put it here for a more limited scope. Alternative 2: we could patch `wchar.h` itself to work correctly and remove references `__CORRECT_ISO_CPP_WCHAR_H_PROTO` from libc++ entirely. It does already set it, but with an additional condition that it is being built by GCC >= 4.4. Clang does pretend to be GCC via `__GNUC__` etc. which can be controlled via `-fgnuc-version` command line flags, but that might have other consequences. Reviewed By: ldionne, #libc, MaskRay Differential Revision: https://reviews.llvm.org/D150015
* [libc++][NFC] Remove duplicate declaration of __iter_value_typeLouis Dionne2023-05-101-3/+0
| | | | The exact same declaration exists a few lines above.
* [libcxx] Fix pstl __init_ identifier after 9c4717aAaron Siddhartha Mondal2023-05-101-4/+4
| | | | | | Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D150201
* [libc++][PSTL] Move the remaining configuration into __configNikolas Klauser2023-05-1023-84/+61
| | | | | | | | Reviewed By: ldionne, #libc Spies: sstefan1, jplehr, arichardson, libcxx-commits, miyuki Differential Revision: https://reviews.llvm.org/D150217
* [libc++] Add assertions for potential OOB reads in std::sortLouis Dionne2023-05-091-24/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We introduced an optimization to std::sort in 4eddbf9f10a6. However, that optimization led to issues where users that were passing invalid comparators to std::sort could start seeing OOB reads. This led to the revert of the std::sort optimization from the LLVM 16 release (see https://llvm.org/D146421). This patch introduces _LIBCPP_ASSERTs to the places in the algorithm where we make an assumption that the comparator will be consistent and hence avoid a bounds check based on that. If the comparator happens not to be consistent with itself, these are the places where we would incorrectly go out of bounds. This allows users that enable libc++ assertions to catch such misuse at the cost of basically a bounds check. For users that do not enable libc++ assertions (which is 99.9% of users since assertions are off by default), this is basically a no-op, and in fact the assertion will turn into a __builtin_assume, making it explicit to the compiler that it can rely on the fact that we're not going out of bounds. I think this patch strikes the right balance. Folks that want absolute performance will get what they want, since it is a precondition for the comparator to be consistent, so the bounds checks are technically not mandatory. Folks who want more safety *already* need to be enabling libc++ assertions to catch other types of bugs (like operator[] OOB), so this solution should also work for them. I do think we have a lot of work towards popularizing the use of libc++ assertions and integrating it better so that users don't have to know about the obscure _LIBCPP_ENABLE_ASSERTIONS macro to enable them, but that's a separate concern. rdar://106897934 Differential Revision: https://reviews.llvm.org/D147089
* [libc++] Provide an assignment operator from pair<U, V> in C++03Louis Dionne2023-05-091-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds an extension to std::pair in C++03 mode where we provide an assignment operator from a pair<U, V>. Previously, any code trying to trigger such an assignment operator would have tried using the `operator=(pair const&)` copy assignment operator, which would then have tried creating a `pair const&` by using the unconstrained pair<U, V> constructor. After this patch, pair will instead go through operator= directly if its member types are assignable. If they are not assignable, the extension operator= is disabled with SFINAE and the pair(pair<U, V>) constructor will be used. Since that constructor is unconstrained, that will either work or give a hard error. This should be pretty transparent to users, but this is technically a behavior change in C++03. Indeed, if a type has both a valid cross-type assignment operator *and* a valid cross-type constructor, the library will now prefer the cross-type assignment instead of going through the cross-type constructor and then using the copy-constructor. Since this is the mandated behavior in C++11, however, one could argue that any user broken by that needs to change their code. The motivation for this change is to allow simplifying the definition of std::map's value_type, which requires handling assignment to a pair of references properly. This patch will allow removing complexity from https://llvm.org/D121485 instead of adding complexity in that patch. Differential Revision: https://reviews.llvm.org/D150119
* [libc++][ranges] Implement the changes to vector from P1206 (`ranges::to`):varconst2023-05-087-188/+481
| | | | | | | | - 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/D149826
* [libc++][spaceship] Implement `operator<=>` for `array`Hristo Hristov2023-05-081-27/+28
| | | | | | | | Implements part of P1614R2 "The Mothership has Landed" Reviewed By: Mordante, #libc, philnik Differential Revision: https://reviews.llvm.org/D132265
* [libc++] Use the __is_trivially_equality_comparable builtinNikolas Klauser2023-05-077-158/+278
| | | | | | | | Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D148553
* [libc++][Modules] Add missing includes and exportsIan Anderson2023-05-0724-3/+86
| | | | | | | | | | | | Several headers are missing includes for things they use. type_traits.is_enum needs to export type_traits.integral_constant so that clients can access its `value` member without explicitly including __type_traits/integral_constant.h themselves. Make `subrange_fwd` a peer submodule to `subrange` rather than a submodule of it, and have `subrange` export `subrange_fwd`. That will make it easier to programmatically generate modules for the private detail headers, and it will accomplish the same effect that __ranges/subrange.h will make subrange_kind visible. Reviewed By: Mordante, #libc Differential Revision: https://reviews.llvm.org/D150055
* [libc++] Modernizes the forwarded ios headers.Mark de Wever2023-05-076-28/+28
| | | | | | Reviewed By: #libc, philnik Differential Revision: https://reviews.llvm.org/D150030
* [libc++][format] Fixes vector<bool> requirements.Mark de Wever2023-05-064-6/+3
| | | | | | | | | | | | | Makes sure the formatter for the vector<bool>::reference is enabled when only the header <vector> is included. Before this change it required <vector> and <format> to be included. This violated the requirements in the Standard. Fixes: https://llvm.org/PR61314 Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D149543
* Revert "[2a/3][ASan][libcxx] std::deque annotations"Vitaly Buka2023-05-062-331/+6
| | | | | | | https://lab.llvm.org/buildbot/#/builders/168/builds/13310 https://lab.llvm.org/buildbot/#/builders/239/builds/2107 This reverts commit 9a5f283139201ba5878780c06c97e4ad1f5eac39.
* [libc++][PSTL] Make the PSTL available by default under -fexperimental-libraryNikolas Klauser2023-05-0517-25/+67
| | | | | | | | | | This removes the need for a custom libc++ build to have a basic set of PSTL algorithms. Reviewed By: ldionne, #libc Spies: miyuki, libcxx-commits, arichardson Differential Revision: https://reviews.llvm.org/D149624
* [2a/3][ASan][libcxx] std::deque annotationsAdvenam Tacet2023-05-052-6/+331
| | | | | | | | | | | | | | | | | | | | | This revision 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, to std::string and `std::deque` collections. These changes allow ASan to detect cases when the instrumented program accesses memory which is internally allocated by the collection but is still not in-use (accesses before or after the stored elements for `std::deque`, or between the size and capacity bounds for `std::string`). The motivation for the research and those changes was a bug, found by Trail of Bits, in a real code where an out-of-bounds read could happen as two strings were compared via a std::equals function that took `iter1_begin`, `iter1_end`, `iter2_begin` iterators (with a custom comparison function). When object `iter1` was longer than `iter2`, read out-of-bounds on `iter2` could happen. Container sanitization would detect it. This revision introduces annotations for `std::deque`. Each chunk of the container can now be annotated using the `__sanitizer_annotate_double_ended_contiguous_container` function, which was added in the rG1c5ad6d2c01294a0decde43a88e9c27d7437d157. Any attempt to access poisoned memory will trigger an ASan error. Although false negatives are rare, they are possible due to limitations in the ASan API, where a few (usually up to 7) bytes before the container may remain unpoisoned. There are no false positives in the same way as with `std::vector` annotations. This patch only supports objects (deques) that use the standard allocator. However, it can be easily extended to support all allocators, as suggested in the D146815 revision. Furthermore, the patch includes the addition of the `is_double_ended_contiguous_container_asan_correct` function to libcxx/test/support/asan_testing.h. This function can be used to verify whether a `std::deque` object has been correctly annotated. Finally, the patch extends the unit tests to verify ASan annotations (added LIBCPP_ASSERTs). If a program is compiled without ASan, all helper functions will be no-ops. In binaries with ASan, there is a negligible performance impact since the code from the change is only executed when the deque container changes in size and it’s proportional to the change. It is important to note that regardless of whether or not these changes are in use, every access to the container's memory is instrumented. Reviewed By: #libc, philnik Spies: mikhail.ramalho, Enna1, #sanitizers, philnik, libcxx-commits Differential Revision: https://reviews.llvm.org/D132092
* [libc++] Remove Solaris related codeLouis Dionne2023-05-059-211/+9
| | | | | | | | This was contributed ~10 years ago, but we don't officially support it and I am not aware of any bot testing it, so this has likely rotten to the point where it is unusable. Differential Revision: https://reviews.llvm.org/D138680
* [libc++][spaceship] Implement `operator<=>` for `optional`Hristo Hristov2023-05-051-76/+139
| | | | | | | | | | | | | Implements parts of **P1614R2**: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html - Implemented `operator<=>` for `optional` - Updated "optional synopsis" to match the current draft https://eel.is/c++draft/optional closer - Implemented https://cplusplus.github.io/LWG/issue3566 - Implemented https://cplusplus.github.io/LWG/issue3746 Reviewed By: #libc, philnik, ldionne Differential Revision: https://reviews.llvm.org/D146392
* [ASan][libcxx] Annotating std::vector with all allocatorsAdvenam Tacet2023-05-041-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This revision 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, to std::string and std::deque collections. These changes allow ASan to detect cases when the instrumented program accesses memory which is internally allocated by the collection but is still not in-use (accesses before or after the stored elements for std::deque, or between the size and capacity bounds for std::string). The motivation for the research and those changes was a bug, found by Trail of Bits, in a real code where an out-of-bounds read could happen as two strings were compared via a std::equals function that took iter1_begin, iter1_end, iter2_begin iterators (with a custom comparison function). When object iter1 was longer than iter2, read out-of-bounds on iter2 could happen. Container sanitization would detect it. In revision D132522, support for non-aligned memory buffers (sharing first/last granule with other objects) was added, therefore the check for standard allocator is not necessary anymore. This patch removes the check in std::vector annotation member function (__annotate_contiguous_container) to support different allocators. Additionally, this revision fixes unpoisoning in std::vector. It guarantees that __alloc_traits::deallocate may access returned memory. Originally suggested in D144155 revision. If you have any questions, please email: - advenam.tacet@trailofbits.com - disconnect3d@trailofbits.com Reviewed By: #libc, #sanitizers, philnik, vitalybuka, ldionne Spies: mikhail.ramalho, manojgupta, ldionne, AntonBikineev, ayzhao, hans, EricWF, philnik, #sanitizers, libcxx-commits Differential Revision: https://reviews.llvm.org/D136765
* [ASan][libcxx] A way to turn off annotations for containers with a specific ↵Advenam Tacet2023-05-041-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | allocator This revision is part of our efforts to support container annotations with (almost) every allocator. That patch is necessary to enable support for most annotations (D136765). Without a way to turn off annotations, it's hard to use ASan with area allocators (no calls to destructors). This is an answer to a request about it. This patch provides a solution to the aforementioned issue by introducing a new template structure `__asan_annotate_container_with_allocator`, which allows the disabling of container annotations for a specific allocator. This patch also introduces `_LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS` FTM. To turn off annotations, it is sufficient to create a template specialization with a false value using a [Unary Type Trait](https://en.cppreference.com/w/cpp/types/integral_constant). The proposed structure is being used in the code enabling annotations for all allocators in `std::vector`, `std::basic_string`, and `std::deque`. (D136765 D146214 D146815) Possibility to do it was added to ASan API in rGdd1b7b797a116eed588fd752fbe61d34deeb24e4 commit. For context on not calling a destructor, look at https://eel.is/c++draft/basic.life#5 and notes there, you may also read a discussion in D136765. Reviewed By: ldionne, philnik, #libc, hans Spies: EricWF, mikhail.ramalho, #sanitizers, libcxx-commits, hans, vitalybuka Differential Revision: https://reviews.llvm.org/D145628
* [libc++][PSTL] Replace _PSTL_ASSERT with _LIBCPP_ASSERTNikolas Klauser2023-05-045-36/+37
| | | | | | | | Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D149605
* [libc++][PSTL] Move all the OpenMP conditionals into a single blockNikolas Klauser2023-05-041-25/+22
| | | | | | | | | | All the used OpenMP pragmas are available with OpenMP 4.0, so they can all share a single conditional block. Reviewed By: ldionne, #libc Spies: yaxunl, sstefan1, guansong, jplehr, libcxx-commits, sunshaoce Differential Revision: https://reviews.llvm.org/D149603
* [libc++][PSTL][NFC] Fix the naming in the SIMD backendNikolas Klauser2023-05-043-78/+81
| | | | | | | | Reviewed By: ldionne, #libc Spies: sstefan1, jplehr, libcxx-commits, miyuki Differential Revision: https://reviews.llvm.org/D149787
* [libc++] Add missing test for std::hash<std::filesystem::path>Louis Dionne2023-05-041-1/+5
| | | | Differential Revision: https://reviews.llvm.org/D149696
* [libc++][PSTL] Reduce the amount of transitive includesNikolas Klauser2023-05-0313-17/+24
| | | | | | | | Reviewed By: ldionne, #libc Spies: libcxx-commits, miyuki Differential Revision: https://reviews.llvm.org/D149599