12731 Commits

Author SHA1 Message Date
Simon Tatham
30ae485835
[libcxx] Work around picolibc argv handling in tests. (#127662)
This fixes some test failures when the libcxx tests are run against an
up-to-date picolibc on embedded Arm, because those tests depend on an
unsupported locale but the `hasAnyLocale` preliminary check wrongly
concluded that the locale _was_ supported.

`hasAnyLocale` passes a set of locale strings to a test program via the
command line, and checks if the libc under test reports that any of the
locales can be successfully set via setlocale(). In some invocations one
of the locale names contains a space, e.g. the Windows-style locale name
"English_United States.1252".

Unfortunately picolibc's crt0, when running under Arm semihosting,
fetches the single command string from the host and then splits it up at
spaces without implementing any kind of quoting. So it simply isn't
possible to get a space into an argv word. As a result, we end up
testing for the locale (in this example) "English_United". In up-to-date
versions of picolibc, this is actually accepted, since it contains no
objectionable character set specification (or indeed any at all). So the
lit check wrongly concludes that libc supports that locale, and enables
some locale tests, which fail.

This patch works around the issue entirely within `hasAnyLocale()`, by
abandoning the use of argv completely, and instead encoding the list of
locales to check as an array of strings inside the test program.
2025-02-21 09:08:53 +00:00
Mark de Wever
e83ad81699 [NFC][libc++][TZDB] Fixes formatting.
This was broken by #127339
2025-02-20 17:47:34 +01:00
Louis Dionne
f00b32e2d0
[libc++] Reduce the dependency of the locale base API on the base system from the headers (#117764)
Many parts of the locale base API are only required when building the
shared/static library, but not from the headers. Document those
functions and carve out a few of those that don't work when
_XOPEN_SOURCE is defined to something old.

Fixes #117630
2025-02-20 08:38:42 -05:00
Louis Dionne
8feb5bac32
[libc++] Add benchmarks for copy algorithms (#127328)
This patch adds benchmarks for the copy family of algorithms (copy,
copy_n, copy_if, copy_backward).
2025-02-20 08:24:32 -05:00
Peng Liu
9107ad41bb
Apply clang-format to bitset_test_cases.h to make PR#120807 cleaner
Applying this formatting per reviewer comment on PR #120807: https://github.com/llvm/llvm-project/pull/120807/files#r1961834956
2025-02-19 18:45:52 -05:00
Peng Liu
ad87d5f23d
[libc++][test] Refactor tests for std::{copy, move, fill} algorithms (#120909)
This refactor includes the following changes:
- Refactor similar tests using `types::for_each` to remove redundant code;
- Explicitly include the missing header `type_algorithms.h` in some test files;
- Some tests scattered in different test functions with ad-hoc names
  (e.g., `test5()`, `test6()`) but belong to the same kind are now grouped
  into one function (`test_struct_array()`).
2025-02-19 12:44:44 -05:00
Peng Liu
ab3d793982
[libc++] Optimize ranges::move{,_backward} for vector<bool>::iterator (#121109)
As a follow-up to #121013 (which optimized `ranges::copy`) and #121026
(which optimized `ranges::copy_backward`), this PR enhances the
performance of `std::ranges::{move, move_backward}` for
`vector<bool>::iterator`, addressing a subtask outlined in issue #64038.

The optimizations bring performance improvements analogous to those
achieved for the `{copy, copy_backward}` algorithms: up to 2000x for
aligned moves and 60x for unaligned moves. Moreover, comprehensive
tests covering up to 4 storage words (256 bytes) with odd and even bit
sizes are provided, which validate the proposed optimizations in this
patch.
2025-02-19 11:36:45 -05:00
Nikolas Klauser
3e61c1ab7f
[libc++] Avoid code duplication in strings operator+ overloads (#126048) 2025-02-19 10:52:01 -05:00
A. Jiang
7f69a399df
[libc++] Deprecate and remove member types of hash in <variant> (#127758)
These member types were deprecated in C++17 by P0174R2 and removed in
C++20 by P0619R4, but the changes in `<variant>` seem missing.

Drive-by: Replace one `_NOEXCEPT` with `noexcept` as the `hash`
specialization is C++17-and-later only.
2025-02-19 21:31:56 +08:00
Louis Dionne
2c8b124851
[libc++] Guard include of <features.h> with __has_include (#127691)
Some configurations define __AMDGPU__ or __NVPTX__ on platforms that
don't provide <features.h>, such as CUDA on Mac.
2025-02-19 08:21:56 -05:00
A. Jiang
2207e3e325
[libc++] Set feature-test macro __cpp_lib_atomic_float (#127559)
The corresponding feature was implemented in LLVM 18 (by #67799), but
this FTM wasn't added before.
2025-02-19 09:06:51 +08:00
Louis Dionne
3a00c428d9
[libc++] Add Hagenberg issues and papers to the Status pages (#127510)
Corresponding Github issues will be created shortly.
2025-02-18 15:09:39 -05:00
Louis Dionne
277512239a [libc++][NFC] Clarify libc++'s stance about implementing the Networking TS 2025-02-18 14:56:19 -05:00
Mark de Wever
f796747a17
[libc++][TZDB] Improves system time zone detection. (#127339)
On some (Linux) systems /etc/localtime is not a symlink to the time
zone, but contains a copy of the binary time zone file. In these case
there usually is a file named /etc/timezone which contains the text for
the current time zone name.

Instead of throwing when /etc/localtime does not exist or is not a
symlink use this fallback.

Fixes: #105634

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-02-18 19:28:16 +01:00
Mark de Wever
b22fc43551
[libc++] Updates the compilers used post LLVM-20 branching. (#126564)
Once LLVM 20 is released the clang-18 will no longer be supported.
2025-02-18 19:26:44 +01:00
Steven Cooreman
762001118c
[libc++] Do not guard inclusion of wchar.h with _LIBCPP_HAS_WIDE_CHARACTERS (#126924)
`mbstate_t` needs to be visible to libcpp, even when it is not providing
wide
character functionality (i.e. `_LIBCPP_HAS_WIDE_CHARACTERS` is turned
off)
and thus not using any of the C library's wide character functions.

There are C libraries (such as newlib-nano/nanolib/picolibc) which do
provide their definition of `mbstate_t` in `<wchar.h>` even though they
do not
come with wide character functions.

Since there is a way to conditionally include the C library's
`<wchar.h>`
only if it exists, we should rely on the fact that if it exists, it will
provide `mbstate_t`. Removing this guard will allow using libc++ on top
of
newlib-nano/picolibc while not breaking the cases where it is used on
top
of a C library which doesn't provide `<wchar.h>` (since it would then
still
go look for `<uchar.h>` or error out).
2025-02-18 12:12:23 +01:00
Louis Dionne
3fa85c7cce
[libc++] Document that libc++ does not and will never implement the Networking TS (#127508)
There has been discussion around this a few times already, and there
seemed to be consensus that we would never pursue an implementation of
the Networking TS. This patch solidifies that discussion by documenting
it and closing issues related to the Networking TS.

Closes #103799
Closes #100223
Closes #100228
Closes #100231
Closes #100232
2025-02-17 14:51:47 -05:00
Mark de Wever
941f7cbf5a
[libc++][TZDB] Fixes mapping of nonexisting time. (#127330)
All non-existing local times in a contiguous range should map to the
same time point. This fixes a bug, were the times inside the range were
mapped to the wrong time.

Fixes: #113654
2025-02-17 19:08:07 +01:00
Louis Dionne
ec54403522 [libc++] Synchronize a few remaining status page rows with Github issues 2025-02-17 10:26:10 -05:00
Louis Dionne
fb29f19fdb [libc++] Synchronize status pages with Github issues list 2025-02-17 10:16:56 -05:00
Un1q32
949e4041c9
[libc++] Add watchOS and tvOS checks for aligned_alloc (#126862)
Adds the equivalent watchOS and tvOS version checks to check for support
for aligned_alloc, we already have macOS and iOS checks.
2025-02-17 08:55:14 -05:00
Vitaly Buka
c6d95c441a
[libc++] Fix initialization-order-fiasco with iostream.cpp constructors (#126995)
Asan reports it after #124103.

It's know case of false positive for Asan.

https://github.com/google/sanitizers/wiki/AddressSanitizerInitializationOrderFiasco#false-positives

It's can be avoided with `constexpr` constructors.

In general order global constructors in different
modules is undefined. If global constructor uses
external global, they can be not constructed yet.

However, implementation may contain workaround for
that, or the state of non-constructed global can
be still valid.

Asan will still falsely report such cases, as it
has no machinery to detect correctness of such
cases.

We need to fix/workaround the issue in libc++, as
it will affect many libc++ with Asan users.
2025-02-15 19:54:23 -08:00
Mark de Wever
248716f814
[libc++] Fixes (|multi)_set spaceship operator. (#127326)
The operators did not have a _Compare template arguement. The fix
updates the generic container test to use allocators for all types used.
No other issues were found.

Fixes: #127095
2025-02-15 20:15:32 +01:00
Nikolas Klauser
2472d38338
[libc++] Move unused basic_string function definition to the dylib sources (#126219)
`__init(const value_type*, size_type, size_type)` is part of our ABI,
but we don't actually use the function anymore in the dylib. THis moves
the definition to the `src/` directory to make it clear that the code is
unused. This also allows us to remove it entirely in the unstable ABI.
2025-02-15 20:11:48 +01:00
Louis Dionne
a6093d3034
[libc++] Explicitly mention vector_bool in the name of benchmarks (#127313)
We have some benchmarks that were benchmarking very specific
functionality, namely the optimizations in vector<bool>::iterator. Call
this out in the benchmarks by renaming them appropriately. In the future
we will also increase the coverage of these benchmarks to test other
containers.
2025-02-15 14:56:19 +01:00
Louis Dionne
cffc1ac349
[libc++] Avoid including <features.h> on arbitrary platforms (#125587)
This partially reverts commit 5f2389d4. That commit started checking
whether <features.h> was a valid include unconditionally, however codebases
are free to have such a header on their search path, which breaks compilation.
LLVM libc now provides a more standard way of getting configuration macros
like __LLVM_LIBC__.

After this patch, we only include <features.h> when we're on Linux or
when we're compiling for GPUs.
2025-02-15 10:54:00 +01:00
Nikolas Klauser
4887e41055
[libc++][NFC] Make enable_ifs in <optional> consistent (#127184)
We've documented the preferred `enable_if` style in the coding
guidelines. This updates `<optional>` to conform to them
2025-02-15 10:38:59 +01:00
Mark de Wever
04bf00c7c4 [NFC][libc++][format] Fixes comment typos. 2025-02-14 18:37:59 +01:00
Mark de Wever
fbd92d0985
[libc++][format] Disables the FTM on older MacOS versions. (#126547)
On older MacOS versions where `std::to_chars` for floating-point types
is not available the format library can't be used. Due to some issue
with the availability macro used to disable format on MacOS the issue
triggers regardless of the type being formatted.

The print library has the same issue.

Fixes: #125353
2025-02-14 18:27:54 +01:00
Hristo Hristov
e52ad499ff
[libc++][NFC] Add reminder to remove _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER macro (#127070)
`__cpp_explicit_this_parameter` has been set in LLVM20
https://github.com/llvm/llvm-project/pull/107451 /
72e58e00c2

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-02-14 16:02:13 +02:00
Nikolas Klauser
55b0fde20a
[libc++][NFC] Simplify unique_ptr a bit (#121230) 2025-02-14 10:08:23 +01:00
Alex Bradbury
db2953d801
[doc] Add Discord invite link alongside channel links (#126352)
By far the most important part of this patch is updating
GettingInvolved.rst to include the invite link, but I've grepped for any
other discord.com links.

I'm no Discord expert, but from my experience (confirmed via @preames
kindly testing as well) the direct channel links provide a confusing
experience if you haven't already found and used an invite link to the
LLVM Discord server. If you're logged into Discord but not a member of
LLVM's sever, the web app opens and then...nothing. No channel opens, no
prompt to join the server or even a hint that you need to find an invite
link (and if you're not used to Discord, you likely don't even know
that's necessary).

This patch addresses the issue by providing the invite link where
Discord is mentioned.
2025-02-13 15:00:21 +00:00
Takuto Ikuta
0761841bc0
[libcxx] Add a missing include for __enable_if_t (#127016)
This is to fix compile error with explicit Clang modules like
```
../../third_party/libc++/src/include/__filesystem/path.h:80:26: error: declaration of '__enable_if_t' must be imported from module 'std_core.type_traits.enable_if' before it is required
   80 | template <class _ECharT, __enable_if_t<__can_convert_char<_ECharT>::value, int> = 0>
      |                          ^
../../third_party/libc++/src/include/__type_traits/enable_if.h:34:1: note: declaration here is not visible
   34 | using __enable_if_t _LIBCPP_NODEBUG = typename enable_if<_Bp, _Tp>::type;
      | ^
```
2025-02-13 08:54:56 +01:00
Takuto Ikuta
672e3858a4
[libcxx] Add a missing include for __bit_iterator (#127015)
This is to fix compile error with explicit Clang modules like
```
../../third_party/libc++/src/include/__vector/vector_bool.h:85:11: error: default argument of '__bit_iterator' must be imported from module 'std.bit_reference_fwd' before it is required
   85 |   typedef __bit_iterator<vector, false> pointer;
      |           ^
../../third_party/libc++/src/include/__fwd/bit_reference.h:23:68: note: default argument declared here is not reachable
   23 | template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
      |                                                                    ^
```
2025-02-13 08:54:43 +01:00
Louis Dionne
5953e5a3c6
[libc++] Simplify the apple-system-hardened CI configuration (#126911)
It was basically a copy-paste of the non-hardened version of the same
job, and it's easy to remove the duplication.
2025-02-12 23:58:14 +01:00
Louis Dionne
dbfb29fd45
[libc++] Add a link to __builtin_verbose_trap from the hardening docs (#126930) 2025-02-12 23:57:37 +01:00
Nikolas Klauser
b101c35bc7
[libc++] Remove conditional for attributes that are always available (#126879)
These attributes are available in all supported compilers, so the
`#else` case of the conditional is dead code.
2025-02-12 13:48:54 +01:00
Louis Dionne
39f0f0a21b
[libc++] Remove obsolete guards for join_view being experimental (#126697)
These TODOs were forgotten when join_view was made non-experimental. By
removing these checks, we slightly increase the coverage of the test
suite.
2025-02-12 09:44:49 +01:00
Mark de Wever
c4fe4561c7 [libc++] Fixes building with Python 3.8.
This addresses the post-commit issues reported in #101880.
2025-02-11 20:08:12 +01:00
Louis Dionne
2d66ab5e8e
[libc++][NFC] Run the container tests through clang-format (#126499)
We've been improving these the tests for vector quite a bit and we are
probably not done improving our container tests. Formatting everything
at once will make subsequent reviews easier.
2025-02-11 06:17:39 +01:00
A. Jiang
998f2422a5
[libc++][test] Fixes for hash<Emplaceable> and value discarding (#126566)
Currently `std::hash<Emplaceable>::operator()` relies implicit
conversion from `int` to `size_t`, which makes MSVC compelling. This PR
switches to use `static_cast`.

In `flat.map/flat.map.access/at_transparent.pass.cpp`, there's one
value-discarding use of `at` that wasn't marked `TEST_IGNORE_NODISCARD`.
This PR adds the missing `TEST_IGNORE_NODISCARD`.
2025-02-11 07:56:53 +08:00
Joseph Huber
3d9409f5bc
[NVPTX] Make ctor/dtor lowering always enabled in NVPTX (#126544)
Summary:
Currently we conditionally enable NVPTX lowering depending on the
language (C/C++/OpenMP). Unfortunately this causes problems because this
option is only present if the backend was enabled, which causes this to
error if you try to make LLVM-IR.

This patch instead makes it the only accepted lowering. The reason we
had it as opt-in before is because it is not handled by CUDA. So, this
pach also introduces diagnostics to prevent *all* creation of
device-side global constructors and destructors. We already did this for
variables, now we do it for attributes as well.

This inverts the responsibility of blocking this from the backend to the
langauage like it should be given that support for this is language
dependent.
2025-02-10 14:25:44 -06:00
Louis Dionne
f332455dd9
[libc++] Extract destroy algorithms into separate headers (#126449)
This patch separates the destroy algorithms from the primitive
construct_at and destroy_at operations, which are conceptually not
algorithms. This makes it easier to start using these destroy algorithms
from upcoming relocation facilities.

As part of this, it also implements `std::destroy_at` for arrays without
relying on the `std::destroy` algorithm, which is conceptually a
higher-level facility.
2025-02-10 21:19:46 +01:00
Mark de Wever
b319dfef21
[libc++][CI] Updates Clang HEAD version in Docker. (#126419)
This is a preparation to test Clang 21 in the CI,

Drive-by: Updated some outdated documentation.
2025-02-10 18:08:24 +01:00
Mark de Wever
5b9e6c7993
[libc++] Improves type-safety in generator script. (#101880)
This changes the code to use dataclasses instead of dict entries. It
also adds type aliases to use in the typing information and updates the
typing information.
2025-02-10 18:03:44 +01:00
Mark de Wever
cb1b51f4ff [libc++][doc] Updates format status. 2025-02-09 15:11:13 +01:00
Mark de Wever
8a4707bf1d [NFC][libc++] Fixes minor issues in the synopsis. 2025-02-09 15:08:30 +01:00
A. Jiang
51ba9819b4
[libc++][test] Fix size_type issues with MinSequenceContainer and min_allocator (#126267)
`MinSequenceContainer::size` can be narrowing on 64-bit platforms, and
MSVC complains about such implicit conversion. This PR changes the
implicit conversion to explicit `static_cast`.

`min_allocator::allocate` and `min_allocator::deallocate` have
`ptrdiff_t` as the parameter type, which seems weird, because the
underlying `std::allocator`'s member functions take `size_t`. It seems
better to use `size_t` consistently.
2025-02-08 09:26:59 +08:00
Louis Dionne
27598aba49
[libc++] Further refactor sequence container benchmarks (#126129)
This patch does not significantly change how the sequence container
benchmarks are done, but it adopts the same style as the associative
container benchmarks.

This commit does adjust how we were benchmarking push_back, where we
never really measured the overhead of the slow path of push_back (when
we need to reallocate).
2025-02-07 09:56:45 -05:00
Nikolas Klauser
0227396417 Revert "[libc++] Reduce std::conjunction overhead (#124259)"
It turns out that the new implementation takes significantly more stack
memory for some reason.

This reverts commit 2696e4fb9567d23ce065a067e7f4909b310daf50.
2025-02-07 15:50:17 +01:00