6346 Commits

Author SHA1 Message Date
Nikolas Klauser
46b4bd2882
[libc++] Implement _LIBCPP_SUPPRESS_DEPRECATED macros in terms of _LIBCPP_DIAGNOSTIC macros (#143857)
This makes the code a bit more consistent, since we use the
`_LIBCPP_DIAGNOSTIC` macros everywhere else.
2025-07-16 11:24:17 +02:00
Nikolas Klauser
50096134f8
[libc++][NFC] Remove some __tree internal accessor functions (#147266) 2025-07-16 10:33:21 +02:00
Nikolas Klauser
ffcb0a4559
[libc++] Update polymorphic_allocator to never contain a nullptr (#148423)
According to `[mem.poly.allocator.ctor]` the pointer contained in
`polymorphic_allocator` can never be null. The default constructor uses
`get_default_resource()`, which never returns null and the constructor
taking a pointer explicitly has a precondition that the pointer is
non-null.

This patch adds a warning and an assertion in case a user passes a null
pointer to `polymorphic_allocator` as well as marking `resource()` to
never return null.

This also fixes some tests which contained UB.

Fixes #148420
2025-07-16 10:03:57 +02:00
Nikolas Klauser
cee679aa3f
[libc++] Always initialize __tree::{,const_}iterator (#147167)
This was probably added to support https://wg21.link/n3644 but there's
no reason not to initialize the pointer in all standard modes. This is
technically an extension since n3644 only required value-initialized
iterators to be comparable, but supporting this as an extension should
be uncontroversial since it avoids potential reads of uninitialized
memory in C++03/C++11 without doing any harm.
2025-07-16 10:01:32 +02:00
Nikolas Klauser
db2eb4d031
[libc++] Simplify std::launder (#147985)
Both Clang and GCC diagnose invalid calls to `__builtin_launder`, which
causes duplicate diagnostics when using `std::launder` in an invalid
way. While the diagnostic message for the builtin isn't perferct, it's
definitely good enough to understand the problem and adding our own
diagnostic doesn't really make things any clearer. Because of that, this
patch simply removes the `static_assert`s and lets the compiler handle
diagnosing incorrect arguments instead. This not only simplifies our
implementation, but also improves compile times a bit, since we avoid
instantiating some type traits.
2025-07-16 09:42:09 +02:00
Nikolas Klauser
3b41e4d4b5
[libc++] Annotate barrier functions that are defined in the dylib (#148542)
This can improve code gen slightly.
2025-07-16 00:44:16 +02:00
Louis Dionne
d145f716ae
[libc++] Bump Xcode support (#148651)
Libc++'s policy is to support only the latest released Xcode, which is
Xcode 16.x. We did update our CI jobs to Xcode 16.x, but we forgot to
update the documentation, which still mentioned Xcode 15. This patch
updates the documentation and cleans up outdated mentions of
apple-clang-15 in the test suite.
2025-07-15 10:45:37 -04:00
Louis Dionne
6291b63a9a
[libc++] Ensure that we restore invariants in basic_filebuf::overflow (#147389)
In rare circumstances, the invariants could fail to be restored.
2025-07-15 10:40:54 -04:00
Tobias Hieta
01f36b39bd Bump version to 22.0.0-git 2025-07-15 16:03:12 +02:00
Nikolas Klauser
339a1f2e8f
Revert "[libc++][hardening] Introduce assertion semantics" (#148822)
Reverts llvm/llvm-project#148268

It looks like this was based on #148266, which I reverted in #148787.
2025-07-15 12:43:37 +02:00
Nikolas Klauser
fda3fbee6f
Revert "[libc++][hardening] Introduce a dylib function to log hardening errors." (#148787)
Reverts llvm/llvm-project#148266

I'm reverting this temporarily, since the release branch is today and
this is ABI sensitive. Let's wait until after the branch so that we have
plenty time to discuss the patch.
2025-07-15 12:12:41 +02:00
Nikolas Klauser
0c3a2faa85
[libc++] Simplify the implementation of __libcpp_{,de}allocate (#147989)
GCC 15 also supports `__buitin_operator_{new,delete}` now, so the
`#else` cases are dead code. This patch inlines the calls to the wrapper
functions and simplifies some surrounding code.
2025-07-15 11:43:55 +02:00
Konstantin Varlamov
7345508c6f
[libc++][hardening] Introduce assertion semantics (#148268)
Assertion semantics closely mimic C++26 Contracts evaluation semantics.
This brings our implementation closer in line with C++26 Library
Hardening (one particular benefit is that using the `observe` semantic
makes adopting hardening easier for projects).
2025-07-15 02:14:30 -07:00
Hristo Hristov
5fc844acd8
[libc++] P2944R3: Constrained comparisons - optional (#144249)
Partially implements [P2944R3](https://wg21.link/P2944R3) which adds
constrained comparisons to std::optional.

Closes #136767


# References
[optional.relops](https://wg21.link/optional.relops)
[optional.comp.with.t](https://wg21.link/optional.comp.with.t)

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-07-15 10:12:39 +02:00
Konstantin Varlamov
49d2b5f1cd
[libc++][hardening] Introduce a dylib function to log hardening errors. (#148266)
Unlike `verbose_abort`, this function merely logs the error but does not
terminate execution. It is intended to make it possible to implement the
`observe` semantic for Hardening.
2025-07-14 17:04:33 -07:00
Konstantin Varlamov
5951c44573
[libc++] Introduce the _LIBCPP_VERBOSE_TRAP macro (#148262)
Split out the calls to __builtin_verbose_trap into a separate header.
This is just a refactoring to make the code a bit more structured.
2025-07-14 09:56:19 -04:00
Nikolas Klauser
d3b339e36d
[libc++] Don't instantiate allocators in __hash_table on an incomplete type (#148353)
Currently, we try to instantiate the allocator on `__hash_value_type`,
which we don't define anymore. Instead, just use the
`map::allocator_type` to instantiate `__tree`, since that's what we
actually want anyways.
2025-07-13 08:59:07 +02:00
Nikolas Klauser
afcf76bda1
[libc++] Fix insert() calling incorrect constructors (#146231)
This fixes `insert()` calling the wrong `allocator_traits::construct` in
the associative containers by removing the special handling that lead to
the inconsistencty inside `__tree` and `__hash_table`.
2025-07-10 09:24:15 +02:00
Nikolas Klauser
9052977c35
[libc++] Implement the public invoke API in terms of the libc++-internal API (#146334)
This adds one additional variable template to the libc++-internal API.
This allows us to implement the public API once instead of twice.
2025-07-10 09:23:28 +02:00
Nikolas Klauser
30f8c64b1d
[libc++][NFC] Simplify std::__destroy_at a bit (#147025) 2025-07-10 09:22:54 +02:00
Nikolas Klauser
28f0935172
[libc++][NFC] Remove special handling for __hash_value_type in <__node_handle> (#147271)
We're not instantiating `__hash_value_type` anymore, so we don't need
any special handling of it here.
2025-07-10 09:21:46 +02:00
A. Jiang
8b171a08db
[libc++] Remove the packaged_task::result_type extension (#147671)
No escape hatch added, as there doesn't seem anyone critically relying
on this.
2025-07-10 15:04:49 +08:00
Hervé Poussineau
1431f8f76f
[libc++] Simplify definition of __libcpp_recursive_mutex_t (#147385)
As it only depends of pointer size, use `_WIN64` define to simplify conditions.
2025-07-09 12:53:08 -04:00
Nikolas Klauser
44d37695a5
[libc++] Optimize ctype::to{lower,upper} (#145344)
```
----------------------------------------------
Benchmark                       old        new
--------------------------- ------------------
BM_tolower_char<char>       1.64 ns    1.41 ns
BM_tolower_char<wchar_t>    1.64 ns    1.41 ns
BM_tolower_string<char>     32.4 ns    12.8 ns
BM_tolower_string<wchar_t>  32.9 ns    15.1 ns
BM_toupper_char<char>       1.63 ns    1.64 ns
BM_toupper_char<wchar_t>    1.63 ns    1.41 ns
BM_toupper_string<char>     32.2 ns    12.7 ns
BM_toupper_string<wchar_t>  33.0 ns    15.1 ns
```
2025-07-09 16:32:01 +02:00
Petr Hosek
9d3b60dea7
[libcxxabi][libunwind] Support for using LLVM libc (#134893)
This generalizes the support added in #99287 renaming the option to
RUNTIMES_USE_LIBC and integrating the module into libc++abi and
libunwind as well.
2025-07-09 00:48:50 -07:00
itrofimow
fcc09b6f02
[libc++] Fix std::make_exception_ptr interaction with ObjC (#135386)
Clang treats throwing/catching ObjC types differently from C++ types,
and omitting the `throw` in `std::make_exception_ptr` breaks ObjC
invariants about how types are thrown/caught.

Fixes #135089

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-07-08 11:34:42 -04:00
Hui
0d1e5ab2fd
[libc++] P2655R3 common_reference_t of reference_wrapper Should Be a Reference Type (#141408)
Fixes #105260

This patch applies the change as a DR to C++20. The rationale is that
the paper is more like a bug fix. It does not introduce new features, it
simply changes an existing behaviour (as a bug fix). MSVC STL DRed this
paper to C++20 as well.
2025-07-06 17:32:59 +01:00
Hui
13f7a1fb59
[libc++] LWG 3987 provide iterator.range access from flat_{map,set} (#137524)
fixes #105309
2025-07-06 12:25:18 +01:00
Hui
9eb4fc7006
[libc++] constexpr flat_set (#140360)
Fixes #128675
2025-07-05 17:38:45 +01:00
Nikolas Klauser
ca697096aa
[libc++] Granularize <locale> (#146650) 2025-07-05 18:11:58 +02:00
Nikolas Klauser
1121d64ba9
[libc++][NFC] Merge add_{r,l}value_reference.h (#147022)
The implementation is now quite simple, so it doesn't make a ton of
sense to have these in separate headers.
2025-07-05 18:11:36 +02:00
Nikolas Klauser
bdbac2bb49
[libc++] default some special members in map and set (#147081)
We don't actually do anything special in these special member functions,
so we can just `= default` them to save a bit of code.
2025-07-05 18:09:40 +02:00
Nikolas Klauser
22f8ceded4
[libc++] Add the thread safety annotations unconditionally (#117497)
For these annotations to do anything you need `-Wthread-safety`, in
which case users most likely enable them anyways. This avoids that users
have to explictly define a macro just to use the feature they already
had to opt-in to.
2025-07-05 18:07:07 +02:00
Nikolas Klauser
1f8e2a4b10
[libc++][NFC] Remove __remove_uncvref (#140531)
The use-case for `__is_same_uncvref` seems rather dubious, since not a
single use-cases needed the `remove_cvref_t` to be applied to both of
the arguments. Removing the alias makes it clearer what actually
happens, since we're not using an internal name anymore and it's clear
what the `remove_cvref_t` should apply to.
2025-07-04 11:16:47 +02:00
Hristo Hristov
a774463133
[libc++][NFC] Fixed some wrongly spelled _LIBCPP_STD_VER in comments (#147008) 2025-07-04 10:56:38 +02:00
xbcnn
3efa461d45
[libcxx] Avoid hash key in __hash_table::find() if it is empty. (#126837)
If the hash table is empty, with or without buckets, the find() can do
fast return. Then computing hash key is useless and avoidable, since it
could be expensive for some key types, such as long strings.

This is a small optimization but useful in cases like a checklist
(unordered_set/map) which is mostly empty.

```
For std::unordered_set<*>, `--benchmark_filter=find`
1. With the opt:

---------------------------------------------------------------------------------------------------------
Benchmark                                                               Time             CPU   Iterations
---------------------------------------------------------------------------------------------------------
std::unordered_set<int>::find(key) (existent)/0                     0.118 ns        0.118 ns   5939922720
std::unordered_set<int>::find(key) (existent)/32                     52.1 ns         52.1 ns     13287232
std::unordered_set<int>::find(key) (existent)/1024                   51.1 ns         51.1 ns     13449472
std::unordered_set<int>::find(key) (existent)/8192                   53.1 ns         53.1 ns     13420864
std::unordered_set<int>::find(key) (non-existent)/0                  14.7 ns         14.7 ns     47725472
std::unordered_set<int>::find(key) (non-existent)/32                 44.1 ns         44.1 ns     15478144
std::unordered_set<int>::find(key) (non-existent)/1024               41.2 ns         41.2 ns     15082464
std::unordered_set<int>::find(key) (non-existent)/8192               49.5 ns         49.5 ns     15233600
std::unordered_set<std::string>::find(key) (existent)/0             0.136 ns        0.136 ns   5157977920
std::unordered_set<std::string>::find(key) (existent)/32              739 ns          739 ns      1023744
std::unordered_set<std::string>::find(key) (existent)/1024            836 ns          836 ns       840448
std::unordered_set<std::string>::find(key) (existent)/8192            768 ns          768 ns      1085664
std::unordered_set<std::string>::find(key) (non-existent)/0          14.6 ns         14.6 ns     47844160
std::unordered_set<std::string>::find(key) (non-existent)/32          608 ns          608 ns      1106496
std::unordered_set<std::string>::find(key) (non-existent)/1024        646 ns          646 ns       986272
std::unordered_set<std::string>::find(key) (non-existent)/8192        669 ns          669 ns      1047584


2. Without the opt:

---------------------------------------------------------------------------------------------------------
Benchmark                                                               Time             CPU   Iterations
---------------------------------------------------------------------------------------------------------
std::unordered_set<int>::find(key) (existent)/0                     0.135 ns        0.135 ns   5188502304
std::unordered_set<int>::find(key) (existent)/32                     54.4 ns         54.4 ns     12954144
std::unordered_set<int>::find(key) (existent)/1024                   57.7 ns         57.7 ns     13107008
std::unordered_set<int>::find(key) (existent)/8192                   50.7 ns         50.7 ns     12953312
std::unordered_set<int>::find(key) (non-existent)/0                  16.1 ns         16.1 ns     43460192
std::unordered_set<int>::find(key) (non-existent)/32                 45.8 ns         45.8 ns     17139584
std::unordered_set<int>::find(key) (non-existent)/1024               44.6 ns         44.6 ns     16538048
std::unordered_set<int>::find(key) (non-existent)/8192               41.5 ns         41.5 ns     12850816
std::unordered_set<std::string>::find(key) (existent)/0             0.133 ns        0.133 ns   5214104992
std::unordered_set<std::string>::find(key) (existent)/32              731 ns          731 ns      1000576
std::unordered_set<std::string>::find(key) (existent)/1024            716 ns          716 ns      1131584
std::unordered_set<std::string>::find(key) (existent)/8192            745 ns          745 ns       909632
std::unordered_set<std::string>::find(key) (non-existent)/0           600 ns          600 ns      1089792
std::unordered_set<std::string>::find(key) (non-existent)/32          645 ns          645 ns       979232
std::unordered_set<std::string>::find(key) (non-existent)/1024        675 ns          675 ns       962240
std::unordered_set<std::string>::find(key) (non-existent)/8192        711 ns          711 ns      1054880

```

We can see the improvements when find() for non-existent
`std::string`(random size 1~1024) keys:
```
std::unordered_set<std::string>::find(key) (non-existent)/0          14.6 ns         14.6 ns     47844160
std::unordered_set<std::string>::find(key) (non-existent)/0           600 ns          600 ns      1089792
```

---------

Co-authored-by: yangxiaobing <yangxiaobing@jwzg.com>
2025-07-03 09:39:06 +02:00
Nikolas Klauser
ae9990ed96
[libc++] Remove dead code from <type_traits> (#143854)
Since we've upgraded to GCC 15 now, we can remove a bunch of dead code
from `<type_traits>`.
2025-07-02 21:49:04 +02:00
Nikolas Klauser
3ee0f97b95
[libc++] Avoid including vector in <functional> (#144310)
`vector` has been used in a very simple way in `boyer_moore_searcher`.
We can instead just use `unique_ptr<T[]>`, which is a lot simpler,
allowing us to drop the `vector` dependency while not losing any
expressiveness in the code. As a nice side effect, this also reduces the
time it takes to instantiate the `boyer_moore_searcher` constructor from
26ms to 22ms on my machine.
2025-07-02 21:48:30 +02:00
Nikolas Klauser
179cc202bd [libc++] Add missing _LIBCPP_NODEBUG in <__type_traits/invoke.h>
libc++ doesn't run clang-tidy in the bootstrapping build, so it wasn't
run when `__builtin_invoke` was introduced. Once libc++ upgrades to a
newer clang version, clang-tidy will start to fail due to missing
`_LIBCPP_NODEBUG` annotations.
2025-06-30 10:19:24 +02:00
Nikolas Klauser
e0864b56b0
[libc++] Fix <charconv> not exporting std::errc (#146268)
`<charconv>` doesn't properly export `std::errc` with locales disabled,
which causes the CI to fail. This fixed the modulemap to let
`from_chars_result` export `std::errc`, like it's supposed to do.
2025-06-30 10:06:34 +02:00
Nikolas Klauser
713839729c
[Clang] Add __builtin_invoke and use it in libc++ (#116709)
`std::invoke` is currently quite heavy compared to a function call,
since it involves quite heavy SFINAE. This can be done significantly
more efficient by the compiler, since most calls to `std::invoke` are
simple function calls and 6 out of the seven overloads for `std::invoke`
exist only to support member pointers. Even these boil down to a few
relatively simple checks.

Some real-world testing with this patch revealed some significant
results. For example, instantiating `std::format("Banane")` (and its
callees) went down from ~125ms on my system to ~104ms.
2025-06-29 17:52:50 +02:00
Hui
34b2e934ea
[libc++] Introduce __product_iterator_traits and optimise flat_map::insert (#139454)
Fixes #108624

This allows `flat_map::insert(Iter, Iter)` to directly forward to
underlying containers' `insert(Iter, Iter)`, instead of inserting one
element at a time, when input models "product iterator". atm,
`flat_map::iterator` and `zip_view::iterator` are "product iterator"s.

This gives about almost 10x speed up in my benchmark with -03 (for both
before and after)

```cpp
Benchmark                                                          Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------
flat_map::insert_product_iterator_flat_map/32                   -0.5028         -0.5320           149            74           149            70
flat_map::insert_product_iterator_flat_map/1024                 -0.8617         -0.8618          3113           430          3112           430
flat_map::insert_product_iterator_flat_map/8192                 -0.8877         -0.8877         26682          2995         26679          2995
flat_map::insert_product_iterator_flat_map/65536                -0.8769         -0.8769        226235         27844        226221         27841
flat_map::insert_product_iterator_zip/32                        -0.5844         -0.5844           162            67           162            67
flat_map::insert_product_iterator_zip/1024                      -0.8754         -0.8754          3427           427          3427           427
flat_map::insert_product_iterator_zip/8192                      -0.8934         -0.8934         28134          3000         28132          3000
flat_map::insert_product_iterator_zip/65536                     -0.8783         -0.8783        229783         27960        229767         27958
OVERALL_GEOMEAN                                                 -0.8319         -0.8332             0             0             0             0
```

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-06-28 13:42:50 +01:00
Hristo Hristov
a19d37044b
[libc++] P2944R3: Constrained comparisions - tuple (#145677)
Implements P2944R3 partially, which adds constrained comparisons
`std::tuple`.
The missing overloads introduced in [P2165R4](https://wg21.link/P2165R4)
are not implemented.

Uses
[`__all`](f7af33a9eb/libcxx/include/__type_traits/conjunction.h (L45))
instead of a fold expression, see comment:
https://github.com/llvm/llvm-project/pull/141396#discussion_r2161166077

Relates to #136765

# References

[tuple.rel](https://wg21.link//tuple.rel)
2025-06-27 20:12:18 +03:00
Nikolas Klauser
d163ab3323
[libc++] Remove a bunch of unnecessary type indirections from __tree (#145295)
Most of the diff is replacing `__parent_pointer` with
`__end_node_pointer`. The most interesting diff is that the pointer
aliases are now defined directly inside `__tree` instead of a separate
traits class.
2025-06-27 10:11:20 +02:00
Nikolas Klauser
4c8fab399b
[libc++] Avoid type-punning between __hash_value_type and pair (#143501)
This patch is very similar to #134819 in nature. Before this patch, we
were dereferencing pointers to objects which were never constructed. Now
we always assume that nodes store `pair<const KeyT, ValueT>` for
unordered_maps instead, as they actually do.
2025-06-26 19:43:59 +02:00
Nikolas Klauser
696c0f92e0
[libc++] Don't try to wait on a thread that hasn't started in std::async, take 2 (#130145)
If the creation of a thread fails, this causes an idle loop that will
never end because the thread wasn't started in the first place.

This also adds a test for the regression reported in #125433 to make
sure we're not reintroducing it later.

Fixes #125428
2025-06-26 12:13:19 +02:00
Hristo Hristov
f2f4b557aa
[libc++] P2944R3: Constrained comparisions - variant (#141396)
This is a follow-up and depends on #139368 being merged first.

Implements [P2944R3](https://wg21.link/P2944R3) partially, which adds
constrained comparisons to `std::variant`

Closes #136769

Depends on #139368

# References

[variant.relops](https://wg21.link/variant.relops)
2025-06-25 12:12:23 +03:00
Louis Dionne
52b27c2bd6
[libc++] Refactor basic_filebuf::overflow() (#144793)
Refactor the function to streamline the logic so it matches the
specification in [filebuf.virtuals] more closely. In particular, avoid
modifying the put area pointers when we loop around after a partial
codecvt conversion.

Note that we're technically not up-to-spec in this implementation, since
the Standard says that we shouldn't try more than once after a partial
codecvt conversion. However, this refactoring attempts not to change any
functionality.
2025-06-24 13:58:49 -04:00
Hui
0b8f3cc6b7
[libc++] Fix no-localisation CI failure on <complex> (#145213) 2025-06-24 13:56:17 -04:00
Peng Liu
d80766152c
[libc++] Fix bitset conversion functions and refactor constructor (#121348)
This patch addresses several implementation issues in `bitset`'s
conversion functions `to_ullong` and `to_ulong`, and refactors its
converting constructor `__bitset(unsigned long long __v)` to a more
generic and elegant implementation.
2025-06-24 12:38:10 -04:00