6968 Commits

Author SHA1 Message Date
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
Nikolas Klauser
43401dd0b5
[libc++] Make .verify.cpp tests more robust against changing headers (#128703)
This is fixes the tests for the frozen headers, but is an improvement
either way.
2025-02-25 18:02:34 +01:00
Nikolas Klauser
11766a4097
[libc++] Don't try to wait on a thread that hasn't started in std::async (#125433)
If the creation of a thread fails, this causes an idle loop that will
never end because the thread wasn't started in the first place.

Fixes #125428
2025-02-25 13:33:17 +01:00
Nikolas Klauser
674dbcfe8f [libc++][NFC] Use TEST_STD_VER instead of _LIBCPP_STD_VER in re.tokiter.comp/equal.pass.cpp 2025-02-25 10:08:37 +01:00
Nikolas Klauser
15860446a8
[libc++] Fix basic_string not allowing max_size() elements to be stored (#125423)
Without this patch `basic_string` cannot be properly resized to be
`max_size()` elements in size, even if an allocation is successful.
`__grow_by` allocates one less element than required, resulting in an
out-of-bounds access. At the same time, `max_size()` has an off-by-one
error, since there has to be space to store the null terminator, which
is currently ignored.
2025-02-23 19:02:14 +01:00
Peng Liu
31824b2a11
[libc++] Fix shrink_to_fit to swap buffer only when capacity is strictly smaller (#127321)
The current implementation of the `shrink_to_fit()` function of
`basic_string` swaps to the newly allocated buffer when the new buffer
has the same capacity as the existing one. While this is not incorrect,
it is truly unnecessary to swap to an equally-sized buffer. With equal
capacity, we should keep using the existing buffer and simply deallocate
the new one, avoiding the extra work of copying elements.

The desired behavior was documented in the following comment within the
function:


61ad08792a/libcxx/include/string (L3560-L3566)

However, the existing implementation did not exactly conform to this
guideline, which is a QoI matter.

This PR modifies the `shrink_to_fit()` function to ensure that the
buffer is only swapped when the new allocation is strictly smaller than
the existing one. When the capacities are equal, the new buffer will be
discarded without copying the elements. This is achieved by including
the `==` check in the above conditional logic.
2025-02-22 14:50:48 +01:00
Damien L-G
affbb4d9cf
[libc++] std::atomic primary template should not have a difference_type member type (#123236)
The test would not check its absence and the code path intended for
pointer was never actually instantiated.
I added a few pointer types since there was no coverage.

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-02-21 12:53:11 -05:00
Mark de Wever
cf50936b23
[libc++][chrono] implements GPS clock. (#125921)
Completes:
- LWG3359 <chrono> leap second support should allow for negative leap
seconds
- P1361R2 Integration of chrono with text formatting

Implements parts of:
- P0355 Extending <chrono> to Calendars and Time Zones

Fixes: #100432
Fixes: #100014
2025-02-21 17:50:01 +01:00
Louis Dionne
aa6d3ff80d
[libc++] Re-enable the FreeBSD CI job (#127687)
Technical issues have apparently been resolved and the node should be
back online.

Closes #117780
2025-02-21 11:38:23 -05:00
Louis Dionne
5e26fb1699
[libc++] Qualify calls to nullary functions like __throw_foo (#122465)
This is technically not necessary in most cases to prevent issues with ADL,
but let's be consistent. This allows us to remove the libcpp-qualify-declval
clang-tidy check, which is now enforced by the robust-against-adl clang-tidy check.
2025-02-21 07:59:46 -05: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