4477 Commits

Author SHA1 Message Date
Louis Dionne
9474e09459
[libc++] Granularize the <new> header (#119270)
This disentangles the code which previously had a mix of many #ifdefs, a
non-versioned namespace and a versioned namespace. It also makes it
clearer which parts of <new> are implemented on Windows by including <new.h>.
2024-12-13 14:17:56 -05:00
Louis Dionne
62bdb85f9b [libc++][NFC] Fix incorrect comment for vector::assign(iter, iter) test 2024-12-13 09:35:56 -05:00
Stephan T. Lavavej
cb4433b677
[libcxx][test] Silence nodiscard warnings for std::expected (#119174)
I'm exploring marking microsoft/STL's std::expected as [[nodiscard]],
which affects all functions returning std::expected, including its
own monadic member functions.

As usual, libc++'s test suite contains calls to these member functions
to make sure they compile, but it's discarding the returns. I'm adding
void casts to silence the [[nodiscard]] warnings without altering
what the test is covering.
2024-12-10 07:23:09 -05:00
Hui
f22ecdd9b9
[libc++] Move out flat_map::iterator (for reusing it in flat_multimap) (#117445) 2024-12-09 09:22:27 -05:00
Louis Dionne
6cb339f9c1
[libc++] Refactor tests for aligned allocation and sized deallocation (#117915)
This patch refactors the tests around aligned allocation and sized
deallocation to avoid relying on passing the -fsized-deallocation or
-faligned-allocation flags by default. Since both of these features are
enabled by default in >= C++14 mode, it now makes sense to make that
assumption in the test suite.

A notable exception is MinGW and some older compilers, where sized
deallocation is still not enabled by default. We treat that as a "bug"
in the test suite and we work around it by explicitly adding
-fsized-deallocation, but only under those configurations.
2024-12-06 16:12:30 -05:00
Louis Dionne
cd74ebaec6
[libc++] Make a few test helper constructors explicit (#118975) 2024-12-06 15:31:20 -05:00
Peng Liu
37797d3e80
[libc++][test] Fix and refactor exception tests for std::vector constructors (#117662)
The existing exceptions tests for `vector<T>` have several issues: some
tests did not throw exceptions at all, making them not useful for
exception-safety testing, and some tests did not throw exceptions at the
intended points, failing to serve their expected purpose. This PR fixes
those tests for vector's constructors. Morever, this PR extracted common
classes and utilities into a separate header file, and renamed those
classes using more descriptive names.
2024-12-06 09:03:17 -05:00
serge-sans-paille
f7ff3cde96
[libc++] Fix sub-overflow in std::gcd implementation (#117984)
Fix #117249
2024-12-06 07:57:49 +00:00
Peng Liu
a821937b6d
[libc++][test] Refactor increasing_allocator (#115671)
The increasing_allocator<T> class, originally introduced to test shrink_to_fit()
for std::vector, std::vector<bool>, and std::basic_string, has duplicated
definitions across several test files. Given the potential utility of this
class for capacity-related tests in various sequence containers, this patch
refactors the definition of increasing_allocator<T> into a single, reusable
location.
2024-12-05 15:44:05 -05:00
Peng Liu
c5cd1e958c
[libc++] Add exception guard for vector<bool>::__init_with_sentinel (#115491)
As a drive-by, also improve the test coverage for throwing exceptions
in vector<bool> constructors.
2024-11-28 09:09:54 -05:00
Peng Liu
5ce981e76d
[libc++] Refactor vector move constructor with allocator (#116449)
This PR simplifies the implementation of std::vector's move constructor
with an alternative allocator by invoking __init_with_size() instead of
calling assign(), which ultimately calls __assign_with_size(). The
advantage of using __init_with_size() lies in its internal use of
an exception guard, which simplifies the code. Furthermore, from a
semantic standpoint, it is more intuitive for a constructor to call
an initialization function than an assignment function.
2024-11-26 16:00:14 -05:00
Louis Dionne
44ef12b020
[libc++] Refactor tests for hijacked address operator in vector (#117457)
This reduces the amount of boilerplate needed to implement the tests.
2024-11-26 14:33:56 -05:00
vannem-sj
c7d5ef420d
[libc++] Rename operator[].pass.cpp to subscript_operator.pass.cpp (#117216)
This filename includes non FAT32 legal characters, and has caused a few
issues with glob tools that don't escape brackets properly.
2024-11-22 15:49:09 +01:00
Louis Dionne
a9882bda96
[libc++] Mark charconv test as unsupported under msan (#116933) 2024-11-22 09:05:08 +01:00
Nikolas Klauser
9ebc6f5d6d
[libc++] Include headers in <thread> conditionally (#116539) 2024-11-20 23:07:20 +01:00
Ryan Prichard
8f53a67bb8
[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
The Android clang-r536225 compiler identifies as Clang 19, but it is
based on commit fc57f88f007497a4ead0ec8607ac66e1847b02d6, which predates
the official LLVM 19.0.0 release.

Some tests need fixes:

* The sized delete tests fail because clang-r536225 leaves sized
deallocation off by default.

* std::array<T[0]> is true when this Android Clang version is used with
a trunk libc++, but we expect it to be false in the test. In practice,
Clang and libc++ usually come from the same commit on Android.
2024-11-20 14:06:58 -08:00
Nikolas Klauser
01a1ca72e8 [libc++][NFC] Format a pait test
I'll be modifying this test in a future PR.
2024-11-19 13:53:43 +01:00
Louis Dionne
3a3517c5e9
[libc++] Improve the tests for vector::erase (#116265)
In particular, test everything with both a normal and a min_allocator,
add tests for a few corner cases and add tests with types that are
trivially relocatable. Also add tests that count the number of
assignments performed by vector::erase, since that is mandated by the
Standard.

This patch is a preparation for optimizing vector::erase.
2024-11-19 00:49:22 +01:00
Nikolas Klauser
85ef9666c8
[libc++] Avoid including all of <thread> in <future> (#116541) 2024-11-18 20:04:05 +01:00
Nikolas Klauser
1636580b0a
[libc++] Avoid including <ostream> in <fstream> and <strstream> (#116014)
This reduces the include time of `<fstream>` from ~800ms to ~500ms.
2024-11-16 18:19:17 +01:00
Louis Dionne
2d6459cb28
[libc++] Fix CI issues recently introduced by localization changes (#116216)
After a recent Github Actions runner policy change [1], the version of
Xcode included in the macos-14 image went from Xcode 16 to Xcode 15,
breaking our build bots.

This moves the bots to the macos 15 (public preview) image, which
contains Xcode 16.

Also, adjust an UNSUPPORTED annotation that was incorrectly targeting
macos 13.7 when it should have been targeting a version of AppleClang.

[1]: https://github.com/actions/runner-images/issues/10703
2024-11-15 00:00:54 +01:00
Louis Dionne
965f3a95b9 [libc++][NFC] Run clang-format on vector::erase test
Since I am about to make significant changes to this test, run clang-format
on it before to avoid obscuring the review.
2024-11-14 14:13:51 +01:00
Louis Dionne
9c3a7ad7fa
[libc++] Cleanly implement the base locale API for BSD-like platforms (#115176)
Instead of going through the old locale entry points, define the base
localization API for BSD-like platforms (Apple and FreeBSD) from
scratch, using <xlocale.h> as a basis. This doesn't actually change how
that functionality is implemented, it only avoids going through a maze
to do so.

This clean new support is implemented in a separate __locale_dir/support
directory, which mirrors what we do for the threading support API.
Eventually, everything under __locale_dir/locale_base_api will go away.

rdar://131476632
2024-11-11 13:11:23 -05:00
A. Jiang
9fd3c4115c
[libc++] Fix unexpected heterogeneous comparison (#115249)
Currently, libc++ incorrectly rejects heterogeneous comparison of
`unexpected`, because the `operator==` is only a hidden friend of
`unexpected<_Err>` but not of `unexpected<_Err2>`. We need to call the
`error()` member function on `__y`.

Fixes #115326
2024-11-07 11:49:29 -05:00
Louis Dionne
427a5cf105
[libc++] Add support for bounded iterators in std::array (#110729)
This patch introduces a new kind of bounded iterator that knows the size
of its valid range at compile-time, as in std::array. This allows computing
the end of the range from the start of the range and the size, which requires
storing only the start of the range in the iterator instead of both the start
and the size (or start and end). The iterator wrapper is otherwise identical
in design to the existing __bounded_iter.

Since this requires changing the type of the iterators returned by
std::array, this new bounded iterator is controlled by an ABI flag.

As a drive-by, centralize the tests for std::array::operator[] and add
missing tests for OOB operator[] on non-empty arrays.

Fixes #70864
2024-11-07 09:23:21 -05:00
Nikolas Klauser
c6f3b7bcd0
[libc++] Refactor the configuration macros to being always defined (#112094)
This is a follow-up to #89178. This updates the `<__config_site>`
macros.
2024-11-06 10:39:19 +01:00
Nikolas Klauser
5acc4a3dc0
[libc++] Remove <stddef.h> includes from the granularized <cstddef> headers (#114788)
We can define some of these aliases without having to include the system
<stddef.h> and there doesn't seem to be much of a reason we shouldn't do
it this way.
2024-11-06 10:38:19 +01:00
Peng Liu
07443e9776
[libc++][test] Improve ThrowingT to Accurately Throw after throw_after > 1 Use (#114077)
This PR fixes the `ThrowingT` class, which currently fails to raise
exceptions after a specified number of copy construction operations. The
class is intended to throw in a controlled manner based on a specified
counter value `throw_after`. However, its current implementation of the
copy constructor fails to achieve this goal.

The problem arises because the copy constructor does not initialize the
`throw_after_n_` member, leaving `throw_after_n_` to default to `nullptr`
as defined by the in-class initializer. As a result, its copy constructor
always checks against `nullptr`, causing an immediate exception rather
than throwing after the specified number `throw_after` of uses. The fix
is straightforward: simply initialize the `throw_after_n_` member in the
member initializer list.

This issue was previously uncovered because all exception tests for
`std::vector` in `exceptions.pass.cpp` used a `throw_after` value of 1,
which coincidentally aligned with the class's behavior.
2024-11-05 11:24:05 -05:00
A. Jiang
76b71c0bc4
[libc++] Set __cpp_lib_smart_ptr_for_overwrite (#114700)
The features were implemented in LLVM 16, but mistakenly considered
unimplemented in FTM tools.
2024-11-05 13:27:40 +08:00
Joseph Huber
95a2eb70cf
[libcxx] Add testing configuration for GPU targets (#104515)
Summary:
The GPU runs these tests using the files built from the `libc` project.
These will be placed in `include/<triple>` and `lib/<triple>`. We use
the `amdhsa-loader` and `nvptx-loader` tools, which are also provided by
`libc`. These launch a kernel called `_start` which calls `main` so we
can pretend like GPU programs are normal terminal applications.

We force serial exeuction here, because `llvm-lit` runs way too many
processes in parallel, which has a bad habit of making the GPU drivers
hang or run out of resources. This allows the compilation to be run in
parallel while the jobs themselves are serialized via a file lock.

In the future this can likely be refined to accept user specified
architectures, or better handle including the root directory by exposing
that instead of just `include/<triple>/c++/v1/`.

This currently fails ~1% of the tests on AMDGPU and ~3% of the tests on
NVPTX. This will hopefully be reduced further, and later patches can
XFAIL a lot of them once it's down to a reasonable number.

Future support will likely want to allow passing in a custom
architecture instead of simply relying on `-mcpu=native`.
2024-11-04 12:58:23 -06:00
Nikolas Klauser
de87dda2da
[libc++][NFC] Use more appropriate type traits for a few cases (#114025) 2024-11-04 18:58:49 +01:00
Louis Dionne
dfe737f231
[libc++] Apply post-commit review comments for unique_ptr<T[]> hardening (#111704) 2024-11-04 10:45:12 -05:00
Hui
f467af6696
[libc++][test] add test coverage for flat_map::emplace_hint (#113773)
Not all the code path has been exercised by the tests for
`flat_map::emplace_hint`
Adding more test coverage.
At the same time, adding more test cases for `flat_map::emplace`
2024-11-02 09:42:26 +00:00
Nikolas Klauser
e99c4906e4
[libc++] Granularize <cstddef> includes (#108696) 2024-10-31 02:20:10 +01:00
A. Jiang
63eb40eeb1
[libc++] Deprecate and remove meaningless <cxxx> headers (#111615)
This PR deprecates `<ccomplex>`, `<cstdbool>`, `<ctgmath>`, and
`<ciso646>` in C++17 and "removes" them in C++20 by special deprecation
warnings.

`<cstdalign>` is previously missing. This PR also tries to add them, and
then deprecates and "removes" `<cstdalign>`.

Papers:
- https://wg21.link/P0063R3
- https://wg21.link/P0619R4

Closes #99985.

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-10-30 09:49:26 +08:00
A. Jiang
f71ea0e72e
[libc++][test] Augment test_alloc in deallocate_size.pass.cpp (#113638)
Making it meet the requirements for allocator since C++11. Fixes
#113609.

This PR doesn't make it meet the C++03 allocator requirements, because
that would make the type too verbose and libc++ has backported many
C++11 features to the C++03 mode.

Drive-by: Removes the `TEST_CONSTEXPR_CXX14` on `allocate`/`dealocate`
which is never in effect (and causes IFNDR-ness before C++23), since
these functions modify the namespace-scoped variable `allocated_`.
2024-10-30 07:16:03 +08:00
Peng Liu
d3b98559be
Add exception guard for constructor vector(n, x, a) (#113086)
Added exception guard to the `vector(n, x, a)` constructor to enhance
exception safety. This change ensures that the `vector(n, x, a)`
constructor is consistent with other constructors, such as `vector(n)`,
`vector(n, x)`, `vector(n, a)`, in terms of exception safety.
2024-10-29 13:29:37 +08:00
serge-sans-paille
71315698c9
[clang] Warn about memset/memcpy to NonTriviallyCopyable types (#111434)
This implements a warning that's similar to what GCC does in that
context: both memcpy and memset require their first and second operand
to be trivially copyable, let's warn if that's not the case.
2024-10-28 20:40:52 +00:00
ZhangYin
99b2feadcc
[libc++] <experimental/simd> temporarily mark XFAIL for the armv7-unknown-linux-gnueabihf with simd unary test to pass the CI (#113641) 2024-10-28 12:40:09 +08:00
Hui
0be1883c36
[libc++] Implement P0429R9 std::flat_map (#98643)
Around half of the tests are based on the tests Arthur O'Dwyer's
original implementation of std::flat_map, with modifications and
removals.

partially implement #105190
2024-10-26 18:58:53 +01:00
A. Jiang
cae351f345
[libc++] Bump __cpp_lib_optional and __cpp_lib_variant (#113650)
In C++20 mode, `__cpp_lib_optional` and `__cpp_lib_variant` should be
`202106L` due to DR P2231R1.

In C++26 mode, `__cpp_lib_variant` should be bumped to `202306L` due to
P2637R3.
- Clang 16/17 shouldn't get this bumping (as member `visit` requires
explicit object parameters), but it's very tricky to make the bumping
conditionally enabled. I _hope_ unconditionally bumping in C++26 will be
OK for LLVM 20 when the support for Clang 17 is dropped.

Related PRs:
- https://reviews.llvm.org/D102119
- #83335
- #76447
2024-10-26 07:38:52 +08:00
Stephan T. Lavavej
f4db221258
[libc++][test] Use ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings) for -Wno-psabi (#113608)
MSVC doesn't understand `-Wno-psabi`, which was introduced here by
@ldionne in #106077.

Using `ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings)` (implemented by
#75317) avoids passing this to MSVC.
2024-10-25 11:12:41 -07:00
Nikolas Klauser
2e43a304f1
[libc++] Granularize <vector> (#99705)
|                    | old time | new time |
| ------------------ | -------- | -------- |
| functional - c++23 | 416ms    | 225ms    |
| random - c++23     | 513ms    | 392ms    |
| vector - c++17     | 206ms    | 100ms    |
2024-10-25 11:28:46 +02:00
Xiaoyang Liu
7c721999ca
[libc++][ranges] LWG4016: container-insertable checks do not match what container-inserter does (#113103)
This patch implements LWG4016: container-insertable checks do not match
what container-inserter does.
2024-10-23 10:04:50 -04:00
ZhangYin
2c3d7d5322
[libc++] <experimental/simd> Add unary operators for class simd (#104764) 2024-10-23 12:26:48 +08:00
Louis Dionne
c623df38c9
[libc++] Fix typo in is_always_lock_free test (#113169) 2024-10-22 09:17:06 -04:00
Michael Jones
6c4267fb17
[libcxx][libc] Hand in Hand PoC with from_chars (#91651)
Implements std::from_chars for float and double.

The implementation uses LLVM-libc to do the real parsing. Since this is
the first time libc++
uses LLVM-libc there is a bit of additional infrastructure code. The
patch is based on the
[RFC] Project Hand In Hand (LLVM-libc/libc++ code sharing)

https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701
2024-10-21 15:04:06 -07:00
Hui
1bbf3a3705
[libc++] Fix reverse_iterator when underlying is c++20 bidirectional_iterator but not Cpp17BidirectionalIterator (#112100)
`reverse_iterator` supports either c++20 `bidirectional_iterator` or
`Cpp17BidirectionalIterator `
http://eel.is/c++draft/reverse.iter.requirements

The current `reverse_iterator` uses `std::prev` in its `operator->`,
which only supports the `Cpp17BidirectionalIterator` properly.

If the underlying iterator is c++20 `bidirectional_iterator` but does
not satisfy the named requirement `Cpp17BidirectionalIterator`,
(examples are `zip_view::iterator`, `flat_map::iterator`), the current
`std::prev` silently compiles but does a no-op and returns the same
iterator back. So `reverse_iterator::operator->` will silently give a
wrong answer.

Even if we fix the behaviour of `std::prev`, at best, we could fail to
compile the code. But this is not ok, because we need to support this
kind of iterators in `reverse_iterator`.

The solution is simply to not use `std::prev`.

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-10-19 11:09:25 +01:00
A. Jiang
397707f718
[libc++] __uglify non-conforming member typedef base (#112843)
Currently, libc++'s `bitset`, `forward_list`, and `list` have
non-conforming member typedef name `base`. The typedef is private, but
can cause ambiguity in name lookup.

Some other classes in libc++ that are either implementation details or
not precisely specified by the standard also have member typdef `base`.
I think this can still be conforming.

Follows up #80706 and #111127.
2024-10-18 23:27:12 +08:00
A. Jiang
cbe03646c6
[libc++][ranges] LWG3692: zip_view::iterator's operator<=> is overconstrained and changes of zip_view in P2165R4 (#112077)
The changes are nearly pure simplifications, so I think it's OK to do
them together in the same PR.

Actual test coverages were already added in commit ad41d1e26b12
(https://reviews.llvm.org/D141216). Thanks to Casey Carter!

Fixes #104975
Towards #105200
2024-10-16 09:34:31 -04:00