12453 Commits

Author SHA1 Message Date
Louis Dionne
3a63407686
[libc++] Make __atomic_base into an implementation detail of std::atomic (#115764)
The __atomic_base base class is only useful to conditionalize the
operations we provide inside std::atomic. It shouldn't be used directly
from other places in the library which can use std::atomic directly
instead.

Since we've granularized our includes, using std::atomic directly should
not make much of a difference compile-time wise.

This patch starts using std::atomic directly from other classes like
std::barrier and std::latch. Changing this shouldn't be an ABI break
since both classes have the same size and layout.

The benefits of this patch are isolating other parts of the code base
from implementation details of std::atomic and simplifying the mental
model for std::atomic's layers of implementation by making it clear that
__atomic_base is only an implementation detail of std::atomic.
2024-11-20 00:35:14 +01:00
Petr Hosek
012dd8be4b
[libcxx] Passthrough the necessary CMake variables to benchmarks (#116644)
This addresses the issue uncovered by #115361. Previously, we weren't
building benchmarks in many cases due to the following block:

e58949632e/libcxx/CMakeLists.txt (L162-L172)

We need to passthrough the necessary variables into the benchmarks
subbuild and use correct syntax.
2024-11-19 14:23:29 -08:00
Nikolas Klauser
01a1ca72e8 [libc++][NFC] Format a pait test
I'll be modifying this test in a future PR.
2024-11-19 13:53:43 +01:00
Louis Dionne
3a3517c5e9
[libc++] Improve the tests for vector::erase (#116265)
In particular, test everything with both a normal and a min_allocator,
add tests for a few corner cases and add tests with types that are
trivially relocatable. Also add tests that count the number of
assignments performed by vector::erase, since that is mandated by the
Standard.

This patch is a preparation for optimizing vector::erase.
2024-11-19 00:49:22 +01:00
Louis Dionne
ec67ad594b [libc++][NFC] Format <string> 2024-11-18 23:23:46 +01:00
Nikolas Klauser
85ef9666c8
[libc++] Avoid including all of <thread> in <future> (#116541) 2024-11-18 20:04:05 +01:00
Nikolas Klauser
de5e4ebb5a
[libc++] Remove transitive includes from empty headers (#116295)
This removes transitive includes that are only in a header that is empty
in a given C++ version.
2024-11-18 19:59:47 +01:00
Peng Liu
c25e09e238
[libc++][test] Speed up input generating functions for benchmark tests (#115544)
The input generating functions for benchmark tests in the GenerateInput.h
file can be slightly improved by invoking vector::reserve before calling
vector::push_back. This slight performance improvement could potentially
speed-up all benchmark tests for containers and algorithms that use these
functions as inputs.
2024-11-18 16:32:54 +01:00
Louis Dionne
748a29f052 [libc++][NFC] Fix incorrect include guard 2024-11-18 14:29:14 +01:00
Louis Dionne
5a48162dc8
[libc++] Remove unnecessary std::vector accessors (#114423)
Now that we don't use __compressed_pair anymore inside std::vector, we
can remove some unnecessary accessors. This is a mechanical replacement
of the __alloc() and __end_cap() accessors, and similar for
std::vector<bool>.

Note that I consistently used this->__alloc_ instead of just __alloc_
since most of the code in <vector> uses that pattern to access members.
I don't think this is necessary anymore (and I'm even less certain I
like this), but I went for consistency with surrounding code. If we want
to change that, we can do a follow-up mechanical change.
2024-11-18 10:48:09 +01:00
A. Jiang
b5bc528c14
[libc++] Guard __pad_and_output with _LIBCPP_HAS_LOCALIZATION (#116580)
This fixes errors for no-localization builds (possibly introduced by
#116223).
2024-11-18 17:03:29 +08:00
Nikolas Klauser
7c010bfdc5
[libc++] Remove some unnecessary boilerplate in <__chrono/duration.h> (#116238) 2024-11-17 12:23:05 +01:00
Nikolas Klauser
811186764d [libc++] Fix a few problems found by clang-tidy 2024-11-17 11:07:41 +01:00
Nikolas Klauser
dedc515999
[libc++] Avoid including <string> in <mutex> (#116254) 2024-11-16 19:25:03 +01:00
Nikolas Klauser
adb80d8a4c
[libc++] Address post-commit comments for __scope_guard (#116291)
Fixes #116204
2024-11-16 19:23:58 +01:00
Nikolas Klauser
764834d63d
[libc++] Remove <istream> and <ostream> includes from <iomanip> (#116223)
This reduces the include time of `<filesystem>` by ~50ms.
2024-11-16 18:20:55 +01:00
Nikolas Klauser
1636580b0a
[libc++] Avoid including <ostream> in <fstream> and <strstream> (#116014)
This reduces the include time of `<fstream>` from ~800ms to ~500ms.
2024-11-16 18:19:17 +01:00
Louis Dionne
649e4bf5d8 [libc++] Update the docker-compose file for actions CI 2024-11-15 10:51:37 +01:00
Louis Dionne
073159004f [libc++] Remove obsolete 'macos-ci-setup' script
We don't use it anymore since we moved to Github hosted runners
for mac instead of the Foundation-provided runners.
2024-11-15 09:07:33 +01:00
Louis Dionne
2d6459cb28
[libc++] Fix CI issues recently introduced by localization changes (#116216)
After a recent Github Actions runner policy change [1], the version of
Xcode included in the macos-14 image went from Xcode 16 to Xcode 15,
breaking our build bots.

This moves the bots to the macos 15 (public preview) image, which
contains Xcode 16.

Also, adjust an UNSUPPORTED annotation that was incorrectly targeting
macos 13.7 when it should have been targeting a version of AppleClang.

[1]: https://github.com/actions/runner-images/issues/10703
2024-11-15 00:00:54 +01:00
Nikolas Klauser
46d8aa8d6a
[libc++] Make __throw_ member functions static (#116233)
Fixes #116092
2024-11-14 22:35:20 +01:00
Louis Dionne
965f3a95b9 [libc++][NFC] Run clang-format on vector::erase test
Since I am about to make significant changes to this test, run clang-format
on it before to avoid obscuring the review.
2024-11-14 14:13:51 +01:00
Louis Dionne
5c3befb91c [libc++] Add forgotten call to std::__to_address in __uninitialized_allocator_relocate 2024-11-14 14:07:57 +01:00
Louis Dionne
8fde648aad
[libc++] Remove obsolete accessors in std::list and std::forward_list (#115748)
We don't need these accessors anymore now that we stopped using
compressed-pair.
2024-11-14 13:09:11 +01:00
Louis Dionne
e58949632e
[libc++] Define all CMake configuration features in the same location (#115361)
This moves the configuration of the CMake features to turn off RTTI,
exceptions and friends to the beginning of the CMake file, where we
configure other optional parts of the library.

This fixes an important bug where we would disable the benchmarks
because these options were not defined yet, leading to the build
thinking they were defined to OFF.
2024-11-14 13:06:43 +01:00
Louis Dionne
6721bcfd1b
[libc++] Accept iterators instead of raw pointers in __uninitialized_allocator_relocate (#114552)
This generalizes the algorithm a bit. Unfortunately, we can't make 
the call sites cleaner inside std::vector because the arguments being
passed can all be fancy pointers, which may not be contiguous iterators.
2024-11-14 11:22:48 +01:00
Nikolas Klauser
67b81e2120
[libc++] Split __shared_count out of <__memory/shared_ptr.h> (#115943)
`__shared_count` is used in a few places where `shared_ptr` isn't. This
avoids a bunch of transitive includes needed for the implementation of
`shared_ptr` in these places.
2024-11-13 12:14:02 +01:00
Nikolas Klauser
b69ddbc628
[libc++] Make variables in templates inline (#115785)
The variables are all `constexpr`, which implies `inline`. Since they
aren't `constexpr` in C++03 they're also not `inline` there. Because of
that we define them out-of-line currently. Instead we can use the C++17
extension of `inline` variables, which results in the same weak
definitions of the variables but without having all the boilerplate.
2024-11-13 11:57:16 +01:00
Peng Liu
c7df10643b
Unify naming of internal pointer members in std::vector and std::__split_buffer (#115517)
Related to PR #114423, this PR proposes to unify the naming of the
internal pointer members in `std::vector` and `std::__split_buffer` for
consistency and clarity.

Both `std::vector` and `std::__split_buffer` originally used a
`__compressed_pair<pointer, allocator_type>` member named `__end_cap_`
to store an internal capacity pointer and an allocator. However,
inconsistent naming changes have been made in both classes:
- `std::vector` now uses `__cap_` and `__alloc_` for its internal
pointer and allocator members.
- In contrast, `std::__split_buffer` retains the name `__end_cap_` for
the capacity pointer, along with `__alloc_`.

This inconsistency between the names `__cap_` and `__end_cap_` has
caused confusions (especially to myself when I was working on both
classes). I suggest unifying these names by renaming `__end_cap_` to
`__cap_` in `std::__split_buffer`.
2024-11-13 11:08:08 +01:00
Nikolas Klauser
a2042521a0
[libc++] Remove _AlgPolicy from std::copy and algorithms using std::copy (#115887)
`std::copy` doesn't use the `_AlgPolicy` for anything other than calling
itself with it, so we can just remove the argument. This also removes
the need in a few other algorithms which had an `_AlgPolicy` argument
only to call `copy`.
2024-11-12 23:03:52 +01:00
Nikolas Klauser
36fa8bdfa0
[libc++][NFC] Remove unused functions from <__split_buffer> (#115735) 2024-11-12 22:55:59 +01:00
Nikolas Klauser
5b67372aec [libc++] Remove a few unused includes from <__algorithm/find_end.h> 2024-11-12 22:11:15 +01:00
h-vetinari
99f44c8fed
[libc++] update comment for P0067R5 (#113239)
Fix review comment from #91651 that was not addressed.
2024-11-12 10:57:08 -05:00
Nikolas Klauser
e3c958a9a4
[libc++] Replace template structs with template variables in <ratio> (#115782)
This avoids a bit of boilerplate.
2024-11-12 15:15:18 +01:00
Nikolas Klauser
5098b56d22
[libc++] Introduce a standalone __scope_guard and use it in <string> (#114867)
This introduces a new `__scope_guard` without any fancy features. The
scope guard is used in `<string>` to simplify some of the ASan
annotations (especially by making it harder to forget them where
exceptions are thrown).
2024-11-12 00:00:34 +01:00
Caslyn Tonelli
bbf2ad026e
[libc++] Amend error message for _LIBCPP_HAS_THREAD_API_EXTERNAL (#115774)
Noticed this while debugging a few things following
https://github.com/llvm/llvm-project/pull/112094. Amended error message
to reflect conditional check.
2024-11-11 22:58:34 +01:00
Louis Dionne
9c3a7ad7fa
[libc++] Cleanly implement the base locale API for BSD-like platforms (#115176)
Instead of going through the old locale entry points, define the base
localization API for BSD-like platforms (Apple and FreeBSD) from
scratch, using <xlocale.h> as a basis. This doesn't actually change how
that functionality is implemented, it only avoids going through a maze
to do so.

This clean new support is implemented in a separate __locale_dir/support
directory, which mirrors what we do for the threading support API.
Eventually, everything under __locale_dir/locale_base_api will go away.

rdar://131476632
2024-11-11 13:11:23 -05:00
Nikolas Klauser
4a68e4cbd2
[libc++] Fix throwing away smaller allocations in string::shrink_to_fit (#115659)
Currently `string::shrink_to_fit()` throws away any allocations which
return more capacity than we requested, even if that allocation is still
smaller than the current capacity. This patch fixes this to compare the
returned allocation against the current capacity of the string instead
of against the requested capacity.
2024-11-11 17:16:15 +01:00
A. Jiang
9f471fd12b
[libc++][hardening] Constrain construction for __{(static_)bounded,wrap}_iter (#115271)
This PR restricts construction to cases where reference types of
source/destination iterators are (`T&`, `T&`) or (`T&`, `const T&`) (
where `T` can be const).

Fixes #50058.
2024-11-11 23:04:38 +08:00
Peng Liu
3af4c2e16e
[libc++][test] Clean up code in GenerateInput.h for benchmark testing (#115560)
This PR refines the code in `GenerateInput.h` used for benchmark testing
by implementing the following changes:

- Replaced all unqualified usages of `size_t` with `std::size_t`.
- Removed unnecessary curly braces `{}` from for loops that contain
  simple single-statement bodies, in accordance with LLVM coding
  standards.
2024-11-11 10:02:56 -05:00
Alexander Richardson
30feb35c1e
[libc++] Update CMake dependency for generate_iwyu_mapping.py (#115387)
This script does not depend on the generated headers since those are
already special-cased in header_information.py. Change the dependency
list to depend on header_information.py instead. While looking at this
code also simplify the assignment to libcxx_root inside this script.
2024-11-11 09:59:58 -05:00
Nikolas Klauser
2c10664afa
[libc++][NFC] Merge add_{const, cv, volatile}.h into a single header (#115610)
There isn't much benefit in having granular headers for only a few
simple lines of code.
2024-11-10 13:21:42 +01:00
Peng Liu
7844257fc2
[libc++] Use explicit #include instead of transitive #include (#115420)
This benchmark test currently uses `std::unique_ptr` without explicitly
`#include <memory>`. I think we should not rely on transitive inclusion.
2024-11-08 16:07:51 +01:00
A. Jiang
1645d99bc9
[libc++][hardening] Use static_assert for __(static_)bounded_iter (#115304)
We can't `static_assert` `__libcpp_is_contiguous_iterator` for
`__wrap_iter` currently because `__wrap_iter` is also used for wrapping
user-defined fancy pointers.

Fixes #115002.
2024-11-08 22:59:21 +08:00
Alona Enraght-Moony
0a7e5e3456
[libc++][docs] Document _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION (#115405)
This was added in 681cde7dd8b5613dbafc9ca54e0288477f946be3, but isn't
currently documented.
2024-11-08 12:35:31 +01:00
Zibi Sarbinowski
ef73533f36
[z/OS][libc++] Remove align_val_t dependency in small_buffer.h (#114396)
Rewriting `__alloc()` and `__dealloc()` template functions to avoid errors when `small_buffer.h` is
included in the modules LIT tests. For example:

```
test-suite-install/include/c++/v1/__utility/small_buffer.h:69:81: error: use of undeclared identifier 'align_val_t'
# |    69 |       byte* __allocation = static_cast<byte*>(::operator new[](sizeof(_Stored), align_val_t{alignof(_Stored)}));
# |       |                                                                                 ^
```
2024-11-07 13:44:49 -05:00
A. Jiang
9fd3c4115c
[libc++] Fix unexpected heterogeneous comparison (#115249)
Currently, libc++ incorrectly rejects heterogeneous comparison of
`unexpected`, because the `operator==` is only a hidden friend of
`unexpected<_Err>` but not of `unexpected<_Err2>`. We need to call the
`error()` member function on `__y`.

Fixes #115326
2024-11-07 11:49:29 -05:00
Louis Dionne
427a5cf105
[libc++] Add support for bounded iterators in std::array (#110729)
This patch introduces a new kind of bounded iterator that knows the size
of its valid range at compile-time, as in std::array. This allows computing
the end of the range from the start of the range and the size, which requires
storing only the start of the range in the iterator instead of both the start
and the size (or start and end). The iterator wrapper is otherwise identical
in design to the existing __bounded_iter.

Since this requires changing the type of the iterators returned by
std::array, this new bounded iterator is controlled by an ABI flag.

As a drive-by, centralize the tests for std::array::operator[] and add
missing tests for OOB operator[] on non-empty arrays.

Fixes #70864
2024-11-07 09:23:21 -05:00
Louis Dionne
e236a52a88
[libc++] Unify the benchmarks with the test suite (#101399)
Instead of building the benchmarks separately via CMake and running them
separately from the test suite, this patch merges the benchmarks into
the test suite and handles both uniformly.

As a result:
- It is now possible to run individual benchmarks like we run tests
  (e.g. using libcxx-lit), which is a huge quality-of-life improvement.

- The benchmarks will be run under exactly the same configuration as
  the rest of the tests, which is a nice simplification. This does
  mean that one has to be careful to enable the desired optimization
  flags when running benchmarks, but that is easy with e.g.
  `libcxx-lit <...> --param optimization=speed`.

- Benchmarks can use the same annotations as the rest of the test
  suite, such as `// UNSUPPORTED` & friends.

When running the tests via `check-cxx`, we only compile the benchmarks
because running them would be too time consuming. This introduces a bit
of complexity in the testing setup, and instead it would be better to
allow passing a --dry-run flag to GoogleBenchmark executables, which is
the topic of https://github.com/google/benchmark/issues/1827.

I am not really satisfied with the layering violation of adding the
%{benchmark_flags} substitution to cmake-bridge, however I believe
this can be improved in the future.
2024-11-07 09:07:50 -05:00
Joseph Huber
a9cd941f39 [libcxx] Fix inverted has_terminal condition
Summary:
This used to indicate "has no terminal" and now it indicates "has
terminal" but the check was not changed.
2024-11-07 07:31:42 -06:00