13866 Commits

Author SHA1 Message Date
Nikolas Klauser
8c93fb0c05
[libc++] Refactor benchmarking std::make_heap and std::sort_heap together (#180935)
We're trying to get the time it takes to run all the benchmarks down, so
that we can run them on a regular basis. This patch saves us ~18 minutes
per run.
2026-02-11 13:17:44 -05:00
Nikolas Klauser
bc1e852241
[libc++] Refactor std::sort_heap benchmark (#180941)
We're trying to get the time it takes to run all the benchmarks down, so
that we can run them on a regular basis. This patch saves us ~80 seconds
per run.
2026-02-11 13:17:28 -05:00
Nikolas Klauser
f32fd56f0e
[libc++] Reduce the number of runs on the ranges::min{,max} benchmarks (#179912)
Testing a bunch of range sizes has relatively little value. This reduces
the number of benchmarks so we can run them on a regular basis. This
saves ~10 minutes when running benchmarks.

Fixes #179698
2026-02-11 13:17:03 -05:00
Xing Xue
f6bdc928a8
[libc++][AIX] Enable LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS on AIX (#179784)
This PR enables the `LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS`
macro on AIX because the functions guarded by this macro are required for
backward compatibility.
2026-02-11 13:03:15 -05:00
Nikolas Klauser
064694160f
[libc++] Rewrite the std::pop_heap benchmark (#179911)
Testing a bunch of random types has relatively little value. This
reduces the number of benchmarks so we can run them on a regular basis.
This saves ~90 seconds when running the benchmarks.
2026-02-11 12:47:33 +01:00
S. B. Tam
e0285e497a
[libc++][test] Include <ios> and <ctime> in tests for time locale facets (#179986)
Add inclusion of `<ios>` and `<ctime>` to ensure that the definitions of `std::basic_ios` and `std::tm` are available.

As a drive-by fix, change uses of `tm` to `std::tm`. The latter is guaranteed to be available in `<ctime>`, but the former isn't.
2026-02-11 15:14:28 +08:00
Louis Dionne
30f4b9c8be
[libc++] Use ValueError instead of non-existent ArgumentError (#179526)
ArgumentError does not exist. argparse.ArgumentError does exist, but
that is not what we want to use. I presume this was never caught because
we never execute that line.
2026-02-10 12:47:06 -05:00
Nikolas Klauser
9d23031032
[libc++] Only make comparators transparent in __tree if they don't cause a conversion (#179453)
We're currently unwrapping `less<T>` even if the `key_type` isn't `T`.
This causes the removal of an implicit conversion to `const T&` if the
types mismatch. Making `less<T>` transparent in that case changes
overload resolution and makes it fail potentially.

Fixes #179319
2026-02-10 13:26:55 +01:00
Vinay Deshmukh
70b7245990
[libc++] Prepare for PR #134330 by migrating to std::__static_fancy_pointer_cast (#180546)
To reduce the noise in #134330 for `libcxx/include/__tree`, we migrate
from certain `static_cast` to `std::__static_fancy_pointer_cast` in this
separate patch.

This change is needed to properly work with fancy pointers like
`min_pointer` during constant evaluation for `std::map`

Co-authored-by: Joseph Huber <huberjn@outlook.com>
2026-02-10 12:39:12 +01:00
Jessica Clarke
bf91c0969b
[libc++] Add myself as a FreeBSD point of contact 2026-02-09 22:57:52 +00:00
Hristo Hristov
e6c73eb0c4
[libc++][docs] Update [[nodiscard]] coding guidelines (#178384)
as requested in
https://github.com/llvm/llvm-project/pull/176936#pullrequestreview-3706775444

Clarifies when not to apply `[[nodiscard]]`.


https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant

---------

Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
Co-authored-by: Hristo Hristov <zingam@outlook.com>
2026-02-09 18:44:45 +02:00
Nikolas Klauser
1026944313
[libc++] Reduce the number of runs on the format_to{,n} and formatted_size benchmarks (#179922)
Testing a bunch of sizes has relatively little value. This reduces the
number of benchmarks so we can run them on a regular basis. This saves
~8 minutes when running the benchmarks.
2026-02-09 15:36:58 +01:00
Nhat Nguyen
9a60b2fa0c
[libc++] LWG4012: common_view::begin/end are missing the simple-view check (#153674)
close #105320
2026-02-09 09:17:30 +08:00
Connector Switch
706cc8b3fe
[libc++][NFC] Fix license header in test for atomic_ref (#180395) 2026-02-08 17:09:42 +08:00
Hui
2002a5926c
[libc++][test][NFC] remove unused and global variables in the test (#179038)
Fixes #178855
2026-02-07 15:30:29 +00:00
Jonathan Wakely
9029744432
[libcxx] Add missing header to re/re.alg/re.alg.search/grep.pass.cpp (#180024)
This test can't be compiled with GCC without this fix.
2026-02-07 14:20:40 +01:00
Nikolas Klauser
763761888f
[libc++] Reduce the number of runs on the stop_token benchmarks (#179914)
Testing a bunch of sizes has relatively little value. This reduces the
number of benchmarks so we can run them on a regular basis.

Fixes #179697
2026-02-07 11:17:05 +01:00
Christopher Di Bella
4d6913e14f
[libcxx] Rename __split_buffer alias template to _SplitBuffer (#180284)
`-Wchanges-meaning` is a GCC warning that catches shadowing in more
contexts. While a bit annoying here, it's a helpful warning. As such, we
need to rename the `__split_buffer` alias template in `std::vector` so
that we don't trip it up.
2026-02-06 23:22:32 +00:00
Christopher Di Bella
f735aa061b
[libc++] Tighten __add_alignment_assumption return type (#180090)
`__add_alignment_assumption` unilaterally returned a `pointer`, even
when passed a `const_pointer`. This was surfaced by some (but not all)
CI jobs when rebasing `std::vector` to have a layout type.
2026-02-06 08:26:37 -05:00
A. Jiang
39dba7b354
[libc++] Fix module builds for <__algorithm/unwrap_range.h> (#179887)
3a653afd45709432181952c0ffdb53eceb0939ae removed the inclusion of
`<__utility/declval.h>` from `<__algorithm/unwrap_range.h>`. However,
`unwrap_range.h` still needs to use `std::declval`. So we should restore
the inclusion.

The building failure with Clang modules was already caught by CI.
2026-02-06 09:42:49 +08:00
Connector Switch
2d106844e7
[libcxx] Optimize ranges::fold_left_with_iter for segmented iterators (#177853)
Part of https://github.com/llvm/llvm-project/issues/102817.

This patch attempts to optimize the performance of
`ranges::fold_left_with_iter` for segmented iterators.

- before

```
# | rng::fold_left(vector<int>)/8             2.78 ns         2.78 ns    241953718
# | rng::fold_left(vector<int>)/32            12.2 ns         12.2 ns     57579851
# | rng::fold_left(vector<int>)/50            19.2 ns         19.2 ns     36487764
# | rng::fold_left(vector<int>)/8192          3226 ns         3226 ns       216811
# | rng::fold_left(vector<int>)/1048576     441842 ns       441839 ns         1592
# | rng::fold_left(deque<int>)/8              2.83 ns         2.83 ns    243888678
# | rng::fold_left(deque<int>)/32             16.6 ns         16.6 ns     42297458
# | rng::fold_left(deque<int>)/50             22.3 ns         22.3 ns     31387998
# | rng::fold_left(deque<int>)/8192           2492 ns         2492 ns       281637
# | rng::fold_left(deque<int>)/1048576      324936 ns       324936 ns         2154
# | rng::fold_left(list<int>)/8               2.54 ns         2.54 ns    275946635
# | rng::fold_left(list<int>)/32              16.2 ns         16.2 ns     42901634
# | rng::fold_left(list<int>)/50              54.7 ns         54.7 ns     12767450
# | rng::fold_left(list<int>)/8192           15154 ns        15154 ns        56744
# | rng::fold_left(list<int>)/1048576      4976906 ns      4976867 ns          158
```

- after

```
# | rng::fold_left(vector<int>)/8             2.74 ns         2.74 ns    255954900
# | rng::fold_left(vector<int>)/32            12.1 ns         12.1 ns     57843462
# | rng::fold_left(vector<int>)/50            19.2 ns         19.2 ns     36422594
# | rng::fold_left(vector<int>)/8192          3202 ns         3202 ns       218265
# | rng::fold_left(vector<int>)/1048576     435718 ns       435709 ns         1609
# | rng::fold_left(deque<int>)/8              2.52 ns         2.52 ns    277288254
# | rng::fold_left(deque<int>)/32             14.1 ns         14.1 ns     52244463
# | rng::fold_left(deque<int>)/50             16.2 ns         16.2 ns     43131857
# | rng::fold_left(deque<int>)/8192           1695 ns         1695 ns       415620
# | rng::fold_left(deque<int>)/1048576      277729 ns       277731 ns         2532
# | rng::fold_left(list<int>)/8               2.55 ns         2.55 ns    277025050
# | rng::fold_left(list<int>)/32              16.2 ns         16.2 ns     43058857
# | rng::fold_left(list<int>)/50              54.7 ns         54.7 ns     12705516
# | rng::fold_left(list<int>)/8192           15236 ns        15235 ns        56840
# | rng::fold_left(list<int>)/1048576      4827263 ns      4827147 ns          152
```
2026-02-05 21:12:36 +08:00
Nikolas Klauser
0bf41e3d7a
[libc++] Rewrite the std::make_heap benchmark (#178696)
This rewrites the `make_heap` benchmark to make it significantly faster
to run. In my test it saves ~10 minutes.

This patch also drops `ranges::` heap benchmarks, since we've decided to
remove `ranges::` benchmarks if there is a `std::` equivalent.
2026-02-05 11:46:11 +01:00
Nikolas Klauser
c9863ceacc
[libc++] Specialize allocator_traits for std::allocator (#160278)
This reduces the time to instantiate `allocator_traits<allocator<T>>`.
2026-02-05 11:43:47 +01:00
Alex Guteniev
39d60bbe5c
[lib++][test] Align atomic_ref underlying variable as required (#179780)
There is one pre-existing
`alignas(std::atomic_ref<T>::required_alignment)`:

1f8a3f2fdb/libcxx/test/std/atomics/atomics.ref/is_always_lock_free.pass.cpp (L54-L60)
This PR adds more of them.

On 32-bit Windows ABI just creating a variable on stack is not enough,
so 32-bit MSVC fails these tests before the fix.
2026-02-05 09:58:46 +01:00
Nikolas Klauser
ccb58432e3
[libc++] Use views::reverse to implement ranges::reverse_copy (#177123)
We currently have a custom utility `__reverse_range`, which does
basically the same thing as `views::reverse` and the only place where we
use it is in `ranges::reverse_copy`. Instead of this special utility, we
can simply use `views::reverse`.

This has originally been introduced due to compile time concerns.
However, there doesn't seem to actually be a significant compile time
regression overall.
2026-02-04 20:58:16 +01:00
Nikolas Klauser
279600ac9b
[libc++] Refactor formatter_int.bench.cpp to not use CartesianProduct (#179483)
The CartesianProduct machinery is incredibly expensive and makes it
trivial to add significant amounts of benchmarks which may not actually
serve much of a purpose. This patch doesn't remove any of the actual
benchmarks, but explicitly lists the benchmarks previous generated via
the CartesianProduct machinery. Still, the benchmarks run ~2x faster.

Fixes #178458
2026-02-04 17:10:52 +01:00
Connector Switch
a3f848057b
[libcxx] Modify std::__for_each{, _n} to accept r-values in __f (#179451)
This is necessary when optimizing algorithms for segmented iterators to
reduce boilerplate code.

related:
-
https://github.com/llvm/llvm-project/pull/177853#discussion_r2754820322
-
https://github.com/llvm/llvm-project/pull/164266#discussion_r2447129525
2026-02-04 23:15:21 +08:00
Nikolas Klauser
3a653afd45
[libc++] Simplify the implementation of __{un,re}wrap_range (#178381)
We can use a relatively simple `if constexpr` chain instead of SFINAE
and class template specialization, making the functions much simpler to
understand.
2026-02-04 10:31:31 +01:00
Nikolas Klauser
f537b4e518
[libc++] Avoid template instantiations in the duration aliases (#178182)
These templates are instantiated whenever `<__chrono/duration.h>` is
included, making these calculations quite costly. I also don't think
that folding the calculations decreases readability here (IMO it's
actually easier to read now), so I don't think there is a reason we
shouldn't do this.

`<__chrono/duration.h>` is currently (transitively) included in at least
(I stopped checking) `<algorithm>`, `<atomic>`, `<barrier>`, `<chrono>`,
`<condition_variable>`, `<future>`, `<iomanip>`, `<ios>`, `<iostream>`,
`<istream>`, `<latch>`, `<locale>`, `<mutex>`, `<ostream>`,
`<semaphore>`, `<shared_mutex>`, `<syncstream>` and `<thread>`
2026-02-04 10:26:48 +01:00
Johan Bengtsson
64fb57bf66
[libc++] Fix gdb pretty printer for strings (#176882)
The gdb pretty printer for strings reports an error when printing a
string that is small enough to fit inline in the string object. The
problem is that the lazy_string method can't be applied directly to an
array value. The fix is to cast the array to a pointer and apply
lazy_string to that value.
2026-02-03 14:09:46 +00:00
Nikolas Klauser
affcbce5ca
[libc++][NFC] Disable std_format_spec benchmarks through lit instead of the preprocessor (#179228)
This is probably a relic from when we didn't use lit to run benchmarks.
Nowadays we should just use the lit features to disable benchmarks like
we do in any other test instead of using the preprocessor.
2026-02-03 13:19:42 +01:00
Nikolas Klauser
c7cd15fcdd
[libc++] Refactor formatter_float.bench.cpp and drop some benchmarks (#178886)
`formatter_float.bench.cpp` currently benchmarks the floating point
formatting very extensively. This patch reduces the number of benchmarks
by removing some of the cases that are relatively meaningless.
The benchmark is also converted to the more recent style of benchmarks.
As a nice side-effect, this reduces the time it takes to compile the
benchmark by ~20x.

We may be able to drop more benchmarks, but I'm not an expert here and
am rather conservative here for that reason.
2026-02-03 11:14:50 +01:00
William Tran-Viet
7b6f1235b9
[libc++] Implement a type-safe iterator for optional (#154239)
Create a new `__capacity_aware_iterator` iterator type which wraps an
existing iterator, takes its container as a template parameter, and
encodes the maximum amount of elements the container can hold. The main
objective is to prevent iterator mixups between different containers
(e.g. `vector`).
2026-02-02 16:18:39 -05:00
Louis Dionne
9dfdb16613 [libc++] Don't fail LNT benchmark script when a benchmark fails
It's normal for some benchmarks to fail (e.g. fail to compile), and
that shouldn't cause the whole script to error out.
2026-02-02 14:31:22 -05:00
Louis Dionne
b560ef9eb7
[libc++] Fix naming of benchmarks with new SPEC metrics (#178445)
We need to ensure that no dots end up in those names to avoid confusing
LNT and the compare-benchmarks script.
2026-02-02 14:09:46 -05:00
A. Jiang
aa5428864e
[libc++] Short-cut constraints of single-argument any constructor (#177082)
When a default template argument of a function template uses
`std::is_copy_constructible<T>::value` and `T` is convertible from and
to `any`, the changes in 21dc73f6a46cd786394f10f5aef46ec4a2d26175 would
introduce constraint meta-recursion when compiling with Clang.

This patch short-cuts constraints of the related constructor to avoid
computing `is_copy_constructible<T>` when `decay_t<T>` is `any`, which
gets rid of constraint meta-recursion in the overload resolution of copy
construction of `T`.

Fixes #176877.
2026-02-02 17:48:55 +01:00
Walter Lee
09f8f22a64
[libc++] "Always" include_next for non C++ path in stdatomic.h (#178463)
In https://github.com/llvm/llvm-project/pull/176903, `#include
<__configuration/compiler.h>` is moved into the
`#ifdef _cplusplus` clause, so `_LIBCPP_COMPILER_CLANG_BASED` is no
longer set for C compiles. This causes a regression internally, where
when C compiles includes stdatomic.h, they no longer get the
corresponding C header.

C++ stdlib headers "shouldn't" be on the search patch for C compile, but
we do and so do lots of other people, so libc++ tends to support that.
This include_next for a C compile should be unconditional, not
conditional upon being Clang.
2026-01-30 10:01:51 -05:00
Nikolas Klauser
a03c35fad7
[libc++][NFC] Avoid checking that string::iterator is a contiguous iterator (#178636)
`__is_continuation` is only used in contexts where we already know that
the argument is a contiguous iterator. However, due to the context in
which it is used, we check it as soon as the header is included. The
`contiguous_iterator` check is quite expensive (~12ms on my system), so
avoiding it reduces compile times for quite a few headers, including
`<vector>`.
2026-01-30 14:29:12 +01:00
sohail
9bde15d76d
[libc++] Deprecate std::launch::any extension (#173397)
`std::launch::any` was a draft C++11 feature that was removed before the
final standard but it has remained in libc++ as an extension. This patch
marks it as deprecated and suggests using `std::launch::async |
std::launch::deferred` instead.

- Used `_LIBCPP_DEPRECATED_` to mark `std::launch::any` as deprecated
with an associated warning message recommending `std::launch::async |
std::launch::deferred` instead.
- Added a `.verify.cpp` test to validate the deprecation warning.
- Updated existing tests to avoid using the deprecated extension.
- Added note about deprecation in docs.

Fixes #173219

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-01-30 13:51:52 +08:00
A. Jiang
a1c81b028a
[libc++][test] Make EvilContainer a sequence container (#178626)
In tests for flat container adaptors, the `EvilContainer` type doesn't
have sufficient constructors to meet the requirements for sequence
containers ([sequence.reqmts]). Also, assignment from an
`initializer_list` doesn't have correct return type.

This patch makes `EvilContainer` inherit constructors from `vector<int>`
and add a correct assignment operator from `initializer_list<int>`.
2026-01-30 07:43:26 +08:00
Christopher Di Bella
3222670c68
[libc++] Fix __split_buffer_size_layout bugs (#178341)
As `__split_buffer` doesn't have any unit tests, and because #139632
disassociated adding `__split_buffer` support for both pointer-based and
size-based layouts from its `vector` counterpart, libc++ had no way to
expose `__split_buffer_size_layout` bugs until the size-based vector
patch integrated #139632. This commit fixes the two problems that were
identified while working on #155330.
2026-01-29 13:24:01 -05:00
Nikolas Klauser
224a6ffbc7
[libc++] Refactor swap_ranges to use __specialized_algorithm for the vector<bool>::iterator specialization (#173384) 2026-01-29 11:11:51 +01:00
Nikolas Klauser
ba0cddb43e
[libc++][NFC] Remove _LIBCPP_FREESTANDING (#176907)
`_LIBCPP_FREESTANDING` isn't used and it is unclear what libc++'s
strategy is going to be for implementing freestanding at the moment.
Therefore, remove the macro.
2026-01-29 10:13:32 +01:00
PiJoules
570d5e3318
[libc++] Don't define _LIBCPP_INSTRUMENTED_WITH_ASAN for hwasan builds (#178278)
This macro should not be defined if `LLVM_USE_SANITIZER` is `HWAddress`.
2026-01-28 15:28:21 -05:00
Louis Dionne
3327eea67f
[libc++] Reduce the number of warnings when running SPEC (#160366)
We don't care about warnings in the SPEC suite, so just use -w to turn
them off.
2026-01-28 13:51:32 -05:00
Nikolas Klauser
562c0b002c
[libc++] Use the fast path for move assignment in __tree if the allocator is_always_equal (#177115)
This avoids instantiating some code that we know is dead. This is also a
prerequisite for #134330, since we avoid trying to `const_cast` in the
common case now.
2026-01-28 10:52:18 -05:00
Nikolas Klauser
9bdaebbeae
[libc++] Remove a bunch of unused includes from <atomic> detail headers (#178161) 2026-01-27 22:00:15 +01:00
Nikolas Klauser
a2fb416b53
[libc++] Rewrite the std::lower_bound benchmark to be more efficient and add an upper_bound benchmark (#177180)
The current benchmark is incredibly slow to run. This patch refactors
the benchmark to be faster and also adds an equivalent benchmark for
`std::upper_bound`.

Fixes #177026
2026-01-27 13:46:36 -05:00
Michael G. Kazakov
4ccdd2ffac
[libc++][pstl] Generic implementation of parallel std::is_sorted (#176129)
This PR implements a generic backend-agnostic parallel `std::is_sorted`
based on `std::transform_reduce`.

While this approach is suboptimal comparing a direct backend-specific
implementation, since it doesn't support early termination and requires
a reduction operation, it does show speedup when the dataset is large
enough and the comparator is not absolutely trivial.

Parent issue: #99938
2026-01-27 13:43:23 -05:00
Louis Dionne
20014885c3
[libc++] Honor __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ in libc++ (#168955)
Address sanitizer recently got a new macro __SANITIZER_DISABLE_CONTAINER_OVERFLOW__
which is intended to disable container overflow checks in libraries (either the
standard library or user libraries that might provide such checks). This patch makes
libc++ honor that macro and, in addition, cleans up how these checks are enabled for
string (which is special) by introducing a macro just for string.

rdar://166234942
2026-01-27 16:04:03 +00:00