Commit graph

13506 commits

Author SHA1 Message Date
Nikolas Klauser
0d97f43974
[libc++] Inline vector::__append into resize (#162086)
These functions are only used in a single place, so there is not much
reason to keep them around.
2025-11-10 20:02:54 +01:00
Louis Dionne
d2521f14a7
[libc++] Split macros related to hardening into their own header (#167069)
Hardening macros are easy to extract into their own header, and doing so
decreases the complexity of the main __config file.
2025-11-10 12:57:41 -05:00
Louis Dionne
911d1c2a24
[libc++][NFC] Remove unused imports from generate_feature_test_macro_components.py (#159591) 2025-11-10 12:56:43 -05:00
A. Jiang
8c52f33a97
[libc++][docs] Update to refer to P3355R2 (#167267)
Per https://github.com/cplusplus/draft/pull/7505, LWG approved P3355R2
and the differences between P3355R1 is subsequently applied. So it seems
better to refer to P3355R2.
2025-11-10 12:17:23 -05:00
A. Jiang
1ffe79d092
[libc++] Avoid overloaded operator, for (T, Iter) cases (#161049)
Several components in libc++ aren't defending against overloaded
`operator,(T, Iter)` currently. Existing deleted overloads in
`test_iterators.h` are insufficient for such cases.

This PR adds corresponding deleted overloads with reversed order and
fixes these libc++ components.
- `piecewise_linear_distribution`'s iterator pair constructor,
- `piecewise_linear_distribution::param_type`'s iterator pair
constructor,
- `piecewise_constant_distribution`'s iterator pair constructor,
- `piecewise_constant_distribution::param_type`'s iterator pair
constructor,
- `money_get::do_get`,
- `money_put::do_put`, and
- `num_put::do_put`.
2025-11-10 20:04:50 +08:00
Nikolas Klauser
0b52b82955
[libc++] Merge insert/emplace(const_iterator, Args...) implementations (#166470) 2025-11-10 11:00:59 +01:00
Nikolas Klauser
471dbb90cb
[libc++] Replace __libcpp_is_final with a variable template (#167137) 2025-11-10 11:00:05 +01:00
Nikolas Klauser
152bda7269
[libc++] Replace the last uses of __tuple_types with __type_list (#167214)
`__tuple_types` is at this point just a `__type_list` with a weird name,
so we can just replace the few places it's still used.
2025-11-10 10:09:14 +01:00
Hristo Hristov
3a8894d7af
[libc++][numeric] Marked saturation artithmetic functions as [[nodiscard]] (#166898)
...according to Coding Guidelines: *`[[nodiscard]]` should be applied to
functions where discarding the return value is most likely a correctness
issue.*

# References
-
https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
-
https://github.com/llvm/llvm-project/pull/166524#issuecomment-3495567876

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-11-09 05:39:36 +02:00
A. Jiang
3bb903e3c0
[libc++] Treat P0513R0 as a defect report against C++11 (#166690)
P0513R0 is essentially a collective resolution paper of LWG2543,
LWG2791, LWG2809, and LWG2817.

Among these LWG issues, LWG2543 (conditionally enabled `hash`) and
LWG2817 (`hash<nullptr_t>`) affect pre-C++17 utilities. We generally
backport changes from LWG issues, so this patch backports the relevant
parts of P0513R0.

Although we provide `hash<unique_ptr>` as an extension in C++03 mode, as
C++03 mode isn't encouraged now, this patch leaves `hash<unique_ptr>`
unchanged in C++03 mode.
2025-11-09 08:40:39 +08:00
Louis Dionne
825943e06f
[libc++] Run macOS buildbot under xcrun (#167072)
This ensures that run-buildbot can find the appropriate build tools
without having to go through a bunch of hoops inside run-buildbot
itself. When we eventually run the bootstrapping build on macOS, it also
allows the bootstrapped Clang to find the SDK headers it requires.

This also allows simplifying run-buildbot a bunch since we should be
able to find build tools in the current $PATH.
2025-11-08 09:27:05 -10:00
A. Jiang
f090dd15a1
[libc++][test] Fix-up tests for is_clock(_v) (#166888)
This fixes incompleteness and inconsistency for test files added in
adc7932461, by
- renaming
`libcxx/test/std/time/time.traits.is.clock/trait.is.clock.compile.pass.cpp`
to `libcxx/test/std/time/time.traits/is.clock.compile.pass.cpp`,
- renaming
`libcxx/test/libcxx/time/time.traits.is.clock/trait.is.clock.compile.verify.cpp`
to `libcxx/test/libcxx/time/time.traits/is.clock.verify.cpp` , and
- adding comments clarifying what are being tested.
2025-11-08 00:45:22 +08:00
Nikolas Klauser
9b114c5d9a
[libc++] Optimize fstream::read (#165223)
```
Benchmark         old       new    Difference    % Difference
-----------  --------  --------  ------------  --------------
bm_read       2468.45    736.27      -1732.18         -70.17%
```
2025-11-07 10:31:31 +00:00
Nikolas Klauser
fc5e0c071b
[libc++] Simplify most of the segmented iterator optimizations (#164797)
This patch does two things.
(1) It replaces SFINAE with `if constexpr`, avoiding some overload
resolution and unnecessary boilerplate.
(2) It removes an overload from `__for_each_n` to forward to
`__for_each`, since `__for_each` doesn't provide any further
optimizations.
2025-11-07 08:27:55 +01:00
Yuxuan Chen
adc7932461
[libcxx] Implement C++20 std::chrono::is_clock, std::chrono::is_clock_v (#160607)
Implemented
[[*time.traits.is.clock*]](https://eel.is/c++draft/time.traits.is.clock)
from [P0355R7](https://wg21.link/p0355r7).

This patch implements the C++20 feature `is_clock` and `is_clock_v`
based on the documentation [on
cppreference](https://en.cppreference.com/w/cpp/chrono/is_clock.html)

Fixes #166049.
2025-11-06 12:33:44 -08:00
Mark Danial
3361e40c32
[AIX] Enable libc++ bots on AIX (#166650)
Removing skip after confirming builds pass locally. Upgraded workers to
clang 20

Fixes #162516
2025-11-05 23:05:32 -05:00
Nikolas Klauser
5b5d0a8319
[libc++][NFC] Make __type_info_implementations a namespace (#166339)
There doesn't seem much of a reason why this should be a struct. Make it
a namespace instead.
2025-11-05 10:00:47 +01:00
Nikolas Klauser
988c1b1c8d
[libc++] Remove <cstdlib> include from <exception> (#166340) 2025-11-05 09:42:35 +01:00
Hristo Hristov
a2977dea61
[libc++][NFC] Removed unsupported compilers from tests (#166403) 2025-11-05 11:12:17 +08:00
A. Jiang
4cdeb7d292
[libc++] Remove guards for builtins for reference binding traits (#166288)
We're only supporting Clang 20+ and Apple Clang 17 now, where these
builtins are universally implemented.
2025-11-05 07:24:59 +08:00
Nikolas Klauser
d4222bf9e2
[libc++] Use saturation builtins directly for {add,sub}_sat (#165228)
This doesn't improve performance (except with optimizations disabled),
since the compiler is able to fold our current implementation. However,
it does significantly reduce the amount of code the compiler has to sift
through, reducing compile times a bit.
2025-11-04 23:29:13 +01:00
Adrian Vogelsgesang
f02b661054
[libc++] Add move constructor & assignment to exception_ptr (#164281)
This commit adds move constructor, move assignment and `swap`
to `exception_ptr`. Adding those operators allows us to avoid
unnecessary calls to `__cxa_{inc,dec}rement_refcount`.

Performance results (from libc++'s CI):

```
Benchmark                               Baseline    Candidate    Difference    % Difference
------------------------------------  ----------  -----------  ------------  --------------
bm_exception_ptr_copy_assign_nonnull        9.77         9.94          0.18           1.79%
bm_exception_ptr_copy_assign_null          10.29        10.65          0.35           3.42%
bm_exception_ptr_copy_ctor_nonnull          7.02         7.01         -0.01          -0.13%
bm_exception_ptr_copy_ctor_null            10.54        10.60          0.06           0.56%
bm_exception_ptr_move_assign_nonnull       16.92        13.76         -3.16         -18.70%
bm_exception_ptr_move_assign_null          10.61        10.76          0.14           1.36%
bm_exception_ptr_move_ctor_nonnull         13.31        10.25         -3.06         -23.02%
bm_exception_ptr_move_ctor_null            10.28         7.30         -2.98         -28.95%
bm_exception_ptr_swap_nonnull              19.22         0.63        -18.59         -96.74%
bm_exception_ptr_swap_null                 20.02         7.79        -12.23         -61.07%
```

As expected, the `bm_exception_ptr_copy_*` benchmarks are not influenced by
this change. `bm_exception_ptr_move_*` benefits between 18% and 30%. The
`bm_exception_ptr_swap_*` tests show the biggest improvements since multiple
calls to the copy constructor are replaced by a simple pointer swap.

While `bm_exception_ptr_move_assign_null` did not show a regression in the CI
measurements, local measurements showed a regression from 3.98 to 4.71, i.e. by
18%. This is due to the additional `__tmp` inside `operator=`. The destructor
of `__other` is a no-op after the move because `__other.__ptr` will be a
nullptr. However, the compiler does not realize this, since the destructor is
not inlined and is lacking a fast-path. As such, the swap-based implementation
leads to an additional destructor call. `bm_exception_ptr_move_assign_nonnull`
still benefits because the swap-based move constructor avoids unnecessary
__cxa_{in,de}crement_refcount calls. As soon as we inline the destructor, this
regression should disappear again.

Works towards #44892
2025-11-03 21:18:43 +01:00
Adrian Vogelsgesang
dccced25a0
[libc++][docs] Fix documentation of REQUIRES: std-at-least-* (#166226)
Due to me not double-checking my PR, an overly eager AI auto-completion
made it into my previous PR :/
2025-11-03 21:13:27 +01:00
Adrian Vogelsgesang
d4ca474ca3
[libc++][docs] Fix documentation of REQUIRES: std-at-least-* (#166221) 2025-11-03 21:03:43 +01:00
Aiden Grossman
d200df0557
[libcxx] Remove Redundant Reset in ~basic_string (#164718)
8dae17be29 refactors basic_string for more
code reuse. This makes sense in most cases, but has performance overhead
in the case of ~basic_string. The refactoring of ~basic_string to call
__reset_internal_buffer() added a redundant (inside the destructor)
reset of the object, which the optimizer is unable to optimize away in
many cases. This patch prevents a ~1% regression we observed on an
internal workload when applying the original refactoring. This does
slightly pessimize the code readability, but I think this change is
worth it given the performance impact.

I'm hoping to add a benchmark(s) to the upstream libc++ benchmark suite
around string construction/destruction to ensure that this case does not
regress as it seems common in real world applications. I will put up a
separate PR for that when I figure out a reasonable way to write it.
2025-11-03 11:04:22 -08:00
Nikolas Klauser
28d3194d11
[libc++] Merge basic_string::__{replace,reset}_internal_buffer (#165404) 2025-11-03 16:47:12 +01:00
Nikolas Klauser
0569cc141b
[libc++] Simplify the implementation of __formatter::__fill a bit (#147777)
This replaces some SFINAE with `if constexpr`.
2025-11-03 10:41:55 +01:00
A. Jiang
bfcd67c347
[libc++][docs] Update status for P2641R4 (#166073)
Follows-up 2527b071ba which missed
updating the status in the documentations.
2025-11-03 11:59:10 +08:00
Matt
d7e44dc6a2
[libcxx][modules] Fix missing includes for windows (#158781)
Previously, I was getting the following error when attempting to compile
libc++ on windows with modules enabled.

```
While building module 'std':
In file included from <module-includes>:1:
In file included from gen/third_party/libc++/src/include/algorithm:1865:
In file included from gen/third_party/libc++/src/include/__algorithm/inplace_merge.h:28:
In file included from gen/third_party/libc++/src/include/__memory/unique_temporary_buffer.h:17:
In file included from gen/third_party/libc++/src/include/__memory/allocator.h:19:
gen/third_party/libc++/src/include/__new/allocate.h(40,73): error: 
      declaration of 'align_val_t' must be imported from module
      'sys_stage1.sysroot_vcruntime_new_h' before it is required
   40 |     return static_cast<_Tp*>(__builtin_operator_new(__size, static_cast<align_val...
      |                                                                         ^
../../third_party/depot_tools/win_toolchain/vs_files/e4305f407e/VC/Tools/MSVC/14.44.35207/include/vcruntime_new.h(27,33): note: 
      declaration here is not visible
   27 |     _VCRT_EXPORT_STD enum class align_val_t : size_t {};
      |                                 ^
```
2025-11-03 13:49:31 +11:00
Louis Dionne
3252e11da3
[libc++] Add availability markup for LLVM 19 and LLVM 20 (#140072)
An LLVM 19-aligned libc++ was released with macOS 15.4 (and corresponding OSes),
and LLVM-20 aligned with macOS 26.0. This patch adds availability markup to
reflect that.
2025-11-02 15:24:30 -10:00
Nikolas Klauser
2527b071ba
[libc++] P2641R4: Checking if a union alternative is active (std::is_within_lifetime) (#165243)
<https://wg21.link/P2641R4>

Implements the C++26 function in `<type_traits>` [meta.const.eval] (and
the corresponding feature test macro `__cpp_lib_is_within_lifetime`)

```c++
template<class T>
  consteval bool is_within_lifetime(const T*) noexcept;
```

This is done with the `__builtin_is_within_lifetime` builtin added to
Clang 20 by #91895 / 2a07509c8d. This is
not (currently) available with GCC.

This implementation has provisions for LWG4138
<https://cplusplus.github.io/LWG/issue4138> where it is ill-formed to
instantiate `is_within_lifetime<T>` with a function type `T`.

Closes #105381

Co-authored-by: Mital Ashok <mital@mitalashok.co.uk>
2025-11-02 10:30:31 +01:00
Nikolas Klauser
f46ac9234f
[libc++] Remove a few unused includes (#165687) 2025-11-02 10:27:56 +01:00
Nikolas Klauser
46c54bb909
[libc++] Add [[clang::lifetimebound]] to std::identity (#165854) 2025-11-02 10:27:09 +01:00
Hui
c07440b887
[libc++] constexpr flat_multiset (#161016)
Fixes https://github.com/llvm/llvm-project/issues/128676
2025-11-01 08:51:35 +00:00
Nikolas Klauser
9f9b8d56f4
[libc++] Simplify the implementation of destroy_at a bit (#165392) 2025-10-31 12:56:37 +01:00
Nikolas Klauser
d1146b1ddd
[libc++] Update our documentation on the supported compilers (#165684) 2025-10-31 12:16:24 +01:00
A. Jiang
73b092ff33
[libc++][test] Make deallocate_size.pass.cpp MSVC-friendly (#165162)
This patch contains several changes to `deallocate_size.pass.cpp`:
1. `static_cast`-ing some parameters to `size_t` to avoid narrowing.
2. Changing the type of loop variable `i` to `unsigned int` avoid
signedness mismatch with the constructor parameter.
3. Separately counting allocations and deallocations in variables
`allocated_` and `deallocated_`, and changing their type to `uint64_t`.
4. Avoiding `assert`-ing count of allocations when a `basic_string` is
allocated, just `assert`-ing after destruction instead.
2025-10-31 10:07:38 +08:00
Louis Dionne
a98295dbcf
[libc++] Fix localization failures on macOS 15.4 (#138744)
This patch reverts e15025dd and 88e15b781 which were temporary measures
until we had figured out the underlying issues. It turns out that recent
OSes updated localization data, removing the need for several Apple-specific
workarounds in the tests.

Fixes #135385
2025-10-30 08:50:33 -07:00
Nikolas Klauser
bb1158f14a
[libc++] Fix LLVM 22 TODOs (#153367)
We've upgraded to LLVM 22 now, so we can remove a bunch of TODOs.
2025-10-30 10:34:41 +01:00
Alex Rønne Petersen
e9389436e5
[libc++] Fix locale-related compilation errors on NetBSD (#143055)
To my knowledge, NetBSD is mostly like other BSDs, but doesn't have
`xlocale.h`. I think c664a7f may have inadvertently broken this.

With this change, I was able to run
[zig-bootstrap](https://github.com/ziglang/zig-bootstrap) to completion
for `x86_64-netbsd10.1-none`.
2025-10-29 21:30:54 +01:00
Connector Switch
0621fd0b88
[libcxx] Optimize rng::generate_n for segmented iterators (#165280)
Part of #102817.

This patch optimizes `rng::generate_n` for segmented iterators by
forwarding the implementation directly to `std::generate_n`.

- before

```
rng::generate_n(deque<int>)/32          21.7 ns         22.0 ns     32000000
rng::generate_n(deque<int>)/50          30.8 ns         30.7 ns     22400000
rng::generate_n(deque<int>)/1024         492 ns          488 ns      1120000
rng::generate_n(deque<int>)/8192        3938 ns         3924 ns       179200
```

- after

```
rng::generate_n(deque<int>)/32          11.0 ns         11.0 ns     64000000
rng::generate_n(deque<int>)/50          16.2 ns         16.1 ns     40727273
rng::generate_n(deque<int>)/1024         292 ns          286 ns      2240000
rng::generate_n(deque<int>)/8192        2291 ns         2302 ns       298667
```
2025-10-28 22:22:26 +08:00
Nikolas Klauser
fc1f3f397e
Revert "[libcxx] Define _LIBCPP_HAS_C8RTOMB_MBRTOC8 to true if compiling with clang" (#165268)
Reverts llvm/llvm-project#152724

The PR was merged with broken pre-commit CI.
2025-10-27 17:08:44 +01:00
Adrian Vogelsgesang
75737ca398
[libc++] Add benchmark for std::exception_ptr (#164278)
This commit adds benchmarks for `std::exception_ptr` to set a baseline
in preparation for follow-up optimizations.
2025-10-27 15:32:12 +01:00
Nikolas Klauser
4732ab5083
[libc++] Enable Clang modules in most of the CI runs (#160251)
Enabling modules makes the CI quite a bit faster with basically no
downsides. The non-modules build is still tested through the
`generic-cxxab` configurations, but most of the other CI runs on
platforms with modules support now use modules.
2025-10-26 17:07:28 +01:00
Victor Campos
d522b1b300
[libcxx] Define _LIBCPP_HAS_C8RTOMB_MBRTOC8 to true if compiling with clang (#152724)
Define `_LIBCPP_HAS_C8RTOMB_MBRTOC8` to `1` if compiling with clang.

Some tests involving functionality from `uchar.h`/`cuchar` fail when the
platform or the supporting C library does not provide support for the
corresponding features. These have been xfailed.

This patch will enable the adoption of newer picolibc versions.
2025-10-24 09:36:31 +01:00
Nikolas Klauser
44331d2594
[libc++][C++03] Remove some of the C++03-specific C wrapper headers (#163772)
`include_next` doesn't work very well with the C++03 headers and
modules. Since these specific headers are very self-contained there
isn't much of a reason to split them into C++03/non-C++03 headers, so
let's just remove them. The few C wrapper headers that aren't as
self-contained will be refactored in a separate patch.
2025-10-24 10:08:21 +02:00
A. Jiang
45f97f71af
[libc++][docs] Add missing column headers for GitHub issues (#164745)
We started to list GitHub issues in the status CSV tables/pages due to
e0d0b90d52. However, the changes made
existing column header insufficient. We probably need to add new column
headers for GitHub issues.
2025-10-23 22:32:21 +08:00
Nikolas Klauser
5f0f7580aa
[libc++] Simplify std::strong_order (#164233)
This patch does two things:
1) The branches for `sizeof(_Dp) == sizeof(int32_t)` and `sizeof(_Dp) ==
sizeof(int64_t)` are merged, since these are basically identical.
2) The branch where `numeric_limits<_Dp>::radix != 2` is removed, since
no platform we support (nor any I'm aware of) have a floating point type
with `radix != 2`. This means that the branch is basically dead code.
2025-10-23 09:47:09 +08:00
Nikolas Klauser
a516cc0bad
[libc++][C++03] Fix alg.count/count.pass.cpp (#163751) 2025-10-22 18:22:43 +02:00
Nikolas Klauser
a4ff6d9cf8
[libc++][C++03] Introduce LIBCPP_{,NON_}FROZEN_ASSERT (#163380)
There are a few cases where test only fail with the C++03 frozen headers
because some implementation details are asserted. This patch introduces
new assertion macros to differentiate between frozen and non-frozen
headers.
2025-10-22 18:22:09 +02:00