7219 Commits

Author SHA1 Message Date
Nikolas Klauser
43260b01dd
[libc++] Add test to ensure that the mangling of types stays the same (#143556) 2025-06-23 10:43:47 +02:00
Hui
831fcb5e91
[libc++] constexpr flat_map (#137453)
Fixes #128673
2025-06-21 13:41:32 +01:00
Jakub Mazurkiewicz
1bb2328fd3
[libc++] Implement views::join_with (#65536)
* Implement "P2441R2 `views::join_with`" (https://wg21.link/P2441R2),
closes #105185
* Implement LWG4074 (https://wg21.link/LWG4074), closes #105346
* Complete implementation of "P2711R1 Making multi-param constructors of
views explicit" (https://wg21.link/P2711R1), closes #105252
* Complete implementation of "P2770R0 Stashing stashing iterators for
proper flattening" (https://wg21.link/P2770R0), closes #105250
2025-06-21 10:54:50 +01:00
Aiden Grossman
7157f33c6c
[libc++] Disable a std::unexpected test in modules build (#144466)
This patch disables unexpected_disabled_cpp17.verify.cpp under clang
modules builds because it changes diagnostics criteria post #143423,
causing the test to fail.

This patch follows a similar style to 853059a15011fd8b57dd0.
This was found when working on trying to land #144033.
2025-06-20 12:58:59 -04:00
Hristo Hristov
945ce1aa3d
[libc++] Update the value of __cpp_lib_constrained_equality after P3379R0 (#144553)
https://wg21.link/P3379R0 updated the value of __cpp_lib_constrained_equality,
but we forgot to update it when we implemented the paper.
2025-06-20 12:36:46 -04:00
Nikolas Klauser
20245bbf66 [libc++][NFC] Format abs.pass.cpp test
I will modify the test in an upcoming PR. I'm formatting it now to avoid
a bunch of whitespace changes in that PR.
2025-06-19 10:41:12 +02:00
Nikolas Klauser
584cc37687
[libc++] Move std::abs into __math/abs.h (#139586)
`template <class = int>` is also added to our implementations to avoid
an ambiguity between the libc's version and our version when both are
visible.

This avoids including `<stdlib.h>` in `<math.h>`.
2025-06-19 10:37:18 +02:00
S. B. Tam
a9a71b6d31
[libc++][test] Don't pass ill-formed UTF-8 to MAKE_STRING_VIEW (#136403) 2025-06-19 15:21:28 +08:00
Peng Liu
9827440f1e
[libc++] Optimize ranges::{for_each, for_each_n} for segmented iterators (#132896)
Previously, the segmented iterator optimization was limited to `std::{for_each, for_each_n}`. This patch
extends the optimization to `std::ranges::for_each` and `std::ranges::for_each_n`, ensuring consistent
optimizations across these algorithms. This patch first generalizes the `std` algorithms by introducing
a `Projection` parameter, which is set to `__identity` for the `std` algorithms. Then we let the `ranges`
algorithms to directly call their `std` counterparts with a general `__proj` argument. Benchmarks
demonstrate performance improvements of up to 21.4x for ``std::deque::iterator`` and 22.3x for
``join_view`` of ``vector<vector<char>>``.

Addresses a subtask of #102817.
2025-06-18 12:22:47 -04:00
Peng Liu
13510c0736
[libc++] Make list constexpr as part of P3372R3 (#129799)
This patch makes `std::list` constexpr as part of P3372R3.

Fixes #128659.
2025-06-18 12:13:50 -04:00
Martin Storsjö
c3efe7d64c
[libcxx] [test] Fix odr_signature tests with optimizations enabled (#144317)
If optimization is enabled, the inline `f()` function actually gets
inlined, meaning that the functions `tu1()` and `tu2()` trivially return
1 and 2, instead of actually referencing the potentially linker
deduplicated function `f()`, which is what the test tries to test.

Therefore, this test previously actually failed to test what it was
supposed to test, if optimization was enabled.

Mark the inline functions with `TEST_NOINLINE` to make sure that they
don't get inlined even with optimizations enabled.

Also update the TODO comments to explain why we have an XFAIL for msvc
mode here.

This avoids these tests unexpectedly passing if building in msvc mode,
with optimizations enabled
(`-DLIBCXX_TEST_PARAMS="optimization=speed"`).
2025-06-18 14:12:14 +03:00
Daniel Thornburgh
fd7e46b864
Revert "[libc++] Remove trailing newline from _LIBCPP_ASSERTION_HANDLER calls" (#144615)
Reverts llvm/llvm-project#143573
2025-06-17 15:50:42 -07:00
Sam Clegg
a5a0d88073
[libc++] Remove trailing newline from _LIBCPP_ASSERTION_HANDLER calls (#143573)
This newline was originally added in https://reviews.llvm.org/D142184
but I think updating `__libcpp_verbose_abort` to add newline instead is
more consistent, and works for other callers of `_LIBCPP_VERBOSE_ABORT`.

The `_LIBCPP_ASSERTION_HANDLER` calls through to either
`_LIBCPP_VERBOSE_ABORT` macro or the `__builtin_verbose_trap`. From what
I can tell neither of these function expect a trailing newline (at least
none of the usage of `_LIBCPP_VERBOSE_ABORT` or `__builtin_verbose_trap`
that I can find include a trailing newline except `_LIBCPP_ASSERTION_HANDLER`).

I noticed this discrepancy when working on
https://github.com/emscripten-core/emscripten/pull/24543
2025-06-17 17:07:16 -04:00
Louis Dionne
8d1610afd0 [libc++] Mark two assertion tests as unsupported in C++03 mode
Our assertion checking facility requires at least C++11, so these
tests were failing when run in C++03 mode.
2025-06-17 16:51:35 -04:00
Hristo Hristov
a0c00ccd5f
[libc++] P2944R3: Constrained comparisons - update reference_wrapper implementation (#139368)
Updates the implementation `std::reference_wrapper` -
[P2944R3](https://wg21.link/P2944R3) as discussed in
https://github.com/llvm/llvm-project/pull/117664#discussion_r1857826166
This PR also refactors the tests in preparation to implements the
constrained comparisons for `optional`, `variant` etc.

- Moves the test helpers (concepts and types) for testing constrained
comparisons to `test_comparisons.h`.
- Updates the `std::reference_wrapper` implementation to use the concept
`__core_convertible_to<bool>` as per comments in #135759.

Closes #138233

# References:
- [refwrap.comparisons](https://wg21.link/refwrap.comparisons)

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-06-15 07:45:48 +03:00
halbi2
eab1a1d491
[libc++][test] Improve test coverage for flat_set (lack of) SCARY iterators (#139649)
Missing from 5e94e26a7afb8db00cc123e5fc5471c1125596e3.
2025-06-12 13:15:41 -04:00
tynasello-google
13fe07d670
[libc++] Expand Android libc++ test config files (#142846)
Parameterize (and rename) existing libc++/libc++abi test configuration
files for the Android NDK to work for both the NDK and platform.

Android LLVM downstream seeks to test libc++ for both the NDK and
platform build (currently only testing the NDK), which will use almost
identical test configuration files. The only difference is the name of
the libc++ shared object used. Because of this we parameterize the
current test files (for both libc++ and libc++abi) with the existing
LIBCXX_SHARED_OUTPUT_NAME cmake variable, and rename the file
accordingly.
2025-06-12 11:39:28 -04:00
A. Jiang
bba4ded3c2
[libc++] Fix constructing bitset from non-null-terminated arrays (#143691)
Unconditional evaluation of `char_traits<_CharT>::length(__str)` is problematic, because it causes
UB when `__str` points to a non-null-terminated array. We should only call `length` (currently, in
`basic_string_view`'s constructor) when `__n == npos` per [bitset.cons]/8.

Drive-by change: Reduction of conditional compilation, given that
- both `basic_string_view<_CharT>::size_type` and `basic_string<_CharT>::size_type` must be 
  `size_t`, and thus
- both `basic_string_view<_CharT>::npos` and `basic_string<_CharT>::npos` must be `size_t(-1)`.

For the type sameness in the standard wording, see:
- [string.view.template.general]
- [basic.string.general]
- [allocator.traits.types]/6
- [default.allocator.general]/1

Fixes #143684
2025-06-12 10:53:41 -04:00
Nikolas Klauser
42c82fcc29
[libc++] Upgrade to GCC 15 (#138293) 2025-06-11 20:19:26 +02:00
Peng Liu
38fb0117ab
[libc++] Make forward_list constexpr as part of P3372R3 (#129435)
Fixes #128658
2025-06-11 12:13:36 -04:00
Nikolas Klauser
3c56437eaf
[libc++] Refactor signed/unsigned integer traits (#142750)
This patch does a few things:
- `__libcpp_is_signed_integer` and `__libcpp_is_unsigned_integer` are
refactored to be variable templates instead of class templates.
- the two traits are merged into a single header
`<__type_traits/integer_traits.h>`.
- `__libcpp_signed_integer`, `__libcpp_unsigned_integer` and
`__libcpp_integer` are moved into the same header.
- The above mentioned concepts are renamed to `__signed_integer`,
`__unsigned_integer` and `__signed_or_unsigned_integer` respectively.
2025-06-11 14:31:13 +02:00
maflcko
a17e97e677
[libc++] Add missing C++20 [time.point.arithmetic] (#143165)
This was part of https://wg21.link/p0355r7, but apparently never
implemented.

---------

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-06-11 08:43:23 +02:00
Louis Dionne
616f83530f
[libc++] Move swap test to a .compile.pass.cpp (#143167) 2025-06-10 15:22:42 -04:00
Nikolas Klauser
040e9e02cc
[libc++] Inline __has_feature and __has_extension uses (#133634)
Since GCC now supports `__has_feature` and `__has_extension` as well,
there isn't much of a reason to define new macros to test for the
features.
2025-06-10 05:54:15 +02:00
Alex Guteniev
8631cddd69
libc++ test: update MinSequenceContainer.h to make some tests pass on MSVC STL (#140287)
Per [sequence.reqmts] there are these member functions.

I did not audit if any other member functions are missing. Adding these
is enough for MSVC STL
2025-06-09 18:35:27 +08:00
Aiden Grossman
20a6b63f1b
[libcxx] Include __fwd/span.h in <mdspan>
This patch includes __fwd/span.h in <mdspan> so that we get the
declaration of dynamic_extent inside <mdspan>. We also clean up quite a
few tests that were manually included <span> for dynamic_extent.

This is based on feedback from #142693.

Reviewers: philnik777, ldionne

Reviewed By: philnik777

Pull Request: https://github.com/llvm/llvm-project/pull/142925
2025-06-08 21:58:36 +00:00
Hui
692c5cdb56
[libc++] Do not call reserve in flat containers if underlying container is user defined (#140379)
This is brought up in the LWG reflector. We currently call `reserve` if
the underlying container has one. But the spec does not specify what
`reserve` should do for Sequence Container. So in theory if the
underlying container is user defined type and it can have a function
called `reserve` which does something completely different.

The fix is to just call `reserve` for STL containers if it has one
2025-06-07 08:47:46 +01:00
Hui
155fd97a66
[libc++] flat_meow transparent comparator string literals (#133654)
See discussion in https://cplusplus.github.io/LWG/issue4239

    std::flat_map<std::string, int, std::less<>> m;
    m.try_emplace("abc", 5);  // hard error

The reason is that we specify in 23.6.8.7 [flat.map.modifiers]/p21
the effect to be as if `ranges::upper_bound` is called.

`ranges::upper_bound` requires indirect_strict_weak_order, which
requires the comparator to be invocable for all combinations. In this
case, it requires

    const char (&)[4] < const char (&)[4]

to be well-formed, which is no longer the case in C++26 after
https://wg21.link/P2865R6.

This patch uses `std::upper_bound` instead.
2025-06-06 13:05:36 -04:00
Nikolas Klauser
1d68abccb5
[libc++] Move _ITER_TRAITS and _ITER_CONCEPT into <__iterator/concepts.h> (#140528)
`_ITER_TRAITS` and `_ITER_CONCEPT` are really implenentation details of
`<__iterator/concetps.h>`, so it makes more sense to put them there than
into `<__iterator/iterator_traits.h>`.
2025-06-06 08:33:15 +02:00
Louis Dionne
9dc5dac52d
[libc++] Avoid spuriously unsupporting the new FTM tests (#142024)
The new FTM tests contain text that they validate against to check the
output of the FTM generation script. However, that text lexically
contains the characters `// UNSUPPORTED: <...>`, which leads Lit to make
the whole test unsupported under these conditions. To prevent that from
happening, an `# END.` block can be used to prevent Lit from looking
further into the file for directives.
2025-06-05 13:29:57 -04:00
Aiden Grossman
5990624383
[libcxx] Add span includes to some mdspan tests (#142693)
This patch adds missing <span> includes for std::mdspan tests that use
std::span. There are other cases where we need dynamic_extent that are
handled in #142925.

This was found by running the test suite in the bootstrapping build
with Clang modules enabled.
2025-06-05 13:22:43 -04:00
A. Jiang
479f992291
[libc++] Fix basic_string::shrink_to_fit for constant evaluation (#142712)
Currently, when the string shrink into the SSO buffer, the `__rep_.__s`
member isn't activated before the `traits_type::copy` call
yet, so internal `__builtin_memmove` call writing to the buffer causes
constant evaluation failure. The existing test coverage seems a bit
defective and doesn't cover this case - `shrink_to_fit` is called on the
copy of string after erasure, not the original string object.

This PR reorders the `__set_short_size` call, which starts the lifetime
of the SSO buffer, before the copy operation. Test coverage is achieved
by calling `shrink_to_fit` on the original erased string.
2025-06-05 07:23:49 +08:00
Peng Liu
ec5610c4a2
[libc++] Ensure strong exception guarantee for forward_list::resize (#131025)
The current implementation of `forward_list::resize` does not meet the
strong exception safety guarantee required by [forward.list.modifiers]:

    If an exception is thrown by any of these member functions there is no
    effect on the container.

This patch refactors `resize()` to provide strong exception safety and
introduces additional tests to validate the strong exception guarantees
for other `forward_list` modifiers.

Fixes #118366.
2025-06-04 13:04:19 -04:00
A. Jiang
fdb11c1be6
[libc++] Disallow specializing common_reference (#141465)
`common_reference` isn't an exception for [meta.rqmts]/4, so it's better
to disallow users to specialize it.

`indirectly_readable.compile.pass.cpp` was a bit problematic. It
attempted to opt-out common reference type in some wrong ways. Also, the
standard effectively forbids opting-out common reference type for `T&`
and `T&&`. This patch removes and adjusts some problematic cases.

---------

Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-06-04 20:41:58 +08:00
Peng Liu
3e5fd77d32
[libc++] constexpr priority_queue (#140634)
This patch makes `priority_queue` constexpr as part of P3372R3.

Fixes #128671.
2025-06-04 19:58:25 +08:00
Louis Dionne
d0fb83531b
[libc++] Remove invalid char_traits instantiations from a test (#142016)
We had a test which created invalid char_traits instantiations for
non-character types. This patch removes them.
2025-06-03 11:58:42 -04:00
A. Jiang
769c42f4a5
[libc++] Fix padding calculation for function reference types (#142125)
#109028 caused `sizeof` to be sometimes applied to function reference
types, which makes a program ill-formed. This PR handles reference types
by specializations to prevent such bogus `sizeof` expression to be
instantiated.

Fixes #142118.
2025-06-03 11:54:49 -04:00
A. Jiang
437ad06f76
[libc++] Use __reference_constructs_from_temporary if eligible (#141916)
Currently, libc++'s `<tuple>` is using the deprecated
`__reference_binds_to_temporary` intrinsic. This PR starts to use
`__reference_constructs_from_temporary` if possible.

It seems that `__reference_constructs_from_temporary` should be used via
an internal type traits provided in
`<__type_traits/reference_constructs_from_temporary.h>`. But given the
old intrinsic was directly used, this PR doesn't switch to the current
convention yet.

P2255R2 is related. Although the paper indicated that constructors of
`tuple` should be deleted in such a case.

---------

Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-06-03 10:34:45 +08:00
Nikolas Klauser
705eedd47d
[libc++] Remove availability annotations which can't fire anymore (#140049)
According to https://developer.apple.com/support/xcode/ the removed
annotations can't fire anymore, since the targets they would fire for
aren't supported anymore.
2025-06-02 13:13:57 -04:00
Hui
665148d5e1
[libc++][test] Fix test not relying on MinSequenceContainer (#140372)
The affected tests are relying on the fact that `MinSequenceContainer`
does not have `insert_range`. This prevents landing of #140287.

This PR creates a new helper class to allow the change in MinSequenceContainer.
2025-05-30 13:12:48 -04:00
Ksar
b71255705b
[libc++] P2165R4: Update deduction guides for map containers and container adaptors (#136011)
Fixes #135351

This PR update CATD guides to associative containers (`std::map`,
`std::multimap`, `std::unordered_map`, `std::unordered_multimap`,
`std::flat_map`, `std::flat_multimap`).

- Updated template alias for deduction guides for the relevant
associative containers.
- Added a new test to verify the deduction guides with `std::map`,
`std::multimap`, `std::unordered_map`, `std::unordered_multimap`,
`std::flat_map`, `std::flat_multimap`.
2025-05-30 15:17:06 +08:00
Peng Liu
4608df5b9f
[libc++] Simplify __bitset::__init (#121357)
This PR simplifies `__bitset::__init` into a more compact and readable
form, which avoids redundant computations of a `size_t` value and
eliminates the overhead of a local array.
2025-05-28 12:09:50 -04:00
James Y Knight
c3656afdf1
Revert "[libc++] Introduce ABI sensitive areas to avoid requiring _LIBCPP_HIDE_FROM_ABI everywhere (#131156)" (#141756)
This reverts commit c861fe8a71e64f3d2108c58147e7375cd9314521.

Unfortunately, this use of hidden visibility attributes causes
user-defined specializations of standard-library types to also be marked
hidden by default, which is incorrect. See discussion thread on #131156.

...and also reverts the follow-up commits:

Revert "[libc++] Add explicit ABI annotations to functions from the block runtime declared in <__functional/function.h> (#140592)"
This reverts commit 3e4c9dc299c35155934688184319d391b298fff7.

Revert "[libc++] Make ABI annotations explicit for windows-specific code (#140507)"
This reverts commit f73287e623a6c2e4a3485832bc3e10860cd26eb5.

Revert "[libc++][NFC] Replace a few "namespace std" with the correct macro (#140510)"
This reverts commit 1d411f27c769a32cb22ce50b9dc4421e34fd40dd.
2025-05-28 12:04:51 -04:00
Martin Storsjö
74a102fc1c
[libcxx] [test] Change an MSVC mode XFAIL into UNSUPPORTED (#141609)
The underlying bug in vcruntime [1] has been fixed in the latest version
of MSVC (released two weeks ago); this will cause the test which is
currently marked XFAIL to start erroring, when it starts passing
unexpectedly.

This version of MSVC may soon start appearing in the Github Actions
runner images used for our CI.

We could try to detect the state of this bug, but in practice, such
detection code would essentially be a copy of this whole test.

Therefore, just mark this test UNSUPPORTED for the MSVC mode builds. If
we at some point require new enough MSVC libraries, we could remove the
marking entirely.

[1]
https://developercommunity.visualstudio.com/t/vcruntime-nothrow-array-operator-new-fal/10373274
2025-05-28 09:21:30 +03:00
LRFLEW
6a738f6cf7
[libc++] Fix directory name in libcxx rand.dist tests path (#140160)
The path libcxx/test/libcxx/numerics/rand/rand.dis was missing the
't' in rand.dist.
2025-05-27 14:13:21 -04:00
Martin Storsjö
cd7104eb87
[libcxx] [test] Extend mingw target checks to cover the arm64ec architecture too (#141227) 2025-05-23 19:13:51 +03:00
Peng Liu
81b81354f8
[libc++] Optimize bitset::to_string (#128832)
This patch optimizes `bitset::to_string` by replacing the existing bit-by-bit processing with a more efficient
bit traversal strategy. Instead of checking each bit sequentially, we leverage `std::__countr_zero` to efficiently
locate the next set bit, skipping over consecutive zero bits. This greatly accelerates the conversion process,
especially for sparse `bitset`s where zero bits dominate. To ensure similar improvements for dense `bitset`s, we
exploit symmetry by inverting the bit pattern, allowing us to apply the same optimized traversal technique. Even
for uniformly distributed `bitset`s, the proposed approach offers measurable performance gains over the existing
implementation.

Benchmarks demonstrate substantial improvements, achieving up to 13.5x speedup for sparse `bitset`s with
`Pr(true bit) = 0.1`, 16.1x for dense `bitset`s with `Pr(true bit) = 0.9`, and 8.3x for uniformly distributed
`bitset`s with `Pr(true bit) = 0.5)`.
2025-05-21 12:16:40 -04:00
Peng Liu
09c266b75d
[libc++] Optimize std::for_each_n for segmented iterators (#135468)
This patch enhances the performance of `std::for_each_n` when used with
segmented iterators, leading to significant performance improvements,
summarized in the tables below. This addresses a subtask of
https://github.com/llvm/llvm-project/issues/102817.
2025-05-21 12:10:50 -04:00
Nikolas Klauser
3a86e0bd29
[libc++] Optimize std::getline (#121346)
```
-----------------------------------------------
Benchmark                   old             new
-----------------------------------------------
BM_getline_string        318 ns         32.4 ns
```
2025-05-19 10:59:36 +02:00
Mark de Wever
b12d68e0b2
[libc++] Implements the new FTM header test generator. (#134542)
This generator has almost identical output to the existing script.
Notable differences are
- conditionally include headers that are not implemented yet
- removes the synopsis
- uses 2 spaces indent in `# if`

There are a few more test macros added that triggered bugs in existing
FTM.
2025-05-18 18:21:20 +02:00