12879 Commits

Author SHA1 Message Date
Nikolas Klauser
c59d3a2684
[libc++] Add visibility annotations to the std namespace with GCC (#133233)
This allows us to remove the need for `_LIBCPP_TEMPLATE_VIS` and fixes a
bunch of missing annotations for RTTI when used across dylib boundaries.
`_LIBCPP_TEMPLATE_VIS` itself will be removed in a separate patch, since
it touches a lot of code.

This patch is a no-op for Clang. Only GCC is affected.
2025-04-02 22:12:59 +02:00
Peng Liu
e6c2fdc90f
[libc++] Fix ambiguous call to std::max in vector<bool> (#119801)
Closes #121713.
2025-04-02 11:14:14 -04:00
Nikolas Klauser
d8d561a388
[libc++][NFC] Remove _LIBCPP_DISABLE_EXTENSION_WARNINGS (#133693)
We only use `_LIBCPP_DISABLE_EXTENSION_WARNINGS` in a single place while
we use extensions all over the place. The warnings are already disabled,
since libc++'s headers are system headers, so this shouldn't be in any
way observable by users.
2025-04-02 15:40:00 +02:00
Matheus Izvekov
dc17429ae6
[clang] improved preservation of template keyword (#133610) 2025-04-01 17:15:18 -03:00
Nikolas Klauser
76e7bddf9d [libc++][NFC] Replace __attribute__((__const__)) with [[__gnu__::__const__]] 2025-03-31 20:46:04 +02:00
Nikolas Klauser
faefb70c7a [libc++][NFC] Remove _LIBCPP_DLL_VIS
This macro is only ever used inside the definiton for the various
visibility macros on windows. There, it's defined in multiple places
with different expansions, which makes it more confusing than helpful
when trying to figure out what macro expands to what.
2025-03-30 12:04:36 +02:00
Nikolas Klauser
abf9c1a18d
[libc++] Switch a few attribute to use the C++11 syntax (#133293)
Using the C++11 attribute syntax makes it more strict where attributes
can be applied, reducing the number of possible positions an attribute
can appear in.
2025-03-29 22:54:57 +01:00
Hui
e16541e1a6
[libc++] fix flat_set's transparent insert (#133402)
Unlike `flat_map` and `flat_multimap`, The two function template
overloads `flat_set::insert`'s wording strongly suggest we should use
the transparent comparator
https://eel.is/c++draft/flat.set#modifiers-1

Both the code and the tests were not using the transparent comparator,
which needs to be fixed
2025-03-29 16:29:31 +00:00
Louis Dionne
646ad89108
[libc++] Unify __can_reference and __is_referenceable_v (#133278)
Both traits do the same thing. This patch renames __can_reference to
__referenceable and moves it to the is_referenceable header.
2025-03-29 10:07:31 +01:00
Nikolas Klauser
457970d25d [libc++][NFC] Format std::num_put tests 2025-03-28 23:03:42 +01:00
Nikolas Klauser
c8246f69f4
[libc++] Remove friend declarations from __tree (#133237)
Instead, make the few functions `map` relies on public. This makes it
more clear what is private to `__tree` and what is part of the
library-internal interface.
2025-03-28 20:50:23 +01:00
David Spickett
1f90a88b80
[libcxx] Remove clang-18 workaround in picolib build (#133254)
clang-19 changed how Arm triples were normalised and so while we
supported 18 and 19, we could not hard code the path here.

Now that Linaro's bots are running clang-19, and libcxx is going to drop
clang-18 support (https://github.com/llvm/llvm-project/pull/130142) I
have simplified it by hard coding the path again.

I also looked into why this exists in the first place. It was added in
https://reviews.llvm.org/D154246 but not questioned at the time.

It is due to the way we build compiler-rt, which is due to the final
layout we need in the install:
1. The builtins library must be called libclang_rt.builtins.a for clang
to find it. There must not be an architecture name in the filename.
2. That builtins library must be directly in lib/, next to picolib's
installed files.

To achieve number 1 we must set LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON.
However, that causes the file to be installed in a per-target dir which
breaks number 2. So to fix that, we move the builtins library up one
level into lib/.

The alternative is to turn off per-target dirs, which results in a
builtin file with an arch in the name, then rename and move that file
(since it gets installed into lib/generic/).

So in the end, it's the same amount of hacks. I think it's best to keep
the one that uses LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON, as this is the
recommended way to built these days.
2025-03-28 14:30:38 +00:00
Joseph Huber
772173f548
[Clang][AMDGPU] Remove special handling for COV4 libraries (#132870)
Summary:
When we were first porting to COV5, this lead to some ABI issues due to
a change in how we looked up the work group size. Bitcode libraries
relied on the builtins to emit code, but this was changed between
versions. This prevented the bitcode libraries, like OpenMP or libc,
from being used for both COV4 and COV5. The solution was to have this
'none' functionality which effectively emitted code that branched off of
a global to resolve to either version.

This isn't a great solution because it forced every TU to have this
variable in it. The patch in
https://github.com/llvm/llvm-project/pull/131033 removed support for
COV4 from OpenMP, which was the only consumer of this functionality.
Other users like HIP and OpenCL did not use this because they linked the
ROCm Device Library directly which has its own handling (The name was
borrowed from it after all).

So, now that we don't need to worry about backward compatibility with
COV4, we can remove this special handling. Users can still emit COV4
code, this simply removes the special handling used to make the OpenMP
device runtime bitcode version agnostic.
2025-03-28 07:35:16 -05:00
Nikolas Klauser
c13c04fdfe
[libc++] Simplify the implementation of the pointer aliases in allocator_traits (#127079) 2025-03-28 10:27:00 +01:00
Mark de Wever
82c078c54d
[libc++] Remove official Clang 18 support. (#130142)
Since Clang 20 has been release we no longer support Clang 18 per our
policy.

Note the Clang 18 workarounds will be removed in a follow-up patch.
2025-03-27 18:00:46 +01:00
Nikolas Klauser
427ce92ea6 [libc++][NFC] Move dylib function in <__filesystem/operations.h> together
Most of the dylib functions inside `<__filesystem/operations.h>` are at
the top of the file. There are a few spread out in the file for some
reason, which this patch fixes.
2025-03-27 15:14:17 +01:00
Peng Liu
8fdfe3f2a7
[libc++] Refactor ranges::{min, max, min_element, max_element} to use std::__min_element (#132418)
Previously, ranges::min_element delegated to ranges::__min_element_impl, which
duplicated the definition of std::__min_element. This patch updates
ranges::min_element to directly call std::__min_element, which allows
removing the redundant code in ranges::__min_element_impl.

Upon removal of ranges::__min_element_impl, the other ranges algorithms
ranges::{min,max,max_element}, which previously delegated to ranges::__min_element_impl,
have been updated to call std::__min_element instead.

This refactoring unifies the implementation across these algorithms,
ensuring that future optimizations or maintenance work only need to be
applied in one place.
2025-03-27 09:05:37 -04:00
Nikolas Klauser
17d0569538
[libc++] Instantiate hash function externally (#127040)
This has multiple benefits:
- There is a single instance of our hash function, reducing object file
size
- The hash implementation isn't instantiated in every TU anymore,
reducing compile times
- Behind an ABI configuration macro it would be possible to salt the
hash
2025-03-27 13:19:59 +01:00
Nikolas Klauser
8abca171c3
[libc++] Introduce unversioned namespace macros (#133009)
We've started using `_LIBCPP_BEGIN_NAMESPACE_STD` and
`_LIBCPP_END_NAMESPACE_STD` for more than just the namespace for a while
now. For example, we're using it to add visibility annotations to types.
This works very well and avoids a bunch of annotations, but doesn't work
for the few places where we have an unversioned namespace. This adds
`_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD` and
`_LIBCPP_END_UNVERSIONED_NAMESPACE_STD` to make it simpler to add new
annotations consistently across the library as well as making it more
explicit that the unversioned namespace is indeed intended.
2025-03-27 11:34:38 +01:00
A. Jiang
3c0300d1fe
[libc++][ranges] Adjust inheritance detection for enable_view (#132582)
Per [range.view]/6, a `view_interface` isn't a base class of itself, so
`enable_view` should report `false`. Also, current implementation
strategy handles `const` but not `volatile`, IIUC cv-qualifiers should
be consistent handled.

In `enable_view.compile.pass.cpp`, coverage for (`const`) `volatile`
types are added.

Drive-by: Remove one unnessary `test_macro.h` inclusion in a test.

Fixes #132577.
2025-03-26 20:56:52 -04:00
Mark de Wever
f9aa7a20d9
[libc++] Verify std::forward_like's mandates clause. (#127318)
The existing using _ForwardLike declaration already fails with a
subsitution failure. The LWG issue was filed to clarify what should
happen for non-referencable types.

Added test to verify libc++ is already enforcing the new Mandates.

Implements:
- LWG3757 What's the effect of std::forward_like<void>(x)

Closes: #105026
2025-03-26 20:53:30 -04:00
Martin Storsjö
51bceb46f8
[libcxx] [test] Fix restoring LLVM_DIR and Clang_DIR (#132838)
In 664f345cd53d1f624d94f9889a1c9fff803e3391, a fix was introduced,
attempting to restore LLVM_DIR and Clang_DIR after doing
find_package(Clang).

However, 6775285e7695f2d45cf455f5d31b2c9fa9362d3d added a return if the
clangTidy target wasn't found. If this is hit, we don't restore LLVM_DIR
and Clang_DIR, which causes strange effects if CMake is rerun a second
time.

Move the code for restoring LLVM_DIR and Clang_DIR to directly after the
find_package calls, to make sure they are restored, regardless of the
find_package outcome.
2025-03-26 22:13:28 +02:00
David Spickett
3e59b00eb5
[libc++] Add GitHub usernames for Linaro managed bots (#133120)
This isn't the whole team, but enough that one of us will see it and
make sure the right person sees it.

Noted explicitly that Picolibc is also our responsiblity as it's not
always clear that that is tested on Arm.
2025-03-26 13:51:16 -04:00
Peng Liu
649cbcc376
[libc++] Remove unnecessary division and modulo operations in bitset (#121312)
The PR removes the unnecessary division and modulo operations in the
one-word specialization `__bitset<1, _Size>`. The reason is that for the
one-word specialization, we have `__pos < __bits_per_word` (as
`__bitset<1, _Size>` is an implementation detail only used by the public
`bitset`). So `__pos / __bits_per_word == 0` and `__pos / __pos %
__bits_per_word == __pos`.
2025-03-26 12:02:03 -04:00
Nikolas Klauser
3b2b918813
[libc++] Use __detected_or_t to implement __has_iterator_{category,concept}_convertible_to (#124456)
This simplifies the implementation a bit.
2025-03-26 08:55:47 +01:00
Peng Xie
3fbd0ec7e3
[libc++] Update the status for LWG3120 (#116772)
The current implementation already have an __initial_descriptor which
saves the initial state. When release() is called, we will reset the
__initial_descriptor.__cur_ pointer.

This patch also updates the status of LWG3120.

Closes #104274

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-03-25 20:24:56 -04:00
A. Jiang
af267993a7
[libc++] Re-implement LWG2770 again * 2 (#132598)
1013fe3c0cfd7582e94ef2d4bfd79da7ea1a1289 used to implement LWG2770, but
cb0d4df97490ec2d2b1cdf7574d26b1bc4063599 made LWG2770 unimplemented
again because of CWG2386.

This patch re-implements LWG2770, while keeping the libc++-specific
implementation strategy (which is controversial as noted in LWG4040).

Drive-by:
- Make the test coverage for the controversial part noted in LWG4040
libc++-only.
- Add the previously missed entry for LWG2770 to the documentation.
2025-03-26 07:38:02 +08:00
Louis Dionne
b0668d859b
[libc++] Make sure that __desugars_to isn't tripped up by reference_wrapper, const and ref qualifiers (#132092)
Previously, const and ref qualification on an operation would cause
__desugars_to to report false, which would lead to unnecessary
pessimizations. The same holds for reference_wrapper.

In practice, const and ref qualifications on the operation itself are
not relevant to determining whether an operation desugars to something
else or not, so can be ignored.

We are not stripping volatile qualifiers from operations in this patch
because we feel that this requires additional discussion.

Fixes #129312
2025-03-25 14:29:06 -04:00
Louis Dionne
fc5b4d4a9d
[libc++] Rename __construct_one_at_end to __emplace_back_assume_capacity (#132276)
This makes it clear that the end of the vector is updated when calling
the function.
2025-03-25 14:27:54 -04:00
Amr Hesham
357306572d
[libcxx] Put std::monostate in <utility> (#128373)
Fixes: #127874
2025-03-25 18:31:57 +01:00
Nikolas Klauser
a8e168e0c1
[libc++][NFC] Replace structs with variable templates in <__memory/allocator_traits.h> (#129237)
Variable templates are a bit easier on the compiler and improve the
readability of the code.
2025-03-25 15:58:24 +01:00
Nikolas Klauser
7334024859
[libc++] Always build the dylib with hidden visibility (#131313)
The comment seems to be wrong by now. The only difference this makes for
GCC is that there are fewer private symbols exported from the dylib,
which can't ever be accessed by user code anyways.
2025-03-25 15:43:48 +01:00
Louis Dionne
aa80388cf9
[libc++] Ensure that we vectorize algorithms on all Clang-based compilers (#132090)
Otherwise, we wouldn't vectorize on compilers like AppleClang when in
reality we know perfectly well how to do it.
2025-03-24 13:22:40 -04:00
Martin Licht
ef4f479dab
[libc++] Documentation for _LIBCPP_REMOVE_TRANSITIVE_INCLUDES (#130560)
Closes #130486

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-03-24 18:20:20 +01:00
Louis Dionne
fdbd26b4ed
[libc++] Add __assertion_handler to the modulemap (#131031)
That header is generated via CMake, but it is nonetheless present in the
final installation, so it should be covered by the modulemap.

rdar://131418726
2025-03-24 12:30:15 -04:00
Louis Dionne
410754410f
[libc++] Add benchmarks for partitioning algorithms (#127324)
This patch adds benchmarks for std::partition, is_partitioned, etc and
their ranges:: variants.
2025-03-24 12:24:43 -04:00
Nikolas Klauser
ddc62797c4
[libc++] Simplify the implementation of __is_referenceable (#130043)
The `__is_referenceable` builtin has been removed from Clang, since all
its uses have been replaced by builtins themselves. This trait only
exists for GCC compatibility and to word around some issues in the other
traits. The non-builtin implementation has been refactored to use
variable templates instead, making the implementation much simpler.
2025-03-24 07:32:01 +01:00
Nikolas Klauser
66531c998a
[libc++] Remove one of the std::signbit overloads (#130505)
We'e specialized `std::signbit` for signed and unsigned integral types
seperately, even though the optimizer can trivially figure out that
`unsigned_value < 0` always false is. This patch removes the
specialization, since there is really not much of a benefit to it.
2025-03-24 07:30:45 +01:00
A. Jiang
e409464e95
[libc++][test][NFC] Introduce TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED (#132593)
And use it for test cases that became constant-evaluation-suitable due
to P2562R1.

`TEST_STD_AT_LEAST_(20|23)_OR_RUNTIME_EVALUATED` are the precedents.
2025-03-24 10:43:19 +08:00
Nikolas Klauser
fb44f00641
[libc++] Add [[gnu::nodebug]] on type traits (#128502) 2025-03-23 21:01:25 +01:00
Hui
2f1416bbcd
[libc++] implement std::flat_set (#125241)
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-03-23 14:45:21 +00:00
Stephan T. Lavavej
51aab96ebf
[libc++][test] Small fixes for time tests (#132532)
* Fix copy-paste damage in `formatter.tai_time.pass.cpp`.
+ Comparing the `#if` to the `#else` case, it's clear that this
half-copied check should be removed.
* Mark `is_steady` as `[[maybe_unused]]`.
  + It's only used within `LIBCPP_STATIC_ASSERT`.
2025-03-22 06:38:47 -07:00
Mark de Wever
dd97324f11
[libc++][CI] Adds GCC trunk image. (#132271)
As discussed during the last monthly meeting we want to be able to test
the GCC development version in our CI, but we don't want to commit to
support this compiler version.

This adds the image to the CI Docker image. At the moment GCC-15 will
not pass the CI. Having it in the Docker image makes it possible to
validate fixes.

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
Co-authored-by: Hristo Hristov <hghristov.rmm@gmail.com>
2025-03-22 11:36:34 +01:00
Mark de Wever
f60bec9b42
[libc++][chrono] Adds a missing main include. (#132100) 2025-03-21 18:02:32 +01:00
Mark de Wever
7be243add2
[NFC][libc++][chrono] Removes dead code. (#132104)
For certain time_points there are specializations of __convert_to_tm.
This means the non-specialized version is never called. This means some
of the `if constexpr` will never be true. These are removed.

Since there is a `static_assert` accidental removal of the
specialization will make the code ill-formed.
2025-03-21 18:01:36 +01:00
S. B. Tam
7d742f97b0
[libc++][test] Guard uses of _LIBCPP_HAS_THREADS in FTM tests (#132258) 2025-03-21 11:36:36 +08:00
A. Jiang
6038077dde
[libc++] Bump __cpp_lib_constexpr_algorithms for P2562R1 in C++26 (#132075)
Completes P2562R1.
2025-03-21 07:33:52 +08:00
Louis Dionne
be36f41ff9 [libc++][NFC] Run two tests I'm about to modify a bunch under clang-format 2025-03-20 16:03:31 -04:00
Louis Dionne
382b707e52
[libc++] Add coverage for C++17 and Clang Modules with LSV (#131815)
In recent versions of Clang, using -std=c++20 (and later) implies LSV
when compiling with modules. This change resulted in making our LSV job
redundant with the regular modules job, which uses the latest Standard.
This patch increases the coverage of our CI without increasing its cost
by pinning the LSV job to use C++17, which normally doesn't use LSV. A
related question is whether we should add coverage for non-LSV builds
using Clang modules.
2025-03-20 13:50:59 -04:00
Mark de Wever
73cd84a90e
[NFC][libc++] Adds (multi|)(map|set) forward declarations. (#131541)
This removes duplicated forward declarations of these classes.

closes: #131518
2025-03-20 18:00:01 +01:00