4466 Commits

Author SHA1 Message Date
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
A. Jiang
d9c2256c97
[libc++][test] Fix overload_compare_iterator::iterator_category (#112165)
`overload_compare_iterator` only supports operations required for
forward iterators. On the other hand, it is used for output iterators of
uninitialized memory algorithms, which requires it to be forward
iterator.

As a result, `overload_compare_iterator<I>::iterator_category` should
always be `std::forward_iterator_tag` if we don't extend its ability.
The correct `iterator_category` can prevent standard library
implementations like MSVC STL attempting random access operations on
`overload_compare_iterator`.

Fixes #74756.
2024-10-15 22:35:16 +08:00
A. Jiang
a061d4d5ce
[libc++] Fix expression-equivalence for mem_fn (#111307)
Previously, SFINAE constraints and exception specification propagation
were missing in the return type of libc++'s `std::mem_fn`. The
requirements on expression-equivalence (or even plain "equivalent" in
pre-C++20 specification) in [func.memfn] are actually requiring them.

This PR adds the missed stuffs. Fixes #86043.

Drive-by changes:
- removing no longer used `__invoke_return`,
- updating synopsis comments in several files, and
- merging several test files for `mem_fn` into one.
2024-10-15 22:33:50 +08:00
Nikolas Klauser
ba87515fea
[libc++][RFC] Always define internal feature test macros (#89178)
Currently, the library-internal feature test macros are only defined if
the feature is not available, and always have the prefix
`_LIBCPP_HAS_NO_`. This patch changes that, so that they are always
defined and have the prefix `_LIBCPP_HAS_` instead. This changes the
canonical use of these macros to `#if _LIBCPP_HAS_FEATURE`, which means
that using an undefined macro (e.g. due to a missing include) is
diagnosed now. While this is rather unlikely currently, a similar change
in `<__configuration/availability.h>` caught a few bugs. This also
improves readability, since it removes the double-negation of `#ifndef
_LIBCPP_HAS_NO_FEATURE`.

The current patch only touches the macros defined in `<__config>`. If
people are happy with this approach, I'll make a follow-up PR to also
change the macros defined in `<__config_site>`.
2024-10-12 09:49:52 +02:00
A. Jiang
159d694c05
[libc++] __uglify internal member names of iterators in bitset (#111127)
[template.bitset.general] indicates that `bitset` shouldn't have member
typedef-names `iterator` and `const_iterator`. Currently libc++'s
typedef-names are causing ambiguity in name lookup, which isn't
conforming.

As these iterator types are themselves useful, I think we should just
use __uglified member typedef-names for them.

Fixes #111125
2024-10-10 09:14:05 -04:00
simpal01
d25f1a19c8
Add 64bit atomic check in the is_always_lock_free_pass test. (#111540)
Currently this test is completely xfailed as part of the patch
https://github.com/llvm/llvm-project/pull/106077. But this test works on
A and R profile, not in v7M profile. Because the test contain cases in
which m-profile will fail for atomic types greater than 4 bytes in size.
2024-10-09 09:19:11 -04:00
Hristo Hristov
a06591b4d4
[libc++][type_traits] P2674R1: A trait for implicit lifetime types (#106870)
Implements P2674R1: https://wg21.link/P2674R1

- https://eel.is/c++draft/type.traits
  - https://eel.is/c++draft/meta.type.synop
  - https://eel.is/c++draft/meta.unary.prop
- https://eel.is/c++draft/support.limits
  - https://eel.is/c++draft/version.syn

Implementation details:
- Uses compiler intrinsic `__builtin_is_implicit_lifetime`:
  - https://github.com/llvm/llvm-project/pull/101807
- Tests based on:
-
d213981c80/clang/test/SemaCXX/type-traits.cpp (L1989)

References:
- Implicit-lifetime
- Implicit-lifetime types [basic.types.general]/9:
https://eel.is/c++draft/basic.types.general
- Implicit-lifetime class [class.prop]/9:
https://eel.is/c++draft/class.prop
- P0593R6 Implicit creation of objects for low-level object
manipulation: https://wg21.link/P0593R6
- P1010R1 Container support for implicit lifetime types:
https://wg21.link/P1010R1
- P0593R6 Implicit creation of objects for low-level object
manipulation: https://wg21.link/P0593R6

Closes: #105259

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-10-09 08:19:14 +02:00
Louis Dionne
848b20de76
[libc++] Correctly handle custom deleters in hardened unique_ptr<T[]> (#110685)
It turns out that we can never do bounds-checking for unique_ptrs with
custom deleters, except when converting from a unique_ptr with a default
deleter to one with a custom deleter.

If we had an API like `std::make_unique` that allowed passing a custom
deleter, we could at least get bounds checking when the unique_ptr is
created through those APIs, but for now that is not possible.

Fixes #110683
2024-10-03 11:45:58 -04:00
Louis Dionne
121ed5c198
[libc++] Remove test suite annotations for experimental stop_token (#110890)
<stop_token> is not experimental anymore, so its tests shouldn't be
guarded by libcpp-has-no-experimental-stop_token.
2024-10-03 09:05:16 -04:00
A. Jiang
19c6958d24
[libc++] Re-apply LWG3870: Remove voidify (#110944)
This reverts commit f3d58f4161b86a479f68acb453e9622911c688a0.

Relands #110355.
2024-10-03 08:28:26 -04:00
A. Jiang
557f7e1398
[libc++] P2167R3: Improved Proposed Wording for LWG 2114 (#109102)
Only the [cmp.alg] part (for `comparison_meow_fallback` CPOs) in the
paper required changes. Other parts merely fixed preconditions of some
standard library functions.

I strongly feel that P2167R3 should be a DR despite that it is not a DR
officially: CPOs -> C++20; remain parts -> C++98/11 (except that
_`boolean-testable`_ should be transformed into the original
_BooleanTestable_ requirements in the old resolution of LWG2114).

Note that P2167R3 damaged the resolution of LWG3465: the type of `F < E`
was left underconstrained. I've tried to submit an LWG issue for this,
which is now LWG4157.

Drive-by change:
- enable some test coverages in `compare_strong_order_fallback.pass.cpp`
when `TEST_LONG_DOUBLE_IS_DOUBLE`, following up #106742

Closes #105241.
2024-10-03 01:09:53 +08:00
Nikolas Klauser
d278fa5e1a
[libc++] Fix constant initialization of unique_ptr in C++17 and prior (#108956)
This is already tested in
`std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp`
except that `TEST_CONSTINIT` doesn't do anything before C++20 without
this patch.
2024-10-02 17:09:06 +02:00