13200 Commits

Author SHA1 Message Date
A. Jiang
4a509f853f
[libc++] Implement comparison operators for tuple added in C++23 (#148799)
And constrain the new `operator==` since C++26.

This patch implements parts of P2165R4, P2944R3, and a possibly improved
resolution of LWG3882. Currently, libstdc++ and MSVC STL constrain the
new overloads in the same way.

Also set feature-test macro `__cpp_lib_constrained_equality` and add
related release note, as P2944R3 will completed with this patch.

Fixes #136765
Fixes #136770
Fixes #105424
2025-08-01 11:53:33 -04:00
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
Victor Campos
16d5db71b3 Revert "[libc++][Clang] Added explanation why is_constructible evaluated to false. Updated the diagnostics checks in libc++ tests. (#144220)"
This reverts commit e476f968bc8e438a0435d10934f148de570db8eb.

It has introduced a failure tracked by https://github.com/llvm/llvm-project/issues/150601

One libcxx test fail if libcxx is build with no exceptions and no RTTI:
 - libcxx/utilities/expected/expected.expected/value.observers.verify.cpp
2025-07-30 11:05:23 +01: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
Aiden Grossman
b33f9f64c7
[libcxx] Enable installing new runner binary on existing container
This patch does some refactoring to enable installing a new GHA runner binary
into an existing libcxx image. We achieve this by pushing the base image to the
registry and enabling control over the base image used for building the actions
image. This will always build and push both images even if an existing image is
being used for the actions image, but this should not impact anything as the
SHAs are pinned everywhere and space/build time is not a large concern.

Reviewers: ldionne, EricWF, #reviewers-libcxx

Reviewed By: ldionne

Pull Request: https://github.com/llvm/llvm-project/pull/148073
2025-07-28 12:35:40 -07:00
Aiden Grossman
6107e3aa22
[libcxx] Install runner last when building CI containers
This patch changes when we install the GHA runner in the CI containers. Instead
of having it in the base image, we install it last. This will enable a follow up
patch that will do some setup enabling building the full container image with an
existing base image, thus enabling updating the GHA runner without modifying the
important bits.

Reviewers: EricWF, ldionne

Reviewed By: ldionne

Pull Request: https://github.com/llvm/llvm-project/pull/148072
2025-07-28 12:32:24 -07:00
Louis Dionne
1d0aa5f6b2
[libc++] Add missing CPO tests for range adaptors (#149557)
Co-authored-by: A. Jiang <de34@live.cn>
2025-07-25 13:29:48 -04:00
Nikolas Klauser
cdb67e1131
[libc++][NFC] Make __is_segmented_iterator a variable template (#149976) 2025-07-25 16:27:34 +02:00
Nikolas Klauser
272da50139
[libc++] Move a bunch of tests from libcxx/test/libcxx to libcxx/test/std (#150199)
These tests test standard behaviour, so they shouldn't be in the
libc++-specific tests.
2025-07-25 10:46:29 +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
Hristo Hristov
03a170837e
[libc++] Enable some tests on android (#149899)
Android compiler was updated to r563880:
https://github.com/llvm/llvm-project/pull/148998
2025-07-22 09:02:49 +03:00
Louis Dionne
f85c1a5615
[libc++] Remove mentions of Clang 18 in the test suite (#148862)
Clang 19 has been the oldest supported version of Clang since the LLVM
20 release, but we had not cleaned up the test suite yet.
2025-07-21 12:45:32 -04:00
Louis Dionne
1a0dd5a67e
[libc++] Avoid duplicate LWGXYZ prefixes in status tables (#148874)
When synchronizing the status tables with Github issues, we use the
title of the Github issue as the name of the paper in the status table.
However, the Github issue titles are prefixed with PXYZ or LWGXYZ (which
is useful to quickly find papers), and that is redundant in the context
of status tables. This patch ensures that we don't add that redundant
PXYZ or LWGXYZ prefix.

As a drive-by, also specify the encoding for opening files explicitly,
which fixes issues on Windows.
2025-07-21 10:02:54 -04: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
Louis Dionne
167c695cec
[libc++] Add and empty skeleton for LLVM 22 release notes (#149535) 2025-07-19 14:32:54 +01:00
Nikolas Klauser
b5348e7622
[libc++] Diagnose passing null pointers to a bunch of APIs (#148585) 2025-07-19 11:12:20 +02:00
Nikolas Klauser
6b371cab94
[libc++] Move a bunch of extensions tests to test/extensions (#149275) 2025-07-19 09:44:25 +02:00
YexuanXiao
7c402b8b81
Reland [Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar types (#149613)
The checks for the 'z' and 't' format specifiers added in the original
PR #143653 had some issues and were overly strict, causing some build
failures and were consequently reverted at
4c85bf2fe8.

In the latest commit
27c58629ec,
I relaxed the checks for the 'z' and 't' format specifiers, so warnings
are now only issued when they are used with mismatched types.

The original intent of these checks was to diagnose code that assumes
the underlying type of `size_t` is `unsigned` or `unsigned long`, for
example:

```c
printf("%zu", 1ul); // Not portable, but not an error when size_t is unsigned long
```  

However, it produced a significant number of false positives. This was
partly because Clang does not treat the `typedef` `size_t` and
`__size_t` as having a common "sugar" type, and partly because a large
amount of existing code either assumes `unsigned` (or `unsigned long`)
is `size_t`, or they define the equivalent of size_t in their own way
(such as
sanitizer_internal_defs.h).2e67dcfdcd/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h (L203)
2025-07-19 03:44:14 -03:00
Louis Dionne
d737fe2c91
[libc++][NFC] Fix typos in the libc++ 21 release notes (#149536) 2025-07-18 11:54:27 -04: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
Paul Kirth
fd12e9aed8
[libc++][tests] Update XFAIL annotations for some tests on Windows (#149124)
These tests still fail on Windows with clang-22, as reported in #70225.
This started failing due to the version bump to Clang 22.
2025-07-18 11:03:19 -04:00
Kazu Hirata
4c85bf2fe8 Revert "[Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar types instead of built-in types (#143653)"
This reverts commit c27e283cfbca2bd22f34592430e98ee76ed60ad8.

A builbot failure has been reported:
https://lab.llvm.org/buildbot/#/builders/186/builds/10819/steps/10/logs/stdio

I'm also getting a large number of warnings related to %zu and %zx.
2025-07-17 21:04:01 -07:00
YexuanXiao
c27e283cfb
[Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar types instead of built-in types (#143653)
Including the results of `sizeof`, `sizeof...`, `__datasizeof`,
`__alignof`, `_Alignof`, `alignof`, `_Countof`, `size_t` literals, and
signed `size_t` literals, the results of pointer-pointer subtraction and
checks for standard library functions (and their calls).

The goal is to enable clang and downstream tools such as clangd and
clang-tidy to provide more portable hints and diagnostics.

The previous discussion can be found at #136542.

This PR implements this feature by introducing a new subtype of `Type`
called `PredefinedSugarType`, which was considered appropriate in
discussions. I tried to keep `PredefinedSugarType` simple enough yet not
limited to `size_t` and `ptrdiff_t` so that it can be used for other
purposes. `PredefinedSugarType` wraps a canonical `Type` and provides a
name, conceptually similar to a compiler internal `TypedefType` but
without depending on a `TypedefDecl` or a source file.

Additionally, checks for the `z` and `t` format specifiers in format
strings for `scanf` and `printf` were added. It will precisely match
expressions using `typedef`s or built-in expressions.

The affected tests indicates that it works very well.

Several code require that `SizeType` is canonical, so I kept `SizeType`
to its canonical form.

The failed tests in CI are allowed to fail. See the
[comment](https://github.com/llvm/llvm-project/pull/135386#issuecomment-3049426611)
in another PR #135386.
2025-07-17 22:45:57 -03:00
Ryan Prichard
8aa4fc0a9f
[libc++][Android] Reenable 2 tests for Android (#149415)
Now that the Android clang has been upgraded to clang-r563880
(llvm.org/pr148998), these two tests pass again.
2025-07-17 18:08:52 -07: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
4695aea28e
[libc++] Move more tests into better places (#148419) 2025-07-17 11:12:01 +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
Nikolas Klauser
3dc5d687b0
[libc++] Remove minimal_cxx11_configuration.pass.cpp (#149119)
This test doesn't seem to be very useful. If it is the only test that
fails we would just remove the failing parts of the test, and otherwise
it doesn't provide any value either, since there will be another test
that fails.
2025-07-17 10:55:29 +02:00
Jonathan Wakely
3071fe55f8
[libc++] Add missing include <limits> to bitset to_ullong.pass.cpp test (#149149)
This was added to to_ulong.pass.cpp years ago by
cf1dc8d39e2c9870468ca86f7956a65c7745fece but I don't think the other
part of that commit matters here.
2025-07-17 09:46:45 +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
Ryan Prichard
038e80cfd3
[libc++][Android] Update compiler and sysroot (#148998)
* Upgrade from r536225 to r563880.

* Upgrade from ab/12644632 to f8b85cc5262c6e5cbc9a92c1bab2b18b32a4c63f,
the current HEAD commit of
https://android.googlesource.com/platform/prebuilts/ndk/+/refs/heads/mirror-goog-main-ndk

The previous source of sysroots (ci.android.com), deleted its artifacts
after a short period of time, and is currently out-of-date because of
the aosp-main turndown.

Updating the Docker image also fixes two tests.
2025-07-16 15:57:13 -07:00
Steve O'Brien
a89e6f6672
Minor formatting fix in 'generate_feature_test_macro_components' (#148889)
Fixes a small annoyance where generated files have a format which does
not agree with the one checked during `code-formatter` in CI.

For example `libcxx-generate-files` updates (among possibly others) the
`*.version.compile.pass.cpp` files. Previously these files contained an
extra newline which would fail the code format check. If you update that
file manually to remove just that extra trailing newline, then
`check-generated-output` will fail due to the file's contents differing
from what's expected.

Contains a number of changes: one actual change to the py script, and
lots of resulting whitespace changes.

My process for this was:
* Update `generate_feature_test_macro_components`: just remove an extra
newline which causes the code-format step to fail
* Run `$NINJA libcxx-generate-files` to rebuild all these
`.version.pass.cpp`'s
* Watch this PR's CI run to ensure things pass (i.e. this didn't break
things worse)
2025-07-16 17:19:54 +02:00
Nikolas Klauser
b8b99d83a6
[libc++] Simplify __hash_table further (#148375) 2025-07-16 17:13:08 +02:00
Corentin Jabot
9e5470e7d6
[Clang] Diagnose forming references to nullptr (#143667)
Per [decl.ref],

> Because a null pointer value or a pointer past the end of an object
does not point to an object, a reference in a well-defined program
cannot refer to such things.

Note this does not fixes the new bytecode interpreter.

Fixes #48665
2025-07-16 14:25:24 +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