6320 Commits

Author SHA1 Message Date
Nikolas Klauser
e20413c045
[libc++][NFC] Refactor __do_rehash a bit (#151543)
This refactors `__hash_table::__do_rehash` to use early returns and
renames some of the variables.
2025-08-01 08:15:09 +02:00
Nikolas Klauser
3e2fadf3be
[libc++] Simplify the tuple constructors a bit (#150405) 2025-08-01 07:59:17 +02:00
Steffen Larsen
09cc8eaf1b
[libc++] Fix return type of ilogb(double) (#150374)
This commit addresses a seemingly unintentional return type of the ilogb
overload taking a double. Currently it returns double, while it is
supposed to return int.

The return types seems to be covered by libcxx/test/std/numerics/c.math/cmath.pass.cpp,
but the issue would only show up if we tested with a libc that doesn't
provide the ilogb(double) overload, which we don't.
2025-07-31 15:25:18 -04:00
Louis Dionne
955ece4fa5
[libc++] Add checks for misused hardening macros (#150669)
Libc++ hardening went through several iterations, sometimes within a
single release. However, some folks in the wild have picked up these
macros that were either public at some point or that were used
temporarily on `main`, and unfortunately those are now ignored.

This can lead to some users thinking they enable hardening when in
reality they don't, which is a pretty big deal. This patch simply checks
various old hardening-related macros and ensures that they are not set,
which will catch such misuse.
2025-07-31 15:17:56 -04:00
Konstantin Varlamov
4ef92469ab
[libc++][hardening] Add a greppable prefix to assertion messages. (#150560)
The current assertion failure messages produced by Hardening are not
very grep-friendly (the common part is rarther generic and requires
wildcards to match). While it's possible to use `__FILE__` for grepping,
it's easier and more straighforward to simply add a libc++-specific
prefix; this is especially important for the planned `observe` mode that
might produce many assertion failure messages over the course of the
program's execution that later need to be filtered and examined.
2025-07-31 02:52:17 -07:00
A. Jiang
a749e68ac4
[libc++][format][NFC] Granularize __fmt_pair_like (#150583)
`<optional>` needs `format_kind` and `range_format` since C++26, but it
shouldn't drag in too many other stuffs necessary for
`<__format/concepts.h>`.
2025-07-29 16:40:06 +08:00
Nikolas Klauser
9f00ab411a
[libc++] Add [[nodiscard]] to the vector accessor functions (#150615) 2025-07-29 10:30:37 +02:00
Konstantin Varlamov
3eee9fc2c4
[libc++][hardening] Introduce assertion semantics. (#149459)
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-29 00:19:15 -07:00
Nikolas Klauser
cdb67e1131
[libc++][NFC] Make __is_segmented_iterator a variable template (#149976) 2025-07-25 16:27:34 +02:00
Konstantin Varlamov
d750c6de8a
[libc++][hardening] Add an experimental function to log hardening errors (#149452)
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-24 13:39:48 -04:00
Nikolas Klauser
0f2c31dc92
[libc++][NFC] Remove __all_default_constructible (#150406)
`__all_default_constructible` is never used, so we can remove it.
2025-07-24 19:17:09 +02:00
Lazarev Alexei
77f0a7de3e
[libc++][regex] Throw exception in the case of wrong range (#148231)
Starting and ending parameters are considered to decide that a range is
a correct one

Fix #51028

Co-authored-by: alexey.lazarev <alexey.lazarev@tasking.com>
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-07-21 20:41:00 +08:00
Nikolas Klauser
6c257754d9
[libc++] Refactor internal index_sequence API to match the public one (#149475)
The internal API is a lot more complicated than it actually needs to be.
This refactors the internal API to match the features and names of the
public one.
2025-07-20 11:23:31 +02:00
Hui
d344c383e2
[libc++][ranges] implement std::ranges::zip_transform_view (#79605)
Fixes #104977
Fixes #105035

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
Co-authored-by: A. Jiang <de34@live.cn>
2025-07-20 09:13:59 +01:00
Hui
64220357b4
[libc++] constexpr flat_multimap (#148417)
Fixes #128674
2025-07-20 00:36:29 +08:00
Nikolas Klauser
b5348e7622
[libc++] Diagnose passing null pointers to a bunch of APIs (#148585) 2025-07-19 11:12:20 +02:00
Brad Smith
5f001294b1
Remove last few bits for Native Client support (#148983) 2025-07-18 11:26:36 -04:00
Louis Dionne
0e40695804
[libc++] Remove unused _LIBCPP_HAS_NO_STD_MODULES macro from __config_site (#148902)
Since 1d6b6132f, that macro isn't used anywhere anymore.
2025-07-18 11:06:27 -04:00
Michael Buch
8f4deff5d5
[libcxx][fstream][NFC] Make __failed helper lambda a member function (#149390)
This patch makes the `__failed` lambda a member function on `fstream`.
This fixes two LLDB expression evaluation test failures that got
introduced with https://github.com/llvm/llvm-project/pull/147389:
```
16:22:51  ********************
16:22:51  Unresolved Tests (2):
16:22:51    lldb-api :: commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
16:22:51    lldb-api :: commands/expression/import-std-module/list/TestListFromStdModule.py
```

The expression evaluator is asserting in the Clang parser:
```
Assertion failed: (capture_size() == Class->capture_size() && "Wrong number of captures"), function LambdaExpr, file ExprCXX.cpp, line 1277.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
```

Ideally we'd figure out why LLDB is falling over on this lambda. But to
unblock CI for now, make this a member function.

In the long run we should figure out the LLDB bug here so libc++ doesn't
need to care about whether it uses lambdas like this or not.
2025-07-17 23:50:39 +01:00
Nikolas Klauser
be3d614cc1
[libc++] Fix hash_multi{map,set}::insert (#149290) 2025-07-17 23:23:04 +02:00
Nikolas Klauser
4993f5b12c
[libc++][NFC] Use variable templates in <string> (#149038)
Variable templates are a bit lighter on the compiler than class
templates.
2025-07-17 11:11:30 +02:00
William Tran-Viet
2194bca2b7
[libc++] Granularize range_format and format_kind declarations (#148876)
While working on #105430 I ran into an issue implementing
[[optional.syn]](https://eel.is/c++draft/optional.syn) because of a
circular include that looked like the following: `optional ->
__format/range_default_formatter.h -> __format/range_formatter.h ->
__format/format_context.h -> optional`. Only `format_kind` and
`range_format` are needed, and so they looked like candidates to be put
into an internal header.
2025-07-17 09:43:12 +02:00
Nikolas Klauser
b8b99d83a6
[libc++] Simplify __hash_table further (#148375) 2025-07-16 17:13:08 +02:00
enh-google
62bd778fd4
Remove workarounds for NDK versions before 2017's r16. (#148879) 2025-07-16 07:39:17 -04:00
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