Commit Graph

10508 Commits

Author SHA1 Message Date
Louis Dionne
3456b2f60a [libc++] Refactor __debug_three_way_comp
This makes __debug_three_way_comp consistent with __debug_less and
in particular gets rid of a potential use-after-move caused by the
use of std::forward. In the previous version of the code, we would
call `__do_compare_assert` after forwarding the arguments into the
comparator, which could end up using the arguments after they've been
moved from.

This also simplifies how we call `__do_compare_assert` by using
`if constexpr` and adds a missing test for proxy iterators in
lexicographical_compare_three_way, which could have found this
issue.

Differential Revision: https://reviews.llvm.org/D152753
2023-06-13 14:24:56 -07:00
Louis Dionne
52310ce9c1 [libc++][NFC] Reformat features.py
This file was reformatted using the Black tool, which led to entirely
unreadable code due to how lines are broken. Formatting tools are fine,
but not when they lead to code that humans have trouble reading. In the
case of features.py, a lot of it was meant to be aligned in a repetitive
but consistent way to make the structure of the code stand out.
Reformatting with the tool lost that property.

Differential Revision: https://reviews.llvm.org/D152737
2023-06-13 10:24:46 -07:00
Louis Dionne
520c7fbbd0 [libc++] Mark slow tests as unsupported on GCC
Some tests in our test suite are unbelievably slow on GCC due to the
use of the always_inline attribute. See [1] for more details.

This patch introduces the GCC-ALWAYS_INLINE-FIXME lit feature to
disable tests that are plagued by that issue. At the same time, it
moves several existing tests from ad-hoc `UNSUPPORTED: gcc-12` markup
to the new GCC-ALWAYS_INLINE-FIXME feature, and marks the slowest tests
reported by the CI as `UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME`.

[1]: https://discourse.llvm.org/t/rfc-stop-supporting-extern-instantiations-with-gcc/71277/1

Differential Revision: https://reviews.llvm.org/D152736
2023-06-13 10:20:30 -07:00
Nikolas Klauser
7d3bba5e2f [libc++] Add [[nodiscard]] extensions to the functions in <bit>
Reviewed By: #libc, ldionne, Mordante

Spies: Mordante, ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D152653
2023-06-13 08:01:34 -07:00
Nikolas Klauser
cd916108b4 [libc++][PSTL] Implement std::generate{,_n}
Reviewed By: #libc, ldionne

Spies: ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D152581
2023-06-13 07:55:06 -07:00
Hristo Hristov
7928ac4e6a [libc++][spaceship] P1612R2: Removed operator!= from locale
Implemented parts of P1612R2:
- Removed `operator!=` from `locale`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152654
2023-06-13 07:47:13 +03:00
Hristo Hristov
5a53323d2c [libc++][spaceship][NFC] P1612R2: Mark some items "remove operator!= from *_iterator" as "Complete"
Several parts of P1612R2 are already implemented:
- `common_iterator` (new in C++20) https://reviews.llvm.org/D103335
- `unreachable_sentinel_t` (new in C++20) https://reviews.llvm.org/D107920
- `istream_iterator` (removed) https://reviews.llvm.org/D119620
- `istreambuf_iterator` (removed) https://reviews.llvm.org/D119620

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152656
2023-06-13 07:44:01 +03:00
Ryan Prichard
1da06804e1 [libc++] Android temp dir is /data/local/tmp, enable Windows test
[libc++] Android temp dir is /data/local/tmp, enable Windows test

On Android, std::filesystem::temp_directory_path() should fall back to
/data/local/tmp when no environment variable is set. There is no /tmp
directory. Most apps can't access /data/local/tmp, but they do have a
"cache dir" (Context#getCacheDir()) that is usable for temporary files.
However, there is no obvious and reliable way for libc++ to query this
directory in contexts where it is available. The global fallback
/data/local/tmp is available for "adb shell", making it useful for test
suites.

On Windows, temp_directory_path falls back to the Windows directory
(e.g. "C:\Windows"), so call GetWindowsDirectoryW to do the test.

Reviewed By: ldionne, #libc, enh

Differential Revision: https://reviews.llvm.org/D137131
2023-06-12 20:43:00 -07:00
Nikolas Klauser
ab028d8006 [libc++][PSTL] Update papers and add a status page for the algorithms
Reviewed By: #libc, ldionne

Spies: libcxx-commits, mgrang, arphaman

Differential Revision: https://reviews.llvm.org/D152578
2023-06-12 16:46:06 -07:00
Louis Dionne
d167fe0c4e [libc++][NFC] Refactor filesystem namespace test 2023-06-12 12:43:19 -07:00
Hristo Hristov
0029ad89e8 [libc++][spaceship] P1614R2: Removed operator!= from weekdays
Implements parts of P1614R2. Removed `operator!=` from:
- `weekday`
- `weekday_indexed`
- `weekday_last`
- `month_weekday`
- `month_weekday_last`
- `year_month_weekday`
- `year_month_weekday_last`

Note these operators were added and removed in C++20.

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152699
2023-06-12 22:22:22 +03:00
Mark de Wever
9c053e6993 [libc++][format] Make public functions nodiscard.
This is an extension and only adds the functions that are a considered a
but when called and ignoring the result.

Drive-by sort all nodiscard extensions in the documentation.

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D152097
2023-06-12 18:55:56 +02:00
Hristo Hristov
a9e0321ffe [libc++][spaceship] P1614R2: Added operator== to file_status
Implemented parts of P1614R2:
- Added `operator==` to `file_status`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152647
2023-06-12 19:53:50 +03:00
Hristo Hristov
8cf3c2920d [libc++][spaceship] P1614R2: Removed operator!= from scoped_allocator_adaptor
Implements parts of P1614R2
- Removed `operator!=` from `scoped_allocator_adaptor`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152678
2023-06-12 19:51:27 +03:00
Hristo Hristov
9a6ca67397 [libc++][spaceship] P1614R2: Removed operator!= from functional
Implements parts of P1614R2:
- Removed `operator!=` from `functional`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152704
2023-06-12 19:48:42 +03:00
Hristo Hristov
d1ef99fe1c [libc++][spaceship] P1614R2: Removed global operator!= from allocator
Implements parts of P1614R2:
- Removed global `operator!=` from `allocator`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152612
2023-06-12 09:41:56 +03:00
Hristo Hristov
7c96cd35bf [libc++][spaceship] P1612R2: Removed operator!= from bitset
Implements parts of P1612R2:
- Removed `operator!=` from `bitset`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152611
2023-06-12 09:26:51 +03:00
Hristo Hristov
3d74398bd3 [libc++][spaceship] P1614R2: Removed operator!= from unordered_map, unordered_multimap, __hash_map_iterator
Implements parts of P1614R2:
- Removed ops from `unordered_map`
- Removed ops from `unordered_multimap`
- Removed ops from `__hash_map_iterator`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152642
2023-06-12 09:23:36 +03:00
Hristo Hristov
bfd6e4dd2d [libc++][spaceship] P1614R2: Removed ops from unordered_multiset, unordered_set
Implements parts of P1614R2:
- Removed ops from `unordered_multiset`,
- Removed ops from `unordered_set`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152643
2023-06-11 21:31:24 +03:00
Hristo Hristov
be45fe5d85 [libc++][spaceship] P1614R2: Removed ops from complex
Implements parts of P1614R2:
- Removed ops from `complex`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152615
2023-06-11 19:52:02 +03:00
Hristo Hristov
f877e88c35 [libc++][spaceship] P1614R2: Added operator== to slice
Implements parts of P1614R2:
- Added `operator==` to `slice`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152617
2023-06-11 19:50:31 +03:00
Hristo Hristov
6c34aab3ff [libc++][spaceship] P1614R2: Removed ops from memory_resource, polymorphic_allocator
Implements parts of P1614R2
- Removed ops from `memory_resource`
- Removed ops from `polymorphic_allocator`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152629
2023-06-11 19:49:35 +03:00
AdityaK
8100aa4c02 [libcxx] Use the unoptimized routines for volatile source types
As reported in: D147741

Reviewers: philnik, var-const, ldionne, hans

Differential Revision: https://reviews.llvm.org/D152571
2023-06-10 23:11:47 -07:00
Hristo Hristov
211efbb198 [libc++][spaceship][NFC] Updates SpaceshipProjects.csv with full details from P1614R2
Adds the remaining sections from [[ https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html | P1614R2 ]]
Some entries were reordered for easier tracking.
The items in the table match [[ https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html | P1614R2 ]]'s sections strictly.

Reviewed By: Mordante, #libc

Differential Revision: https://reviews.llvm.org/D152297
2023-06-10 22:09:58 +03:00
Hristo Hristov
ca7a041626 [libc++][spaceship] Implement operator<=> for stack
Depends on D146066

Depends on D132268

Implements parts of P1614R2 `operator<=>` for `stack`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D146094
2023-06-10 07:37:36 +03:00
Hristo Hristov
55ec808a88 [libc++][spaceship] Implement operator<=> for vector
Implements part of P1614R2 "The Mothership has Landed"

Depends on D150188

Reviewed By: Mordante, #libc

Differential Revision: https://reviews.llvm.org/D132268
2023-06-10 06:53:05 +03:00
Hristo Hristov
8fe609cb3a [libc++][spaceship] Fixed __debug_three_way_comp's operator() for vector<bool>'s operator<=>`
An issue with `operator()` was found during the implementation of https://reviews.llvm.org/D132268.

This patch aims to resolve the issues by updating the operator to use perfect forwarding.

The original motivation for `three_way_comp_ref_type` is given in: https://reviews.llvm.org/D131395

`three_way_comp_ref_type`'s implementation is inspired by `comp_ref_type`, which has two overloads:

```
    template <class _Tp, class _Up>
    bool operator()(const _Tp& __x,  const _Up& __y);

    template <class _Tp, class _Up>
    bool operator()(_Tp& __x,  _Up& __y);
```

`__debug_three_way_comp` is missing the first overload and also declares the typealias`_three_way_comp_ref_type ` incorrectly.

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D150188
2023-06-10 06:48:01 +03:00
Nikolas Klauser
6adb1ca555 [libc++] Add concepts that ensure a given iterator meets the syntactic requirements
These concepts are used to ensure valid iterators are passed to PSTL algorithms, but can also be used for other interfaces.

Reviewed By: ldionne, #libc

Spies: EricWF, libcxx-commits

Differential Revision: https://reviews.llvm.org/D150493
2023-06-09 08:38:22 -07:00
Nikolas Klauser
7949ee0d4f [libc++] Introduce __is_pointer_in_range
This checks whether a pointer is within a range, even during constant evaluation. This allows running optimized code paths during constant evaluation, instead of falling back to the general-purpose implementation all the time. This is also a central place for comparing unrelated pointers, which is technically UB.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D143327
2023-06-07 13:33:58 -07:00
Louis Dionne
dd72b81334 [libc++] Rename availability macros for <filesystem>
This makes it clearer that the availability macro only pertains to
<filesystem>, and not to whether the platform has support for a file
system.

Differential Revision: https://reviews.llvm.org/D152172
2023-06-07 11:31:29 -07:00
Louis Dionne
66a562d22e [libc++] Roll up fstream support into filesystem support
LIBCXX_ENABLE_FILESYSTEM should represent whether the platform has
support for a filesystem, not just whether we support <filesystem>.
This patch slightly generalizes the setting to also encompass whether
we provide <fstream>, since that only makes sense when a filesystem is
supported.

Differential Revision: https://reviews.llvm.org/D152168
2023-06-07 08:04:58 -07:00
Nikolas Klauser
88632e4806 [libc++] Refactor __less
This simplifies the usage of `__less` by making the class not depend on the types compared, but instead the `operator()`. We can't remove the template completely because we explicitly instantiate `std::__sort` with `__less<T>`.

Reviewed By: ldionne, #libc

Spies: arichardson, EricWF, libcxx-commits, mgrang

Differential Revision: https://reviews.llvm.org/D145285
2023-06-06 13:58:52 -07:00
Louis Dionne
1939eb3dc2 [libc++] Disable int128_t and ship filesystem on MSVC by default
Back in 2020 [1], we went very close to enabling Filesystem on MSVC
by disabling int128_t, but decided to wait because MSVC support
for int128_t was supposed to come shortly after. Since it's not
there yet, I propose turning off int128_t support by default on MSVC.
This will make <filesystem> available by default on MSVC, and most
importantly will open the possibility for changing
LIBCXX_ENABLE_FILESYSTEM to mean "the system doesn't have support
for a filesystem" instead of simply "don't build the std::filesystem
library", which is what I'm really after with this change.

In a way, this is a resurection of D91139.

[1]: https://reviews.llvm.org/D91139#2429595

Differential Revision: https://reviews.llvm.org/D134912
2023-06-06 13:31:03 -07:00
Louis Dionne
7d2b9fafab [libc++] Use Lit annotations for all .gen.py tests
Instead of guarding header tests using #ifdefs inside the tests,
use Lit markup to mark all the tests as unsupported. This is simpler
but also provides better feedback about which tests are being run
when running the test suite.

Differential Revision: https://reviews.llvm.org/D151893
2023-06-06 13:28:09 -07:00
Nikolas Klauser
51131edf83 [libc++][PSTL] Implement std::replace{,_if,_copy,_copy_if}
Reviewed By: #libc, ldionne

Spies: ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D151841
2023-06-06 08:44:53 -07:00
Nikolas Klauser
7a3b528e1b [libc++][PSTL] Implement std::count{,_if}
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D150128
2023-06-06 08:42:59 -07:00
Mark de Wever
6593fcccd7 [libc++] Fixes transitive includes. 2023-06-06 17:16:23 +02:00
Mark de Wever
f26b43fa5c [libc++] Removes CMake work-arounds.
CMake older than 3.20.0 is no longer supported.
This removes work-arounds for no longer supported versions.

Reviewed By: #libc, jloser, philnik

Differential Revision: https://reviews.llvm.org/D152099
2023-06-06 08:10:31 +02:00
Hristo Hristov
172d990c03 [libc++][spaceship] Implement operator<=> for queue
Implements parts of P1614R2 `operator<=>` for `queue`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D146066
2023-06-06 08:41:56 +03:00
varconst
87f3ff3e55 [libc++][ranges] Implement the changes to container adaptors from P1206 (ranges::to):
- add the `from_range_t` constructors and the related deduction guides;
- add the `push_range` member function.

(Note: this patch is split from https://reviews.llvm.org/D142335)

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D149829
2023-06-05 18:57:25 -07:00
Nikolas Klauser
355f466744 [libc++][NFC] Add __element_count and use it in the constexpr C functions
This makes it less ambiguous what the parameter is meant to get.

Reviewed By: #libc, ldionne

Spies: ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D152040
2023-06-05 15:08:01 -07:00
Nikolas Klauser
d965960fcf Revert "[libc++] Optimize for_each for segmented iterators"
This reverts commit b1dc43aa3a.
2023-06-05 10:00:02 -07:00
Louis Dionne
81cc929d4f [libc++] Use .gen.py tests for the transitive inclusion tests
This finishes the transition of tests covered in generate_header_tests.py
to the new .gen.py format.

Differential Revision: https://reviews.llvm.org/D152008
2023-06-05 07:23:31 -07:00
Hui
b77e50e6ae [libc++] Implement stop_token
Implement stop_token
http://eel.is/c++draft/thread.stoptoken
2023-06-05 15:10:36 +01:00
Danila Kutenin
7e1ee1e10d [libcxx] Add strict weak ordering checks to sorting algorithms
This is the implementation of the first proposal of strict weak ordering checks described in https://discourse.llvm.org/t/rfc-strict-weak-ordering-checks-in-the-debug-libc/70217

This targets the most vulnerable algorithms like std::sort

Reviewed By: philnik, #libc

Differential Revision: https://reviews.llvm.org/D150264
2023-06-04 19:27:31 +02:00
Martin Storsjö
fcbbd9649a [libcxx] Fix using std::wcout/wcin on Windows with streams configured in wide mode
On Windows, the underlying file descriptors for stdout/stdin/stderr
can be reconfigured to wide mode. In the default (narrow) mode, the
charset usually isn't utf8 (as libcxx assumes), but normally a locale
specific codepage (where each codepage only can represent a small
subset of unicode characters).

By configuring the stdout file descriptor to wide mode, the user can
output wchar_t based strings without convesion to the narrow charset.
Within libcxx, don't try to use codecvt to convert this to a narrow
character encoding, but output these strings as such with fputwc.

In wide mode, such strings could be output directly with fwrite too,
but if the file descriptor hasn't been configured in wide mode, that
breaks the output (which currently works reasonably). By always
outputting one character at a time with fputwc, it works regardless
of mode of the stdout file descriptor.

For the narrow output stream, std::cout, outputting (via fwrite)
does fail when the file descriptor is set to wide mode. This matches
how it behaves with both MS STL and GNU libstdc++ too, so this is
probably acceptable.

This fixes https://github.com/llvm/llvm-project/issues/46646, and
the downstream bugs https://github.com/mstorsjo/llvm-mingw/issues/145
and https://github.com/mstorsjo/llvm-mingw/issues/222.

Differential Revision: https://reviews.llvm.org/D146398
2023-06-03 23:11:39 +03:00
Louis Dionne
3b12d34a70 [libc++] Remove min_max_macros test
This test is redundant since we already test the same thing in our
nasty_macros test.

Differential Revision: https://reviews.llvm.org/D152007
2023-06-02 10:05:43 -07:00
Louis Dionne
c0f4b12da4 [libc++] Transition several remaining generated tests to the new .gen format
In addition to reducing the amount of boilerplate we need to generate
whenever a new header is added, this also improves the existing tests
by running them in separate Lit tests (so they can be parallelized).
This also creates separate translation units for most header tests,
which is what we really should have done from the start since it
isolates each header we're testing.

Differential Revision: https://reviews.llvm.org/D151654
2023-06-02 10:02:15 -07:00
Louis Dionne
bb9b12907e [libc++] Fix broken transitive includes test 2023-06-02 07:23:44 -07:00
Louis Dionne
45307f1b0d [libc++] Refactor the mandatory header inclusion tests to .gen.py
This allows removing a bunch of boilerplate from the test suite and
reducing the amount of manual stuff contributors have to do when they
add a new public header.

Differential Revision: https://reviews.llvm.org/D151830
2023-06-01 19:56:30 -07:00