6982 Commits

Author SHA1 Message Date
Louis Dionne
b3a4bf9d8f
[libc++] Refactor and add benchmarks from [alg.nonmodifying] (#128206) 2025-03-19 00:08:46 -04:00
A. Jiang
854a4f2bbb
[libc++] Implement part of P2562R1: constexpr std::inplace_merge (#129008)
Drive-by:
- Adds `constexpr_random.h` for pseudo-randomizing or shuffling in tests
for constant evaluation.
2025-03-19 07:42:23 +08:00
Mark de Wever
9feac2cbd0 [libc++] Improve deprecated diagnostic guards.
Recent Clang-21 builds improved the deprecated diagnotics. This
uncovered missing guards in libc++ internally.

Note: This patch should be a separate commit and not merged.
For testing purposes they are combined.

Reviewed as part of #130497.
2025-03-18 18:30:48 +01:00
Mark de Wever
b271b44158
[libc++] Guard call_once against operator hijacking. (#128054) 2025-03-18 18:06:24 +01:00
Louis Dionne
428b320bf3
[libc++] Fix allocate_at_least test that assumes the size_type of the allocator (#131682)
If the size_type of the allocator is not the same as std::size_t, this
test would fail.
2025-03-18 08:55:43 -04:00
Alexander Kornienko
d1156fcb56
Revert "[libc++] Optimize num_put integral functions" (#131613)
Reverts llvm/llvm-project#120859

This change breaks formatting of `0` with `std::showbase` + `std::hex`
or `std::oct`, as well as `+0` with `std::showpos`. I believe the new
behavior is violating the standard. See
https://github.com/llvm/llvm-project/pull/120859#issuecomment-2723970242
and later comments for details and explanation.
2025-03-18 02:05:51 +01:00
Louis Dionne
5b9006550d [libc++][NFC] Fix incorrect main() signatures 2025-03-17 18:02:40 -04:00
Louis Dionne
24e88b0e6b
[libc++] Add remaining benchmarks from [alg.modifying.operations] (#127354)
This patch adds benchmarks for all the remaining algorithms in
[alg.modifying.operations] that we didn't already have a benchmark for.
2025-03-17 15:11:13 -04:00
Mark de Wever
9829d457ae
[libc++][test] Adds a test for a reserved name. (#131363)
This was discovered when using this name in #130500.
2025-03-16 15:37:47 +01:00
Hristo Hristov
f7cab64684
[libc++][numeric][NFC] Cleanup *Saturation arithmetic* tests (#101826)
This simplifies the tests a little bit:

Fixed -> TODO(LLVM20): remove [[maybe_unused]] and `{}` scope since all
supported compilers support "Placeholder variables with no name"

*IMPORTANT: Requires Apple Clang with [P2169R4: A nice placeholder with
no name](https://wg21.link/P2169R4)*

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-03-16 11:31:35 +08:00
A. Jiang
5cc2ae0b51
[libc++][test] Skip a is_virtual_base_of test for apple-clang-17 (#131438)
It seems that Apple Clang 17 starts to be used for CI, while it hasn't
supported `__builtin_is_virtual_base_of` yet. And thus we need to skip
the test for `is_virtual_base_of`.

Follows up #131302.
2025-03-15 21:07:53 +08:00
A. Jiang
999700ca47
[libc++][test] Skip some is_implicit_lifetime tests for apple-clang-17 (#131302)
The skipping was present before but dropped. At the time it was dropped
in #128649, apple-clang-17 wasn't used for CI. But today it is used at
least for the "macos (generic-cxx23, macos-15)" configuration. So I
think we need to skip apple-clang-17 again.
2025-03-15 00:08:20 +08:00
Peng Liu
3bd71cbec7
[libc++] Fix ambiguous call in {ranges, std}::find (#122641)
This PR fixes an ambiguous call encountered when using the `std::ranges::find` or `std::find`
algorithms with `vector<bool>` with small `allocator_traits::size_type`s, an issue reported
in #122528. The ambiguity arises from integral promotions during the internal bitwise
arithmetic of the `find` algorithms when applied to `vector<bool>` with small integral
`size_type`s. This leads to multiple viable candidates for small integral types:
__libcpp_ctz(unsigned), __libcpp_ctz(unsigned long), and __libcpp_ctz(unsigned long long),
none of which represent a single best viable match, resulting in an ambiguous call error.

To resolve this, we propose invoking an internal function __countr_zero as a dispatcher
that directs the call to the appropriate overload of __libcpp_ctz. Necessary amendments
have also been made to __countr_zero.
2025-03-13 14:15:03 -04:00
Peng Liu
4baf1c03fa
[libc++] Optimize ranges::rotate for vector<bool>::iterator (#121168)
This PR optimizes the performance of `std::ranges::rotate` for
`vector<bool>::iterator`. The optimization yields a performance
improvement of up to 2096x.

Closes #64038.
2025-03-13 14:07:23 -04:00
Austin
9d7ca6cdf0
[regex] fix uncaught exception when string is like "\\_" (#129348)
`\_ `is a valid identity escape in regular expressions, but previously
libc++ incorrectly treated it as invalid. So I deleted this judgment
fixes #129062
2025-03-11 09:12:14 +08:00
Damien L-G
e235432867
[libc++] Add -Watomic-memory-ordering diagnostic tests for atomic_ref (#130206)
Fix #130053
2025-03-10 16:32:13 -04:00
AdityaK
deb4b20662
[NFC][libcxx][test] clang-format: search.pass.cpp (#130551) 2025-03-10 11:21:09 -07:00
Kadir Cetinkaya
f059e58702
Revert "[libc++] Don't try to wait on a thread that hasn't started in std::async (#125433)"
This reverts commit 11766a40972f5cc853e296231e5d90ca3c886cc1.
2025-03-10 15:13:41 +01:00
Hristo Hristov
6d9dfd75e4
[libc++][type_traits] Implements "A type trait to detect reference binding to temporary" (#128649)
Implements partially: [P2255R2: A type trait to detect reference binding
to temporary](https://wg21.link/P2255R2)
Issue: https://github.com/llvm/llvm-project/issues/105180

https://eel.is/c++draft/meta.type.synop
https://eel.is/c++draft/meta.unary.prop

Implented type traits:
- [x] `reference_constructs_from_temporary`
- [x] `reference_converts_from_temporary`

Closes #129049

Minor drive-by tweak to `std::is_implicit_lifetime` tests.

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-03-08 15:20:56 +01:00
A. Jiang
94714fb303
[libc++] Deprecate is_pod(_v) since C++20 (#129471)
Previously, commit 042f07eed8c1acba19ea04310137bee12b18045a claimed that
P0767R1 was implemented in LLVM 7.0, but no deprecation warning was
implemented. This patch adds the missing warnings.
2025-03-07 16:02:57 +08:00
A. Jiang
ba9aeedf8e
[libc++] Implement part of P2562R1: constexpr ranges::stable_sort (#128860)
Drive-by: Enables test coverage for `ranges::stable_sort` with proxy
iterators, and changes "constexpr in" to "constexpr since" in comments
in `<algorithm>`.
2025-03-07 01:27:48 +08:00
A. Jiang
27e686c788
[libc++] Verify that LWG4140 is implemented (#128624)
According to the commit history, the constructors removed by LWG4140
have never been added to libc++.

Existence of non-public or deleted default constructor is observable,
this patch tests that there's no such default constructor at all.
2025-03-06 11:12:17 +08:00
A. Jiang
c28c508962
[libc++] Implement part of P2562R1: constexpr ranges::stable_partition (#129839) 2025-03-06 09:23:55 +08:00
Nikolas Klauser
15edf8725a
[libc++] Optimize num_put integral functions (#120859)
```
-------------------------------------------------------
Benchmark                              old          new
-------------------------------------------------------
BM_num_put<bool>                   76.2 ns      32.0 ns
BM_num_put<long>                   76.9 ns      33.1 ns
BM_num_put<long long>              77.9 ns      34.2 ns
BM_num_put<unsigned long>          78.4 ns      33.1 ns
BM_num_put<unsigned long long>     78.0 ns      34.4 ns
BM_num_put<double>                  224 ns       228 ns
BM_num_put<long double>             239 ns       230 ns
BM_num_put<const void*>            68.7 ns      35.1 ns
```

Fixes #40109.
2025-03-05 14:18:49 +01:00
A. Jiang
e739ce2e10
[libc++] Add missed constexpr to erase(_if) in <string> (#129666)
`std::erase(_if)` for `basic_string` were made `constexpr` in C++20 by
cplusplus/draft@2c1ab9775c as follow-up
changes of P0980R1.

This patch implements the missed changes that were not tracked in a
specific paper.
2025-03-05 08:31:28 +08:00
Peng Liu
a12744ff05
[libc++] Optimize ranges::swap_ranges for vector<bool>::iterator (#121150)
This PR optimizes the performance of `std::ranges::swap_ranges` for
`vector<bool>::iterator`, addressing a subtask outlined in issue #64038.
The optimizations yield performance improvements of up to **611x** for
aligned range swap and **78x** for unaligned range swap comparison.
Additionally, 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-03-04 17:15:36 -05:00
A. Jiang
bf9bf291a3
[libc++] Implement part of P2562R1: constexpr std::stable_partition (#128868)
Drive-by changes:
- Enables no-memory case for Clang.
- Enables `robust_re_difference_type.compile.pass.cpp` and
`robust_against_proxy_iterators_lifetime_bugs.pass.cpp` test coverage
for `std::stable_sort` in constant evaluation since C++26. The changes
were missing in the PR making `std::stable_sort` `constexpr`.
2025-03-04 09:23:29 +08:00
A. Jiang
5bf1f03d1f
[libc++] Fix assignment in insertion into vector (#116001)
Changes:
- Avoid direct assignment in iterator-pair `insert` overload and
`insert_range`, except when the assignment is move assignment.
2025-03-04 09:06:49 +08:00
Paul Osmialowski
8f4ee42d59
[libc++][test] extend XFAIL clauses to cover Amazon Linux too (#129377)
The default triple of Amazon Linux on AArch64 is aarch64-amazon-linux,
see issue highlighded by PR #109263, somewhat serious linker issues are
encountered if any other triple is being used.

Unfortunately, this makes XFAIL lines like
`XFAIL: target=aarch64{{.*}}-linux-gnu` ineffective, making it
impossible to complete all of the check-cxx on Amazon Linux without
failing.
2025-03-03 18:10:36 +00:00
A. Jiang
ca0612c383
[libc++] Fix money_get::do_get with huge input (#126273)
`money_get::do_get` needs to be fixed to handle extremely huge input
(e.g. more than 100 digits).
1. `__double_or_nothing` needs to copy the contents of the stack buffer
on the initial allocation.
2. The `sscanf` call in `do_get` needs to scan the dynamic buffer if
dynamic allocation happens.
2025-03-03 07:13:38 +08:00
Mark de Wever
376ffec876
[libc++][format] Enables formattable tests for chrono formatters. (#128356)
These were forgotten when these types were implemented.
2025-03-02 18:36:27 +01:00
A. Jiang
f5f5286da3
[libc++] Implement LWG3990 for Clang (#128834)
This patch adds `[[_Clang::__no_specializations__]]` to `tuple`, with
warning/error suppressed for `tuple<>`.
2025-03-02 23:00:08 +08:00
A. Jiang
fa5db05ca3
[libc++][test] XFAIL for FreeBSD in thread_create_failure.pass.cpp (#129413)
Per https://man.freebsd.org/cgi/man.cgi?query=setrlimit, FreeBSD's
`setrlimit` seems to limit the number of processes, not threads via
`RLIMIT_NPROC`. So this test should be XFAIL for FreeBSD.
2025-03-02 11:35:22 +01:00
AdityaK
4a8412d430
[libc++] Add tests for gcd that result in something other than zero or one (#129395)
@colincross identified gcd does not have a single case whose answer is
not 0, 1, or the smaller of the two inputs.
2025-03-02 11:33:59 +01:00
Mark de Wever
d2b09e21bc
[libc++] Prohibits initializer_list specializations. (#128042)
This relies on Clang's no_specializations attribute which is not
supported by GCC.

Implements:
- LWG2129: User specializations of std::initializer_list

Fixes: #126270
2025-03-01 12:34:35 +01:00
Mark de Wever
65f105b6cf
[libc++] Implements LWG3600 Making istream_iterator copy constructor trivial is an ABI break (#127343)
Closes: #105003
2025-03-01 12:29:21 +01:00
Martin Storsjö
f909b2229a
[libcxx] Provide locale conversions to tests through lit substitution (#105651)
There are 2 problems today that this PR resolves:

libcxx tests assume the thousands separator for fr_FR locale is x00A0 on
Windows. This currently fails when run on newer versions of Windows (it
seems to have been updated to the new correct value of 0x202F around
windows 11. The exact windows version where it changed doesn't seem to
be documented anywhere). Depending the OS version, you need different
values.

There are several ifdefs to determine the environment/platform-specific
locale conversion values and it leads to maintenance as things change
over time.

This PR includes the following changes:

- Provide the environment's locale conversion values through a
  substitution. The test can opt in by placing the substitution value in a
  define flag.
- Remove the platform ifdefs (the swapping of values between Windows,
  Linux, Apple, AIX).

This is accomplished through a lit feature action that fetches the
environment's locale conversions (lconv) for members like
'thousands_sep' that we need to provide. This should ensure that we
don't lose the effectiveness of the test itself.

In addition, as a result of the above, this PR:

- Fixes a handful of locale tests which unexpectedly fail on newer
  Windows versions.
- Resolves 3 XFAIL FIX-MEs.

Originally submitted in https://github.com/llvm/llvm-project/pull/86649.

Co-authored-by: Rodrigo Salazar <4rodrigosalazar@gmail.com>
2025-02-28 23:43:46 +02:00
Paul Osmialowski
c363975da4
Revert "[libc++][test] extend -linux-gnu XFAIL to cover all of the -linux targets (#129140)" (#129271)
The effect of this commit is too broad and may affect also those
variants of Linux systems on which the affected test cases are known to
pass.

An alternative version of this commit will be prepared afresh.

This reverts commit c93dc581d979eb20ded470d2c16e51b3e775f6e7.
2025-02-28 15:58:37 -05:00
Louis Dionne
037cf12b07
[libc++] Mark _XOPEN_SOURCE test as unsupported on FreeBSD (#128950)
The test otherwise fails on FreeBSD, which wasn't noticed when
originally landing the patch that added the test because FreeBSD
CI was disabled at that moment.
2025-02-28 09:58:49 -05:00
Paul Osmialowski
c93dc581d9
[libc++][test] extend -linux-gnu XFAIL to cover all of the -linux targets (#129140)
The default triple of Amazon Linux on AArch64 is aarch64-amazon-linux,
see issue highlighded by PR #109263, somewhat serious linker issues are
encountered if any other triple is being used.

Unfortunately, this makes XFAIL lines like:
`XFAIL: target=aarch64{{.*}}-linux-gnu` ineffective,
making it impossible to complete all of the check-cxx without failures.
2025-02-28 10:54:08 +00:00
Nikolas Klauser
f896bd3670
[libc++] Diagnose when nullptrs are passed to string APIs (#122790)
This allows catching misuses of APIs that take a pointer to a
null-terminated string.
2025-02-27 22:57:19 +01:00
elhewaty
2c36411ed2
[libcxx] Add LWG4135: The helper lambda of std::erase for list should specify return type as bool (#128358)
Fixes https://github.com/llvm/llvm-project/issues/118355
2025-02-26 22:13:27 +02:00
Peng Liu
7717a549e9
[libc++] Optimize ranges::equal for vector<bool>::iterator (#121084)
This PR optimizes the performance of `std::ranges::equal` for
`vector<bool>::iterator`, addressing a subtask outlined in issue #64038.
The optimizations yield performance improvements of up to 188x for
aligned equality comparison and 82x for unaligned equality
comparison. 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-26 12:18:25 -05:00
Peng Liu
f161b1b526
[libc++][test] Refactor tests for rotate and rotate_copy (#126458)
This PR refactors the tests and fix some problems:  
- Refactor similar tests using `types::for_each` to remove redundant code;
- Explicitly include the missing header `type_algorithms.h` instead of relying
  on a transitive include;
- Fix the incorrect constexpr declaration in `rotate.pass.cpp`, where
  the `test()` function is incorrectly defined as `TEST_CONSTEXPR_CXX17`,
  which is wrong since `std::rotate()` becomes constexpr only since C++20.
2025-02-26 11:57:57 -05:00
Mark de Wever
26be07b851
[libc++][format] Disables narrow string to wide string formatters. (#128355)
Implements LWG3944: Formatters converting sequences of char to sequences
of wchar_t

Fixes: #105342
2025-02-26 17:54:18 +01:00
Mark de Wever
a841cf91b3
[lib++][print] Don't pad the ostream output. (#128354)
Per [ostream.formatted.reqmts]/3 padding should only be done when
explicitly stated.

Fixes: #116054
2025-02-26 17:53:26 +01:00
Peng Liu
ffc5d2b5d4
[libc++][test] Refactor tests for ranges::swap_range algorithms (#121138)
This PR refactors tests for `ranges::swap_range`, `std::{swap_range,
iter_swap, swap}` algorithms to eliminate redundant code.
2025-02-26 11:49:19 -05:00
Peng Liu
1d583ed2fb
[libc++][test] Augment ranges::{fill, fill_n, find} with missing tests (#121209)
libc++ currently has very limited test coverage for `std::ranges{fill, fill_n, find}`
with `vector<bool>::iterator` optimizations. Specifically, the existing tests for
`std::ranges::fill` only covers cases of 1 - 2 bytes, which is merely 1/8 to 1/4
of the `__storage_type` word size. This renders the tests insufficient to validate
functionality for whole words, with or without partial words (which necessitates at
least 8 bytes of data). Moreover, no tests were provided for `ranges::{find, fill_n}`
with `vector<bool>::iterator` optimizations. This PR fills in the gap.
2025-02-26 11:38:15 -05:00
Peng Liu
56379b2904
Simplify flip() for std::bitset (#120807)
This PR simplifies the internal bitwise logic of the `flip()` function
for `std::bitset`.
2025-02-26 15:33:57 +01:00
Thurston Dang
5e4938a991
Exclude hwasan from thread_create_failure.pass.cpp (#128768)
Fixes hwasan buildbot failure

(https://lab.llvm.org/buildbot/#/builders/55/builds/7536/steps/10/logs/stdio)
introduced in https://github.com/llvm/llvm-project/pull/125433 by
excluding this test for hwasan, similar to the existing exclusion of
asan.
2025-02-25 12:18:07 -08:00