Commit Graph

13026 Commits

Author SHA1 Message Date
Louis Dionne
4d50b405f1 [libc++] Remap headers in the debug info when building the library (#143004)
The libc++ build includes a step where headers are generated. This is
required in order to preprocess some files such as the assertion handler
and the __config_site header. As a result, the library is built against
headers located inside the build directory, and the path to those
headers is what's included in the debug information of the library.

However, these headers in the build directory are usually not
persistent, which means that the debug information might end up
referring to headers that don't exist anymore. To solve this problem,
this patch uses the -fdebug-prefix-map flag supported by Clang and GCC
to remap the generated headers to the original headers in the source
directory. This provides the illusion that the library was truly built
against the in-source version of the headers.
2025-06-09 16:52:29 -04: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
a925e90ec2 [libc++][NFC] Remove some unused code from <map> (#142408) 2025-06-06 15:27:05 +02: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
Tomohiro Kashiwada
11c3e65e1d [libc++] Remove unused include caused by wrong __has_include (#141328)
The parameter passed to __has_include has to be quoted by `<>` or `"`,
not both.
2025-06-02 13:12:40 -04:00
Jessica Clarke
35757d67ba Revert "[libc++] Re-enable std::pair trivial copy constructor for FreeBSD >= 14" (#142204)
The ABI bump to adopt the conforming ABI v1 std::pair implementation did
not end up happening for FreeBSD 14, and instead this diff was reverted
downstream in FreeBSD[1]. Align the upstream ABI config with FreeBSD's
actual ABI.

[1] ce4f1f49e036 ("Revert commit 6255157d24 from llvm-project (by
Dimitry Andric):")

This reverts commit 6255157d24.
2025-05-31 08:07:15 +01: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
4ad230bebd [libc++] Refactor bitset::{any, all} (#128445)
This patch refactors the `all()` and `any()` methods in `bitset` to
eliminate redundant code while preserving the performance. Code
generation remains unchanged, as verified on Compiler
Explorer: https://godbolt.org/z/xx8hb4sPM.
2025-05-28 12:10:46 -04: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 c861fe8a71.

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 3e4c9dc299.

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

Revert "[libc++][NFC] Replace a few "namespace std" with the correct macro (#140510)"
This reverts commit 1d411f27c7.
2025-05-28 12:04:51 -04:00
Louis Dionne
7f78ebf248 Revert "[libc++] Fix build failure with libdispatch backend (#141606)"
It turns out that we're about to revert the patches that added these
annotations in the first place. I was too hasty to land this.

This reverts commit 56594710c7.
2025-05-28 10:21:36 -04:00
Louis Dionne
56594710c7 [libc++] Fix build failure with libdispatch backend (#141606)
We get an error "cannot add 'abi_tag' attribute in a redeclaration"
because functions like `__dispatch_apply` are first declared without an
ABI tag due to `_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS` inside the
header, and then redeclared with an ABI tag in the .cpp file.
2025-05-28 10:20:48 -04:00
David Spickett
783b399346 [libcxx][docs] Fix bullet point in Additional Tools section
Without a blank line after the ":", it was rendered on the same
line instead of a new one.
2025-05-28 08:35:54 +00: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
Nikolas Klauser
afd53edefa [libc++] Bump the docker image hash (#140517)
This updates GCC 15 to the release version to allow us to upgrade to GCC
15.
2025-05-27 10:58:45 +02:00
Nikolas Klauser
1d411f27c7 [libc++][NFC] Replace a few "namespace std" with the correct macro (#140510)
We've added a new macro for the unversioned `namespace std` cases in
#133009, but it seems we've missed a few places. This fixes the places I
just found.
2025-05-23 22:56:24 +02: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
f73287e623 [libc++] Make ABI annotations explicit for windows-specific code (#140507)
This doesn't show up in the CI, since we don't have abilists for
windows. I'm also not sure whether we want them, so I don't think we can
easily test this change.
2025-05-20 09:05:48 +02:00
Nikolas Klauser
3e4c9dc299 [libc++] Add explicit ABI annotations to functions from the block runtime declared in <__functional/function.h> (#140592) 2025-05-20 08:25:40 +02: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
Nikolas Klauser
b060022103 [libc++] Bump GCC_HEAD_VERSION to 16
We need to update or GCC version to be able to upgrade to GCC 15.
2025-05-19 10:50:18 +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
Nikolas Klauser
c861fe8a71 [libc++] Introduce ABI sensitive areas to avoid requiring _LIBCPP_HIDE_FROM_ABI everywhere (#131156)
This patch introduces `_LIBCPP_{BEGIN,END}_EXPLICIT_ABI_ANNOTATIONS`,
which allow us to have implicit annotations for most functions, and just
where it's not "hide_from_abi everything" we add explicit annotations.
This allows us to drop the `_LIBCPP_HIDE_FROM_ABI` macro from most
functions in libc++.
2025-05-18 15:47:05 +02:00
Nikolas Klauser
f6867709a7 [libc++] Fix set::operator= when instantiating with a std::pair (#140385)
This has been introduced by #134819, most likely due to a merge conflict
I didn't resolve properly (I thought I did in that patch what I'm now
doing here).
2025-05-18 12:40:34 +02:00
Nikolas Klauser
962aa2666f [libc++] Don't instantiate allocators in __tree on an incomplete type (#140225)
This causes a mismatch between `value_type` and
`allocator_type::value_type` in `__tree`, but I think that's acceptable.
`__tree` primarily gets a `__value_type` wrapper due to potential ABI
breaks and unwraps it to the same as `allocator_type::value_type` in the
end. A cleanup patch will also change `__tree::value_type` to be the
same as `allocator_type::value_type`, making the type mismatch only
visible where `__tree` is instantiated in `map`.
2025-05-18 12:38:06 +02:00
Hui
4b104c6853 [libc++] Fix flat_{multi}set insert_range (#137462)
Fixes #136656
2025-05-16 13:17:21 -04:00
Nikolas Klauser
e1ca2c5b60 [libc++] Reject abilist if it contains an ABI tag (#139030)
We currently don't have any ABI tags in our dylib symbols, and this is
unlikely to change in the future. By diagnosing this we avoid
accidentally adding one through e.g. having `_LIBCPP_HIDE_FROM_ABI` on
an exported symbol.
2025-05-16 15:41:53 +02:00
Louis Dionne
e829963a4f [libc++][NFC] Update the documentation for _LIBCPP_OVERRIDABLE_FUNCTION (#140121) 2025-05-16 07:29:46 -04:00
Christopher Di Bella
c41812e6ea [libcxx] applies #134819 to insert_or_assign with const key_type& (#140124)
This was missed due to using prvalues in the test case, which were
picked up by the rvalue-reference overload instead.
2025-05-16 08:56:45 +02:00
cor3ntin
381a649fb9 [Clang] Add warnings when mixing different charN_t types (#138708)
charN_t represent code units of different UTF encodings. Therefore the
values of 2 different charN_t objects do not represent the same
characters.

In order to avoid comparing apples and oranges, we add new warnings to
warn on:
  - Implicit conversions
  - Comparisons
  - Other cases involving arithmetic conversions

We only produce the warning if we cannot establish the comparison would
be safe through constant evaluation.

The new `-Wimplicit-unicode-conversion` warning is enabled by default.

Note that this PR intentionally doesn;t touches char/wchar_t, but it
would be worth considering also warning on extending the new warnings to
these types (in a follow up)

Additionally most arithmetic operations on charN_t don't really make
sense (ie what does it mean to addition code units), so we could add
warnings for that.

Fixes #138526
2025-05-15 18:16:05 +02:00
Kazu Hirata
b7d6a54703 [libc++] Fix typos in documentation (#139853) 2025-05-15 10:35:32 -04:00
Nikolas Klauser
49bced456c [libc++] Add basic constant folding for std::format (#107197)
```
-------------------------------------------------------------------
Benchmark                                        old            new
-------------------------------------------------------------------
BM_format_string<char>/1                     42.1 ns        7.67 ns
BM_format_string<char>/2                     22.3 ns        3.84 ns
BM_format_string<char>/4                     10.6 ns        1.92 ns
BM_format_string<char>/8                     5.31 ns       0.815 ns
BM_format_string<char>/16                    2.79 ns       0.480 ns
BM_format_string<char>/32                    1.63 ns       0.550 ns
BM_format_string<char>/64                   0.782 ns       0.276 ns
BM_format_string<char>/128                  0.397 ns       0.145 ns
BM_format_string<char>/256                  0.211 ns       0.066 ns
BM_format_string<char>/512                  0.154 ns       0.035 ns
BM_format_string<char>/1024                 0.146 ns       0.021 ns
BM_format_string<char>/2048                 0.125 ns       0.033 ns
BM_format_string<char>/4096                 0.097 ns       0.016 ns
BM_format_string<char>/8192                 0.077 ns       0.012 ns
BM_format_string<char>/16384                0.066 ns       0.010 ns
BM_format_string<char>/32768                0.062 ns       0.016 ns
BM_format_string<char>/65536                0.062 ns       0.016 ns
BM_format_string<char>/131072               0.443 ns       0.015 ns
BM_format_string<char>/262144               0.629 ns       0.017 ns
BM_format_string<char>/524288               0.715 ns       0.020 ns
BM_format_string<char>/1048576              0.757 ns       0.020 ns
BM_format_string<wchar_t>/1                  38.8 ns        34.0 ns
BM_format_string<wchar_t>/2                  19.4 ns        16.9 ns
BM_format_string<wchar_t>/4                  9.88 ns        8.45 ns
BM_format_string<wchar_t>/8                  6.30 ns        6.47 ns
BM_format_string<wchar_t>/16                 3.11 ns        3.21 ns
BM_format_string<wchar_t>/32                 1.60 ns        1.63 ns
BM_format_string<wchar_t>/64                0.899 ns       0.925 ns
BM_format_string<wchar_t>/128               0.676 ns       0.693 ns
BM_format_string<wchar_t>/256               0.658 ns       0.685 ns
BM_format_string<wchar_t>/512               0.556 ns       0.531 ns
BM_format_string<wchar_t>/1024              0.428 ns       0.402 ns
BM_format_string<wchar_t>/2048              0.328 ns       0.319 ns
BM_format_string<wchar_t>/4096              0.276 ns       0.274 ns
BM_format_string<wchar_t>/8192              0.252 ns       0.251 ns
BM_format_string<wchar_t>/16384             0.248 ns       0.246 ns
BM_format_string<wchar_t>/32768             0.229 ns       0.232 ns
BM_format_string<wchar_t>/65536             0.248 ns       0.246 ns
BM_format_string<wchar_t>/131072            0.250 ns       0.240 ns
BM_format_string<wchar_t>/262144             3.03 ns        3.03 ns
BM_format_string<wchar_t>/524288             3.14 ns        3.15 ns
BM_format_string<wchar_t>/1048576            3.60 ns        3.61 ns
BM_string_without_formatting<char>           32.2 ns       0.470 ns
BM_string_without_formatting<wchar_t>        38.8 ns        10.2 ns
```
2025-05-15 10:37:32 +02:00
Nikolas Klauser
fbdf38ed43 [libc++] run clang-tidy on src/ in the CI (#121198)
This adds a new test to run clang-tidy on the `src/` directory and
temporarily disables and clang-tidy checks that currently fail. They
will be enabled in follow-up patches.
2025-05-15 10:34:09 +02:00