6431 Commits

Author SHA1 Message Date
Ilya Biryukov
4bf8dc1a0f
[libc++] Remove macros for keeping std::allocator members and void specialization after C++20 (#85806)
Fixes #75975.

Remove `_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS` for the LLVM 19
release, it was previously marked as deprecated in LLVM 18.

I believe that
`_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION` was only
used by Google in conjunction with
`_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`.

Removing both macros together should not cause any issues in practice,
even though we did not announce the removal of
`_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION` before.
2024-03-21 17:48:13 +01:00
Mark de Wever
8779edb8b3
[libc++] Deprecates std::errc constants. (#80542)
Implements:
- LWG3869 Deprecate std::errc constants related to UNIX STREAMS
2024-03-21 12:14:24 +01:00
Mark de Wever
22f20564a8
[libc++][CI] Reenables the module tests. (#85799)
These were disabled due to ODR violations with mixed versions of
clang-tidy and the clang libraries. This issue was fixed in
e19e8600cf743690e1a23fb8a2b0dfbe2dafe559.

This reverts commit 0bbada93a559b604797fe57978f3eca5e41edaeb.
2024-03-20 11:32:51 +01:00
Xiaoyang Liu
cf09b7dec4
[libc++][ranges] LWG3715: view_interface::empty is overconstrained (#85004)
## Abstract

This pull request implements LWG3715: `view_interface::empty` is
overconstrained. Here is an example similar to those described in the
report, which compiles with `-stdlib=libstdc++` but failed to compile
with `-stdlib=libc++`:

```cpp
// https://godbolt.org/z/EWEoTzah3
std::istringstream input("1 2 3 4 5");
auto i = std::views::istream<int>(input);
auto r = std::views::counted(i.begin(), 4) | std::views::take(2);
assert(!r.empty());
```

## Reference

- [Draft C++ Standard:
[view.interface.general]](https://eel.is/c++draft/view.interface.general)
- [LWG3715](https://wg21.link/LWG3715)
2024-03-20 09:47:40 +01:00
Mark de Wever
11dd881b9c
[libc++][format] Fixes nested concept evaluation. (#85548)
Before the __formattable concept depended on itself in a contrieved
example. By using the underlying concept directly the cycle is broken.

Fixes https://github.com/llvm/llvm-project/issues/81590
2024-03-20 09:45:12 +01:00
Mark de Wever
f804217155 Revert "[libc++][CMake] Removes LIBCXX_ENABLE_CLANG_TIDY. (#85262)"
This reverts commit 4109b18ee5de1346c2b89a5c89b86bae5c8631d3.

It looks like the automatic detection has false positives. This broke
the following build https://github.com/llvm/llvm-project/pull/85262
2024-03-18 17:13:56 +01:00
Mark de Wever
4109b18ee5
[libc++][CMake] Removes LIBCXX_ENABLE_CLANG_TIDY. (#85262)
The clang-tidy selection in CMake was refactored in
https://github.com/llvm/llvm-project/pull/81362. During review it was
suggested to remove this CMake option.
2024-03-18 14:32:30 +01:00
Nikolas Klauser
4ea850b52f
[libc++] Remove __unconstrained_reverse_iterator (#85582)
`__unconstrained_reverse_iterator` has outlived its usefullness, since
the standard and subsequently the compilers have been fixed.
2024-03-18 14:19:51 +01:00
Nikolas Klauser
a10aa4485e
[libc++] Simplify the implementation of remove_reference (#85207)
GCC 13 introduced the type trait `__remove_reference`. We can simplify
the implementation of `remove_reference` a bit by using it.
2024-03-18 13:57:07 +01:00
Rodrigo Salazar
4c5bc76677
[libcxx][test] Create feature host-can-create-symlinks (#82204)
On Windows you can not create symlinks without elevated privileges
unless you have Windows developer mode enabled. There's ~67 libcxx tests
that run into failures on windows if your environment is not set up
correctly (Go to windows settings and enable "developer mode").

This change:
- Adds a feature check for whether the host can create symlinks. (see
libcxx/utils/libcxx/test/features.py)
- Mark the feature as required for the 67 tests that hit failures on
windows due to this. This will allow lit to correctly mark these tests
as unsupported instead of unexpectedly failed (this is helpful since
then you know you didn't break something with your change, it's just
that it's not supported with your environment).
2024-03-18 12:53:54 +01:00
Nikolas Klauser
07b18c5e1b
[libc++] Optimize ranges::fill{,_n} for vector<bool>::iterator (#84642)
```
------------------------------------------------------
Benchmark                          old             new
------------------------------------------------------
bm_ranges_fill_n/1             1.64 ns         3.06 ns
bm_ranges_fill_n/2             3.45 ns         3.06 ns
bm_ranges_fill_n/3             4.88 ns         3.06 ns
bm_ranges_fill_n/4             6.46 ns         3.06 ns
bm_ranges_fill_n/5             8.03 ns         3.06 ns
bm_ranges_fill_n/6             9.65 ns         3.07 ns
bm_ranges_fill_n/7             11.5 ns         3.06 ns
bm_ranges_fill_n/8             13.0 ns         3.06 ns
bm_ranges_fill_n/16            25.9 ns         3.06 ns
bm_ranges_fill_n/64             103 ns         4.62 ns
bm_ranges_fill_n/512            711 ns         4.40 ns
bm_ranges_fill_n/4096          5642 ns         9.86 ns
bm_ranges_fill_n/32768        45135 ns         33.6 ns
bm_ranges_fill_n/262144      360818 ns          243 ns
bm_ranges_fill_n/1048576    1442828 ns          982 ns
bm_ranges_fill/1               1.63 ns         3.17 ns
bm_ranges_fill/2               3.43 ns         3.28 ns
bm_ranges_fill/3               4.97 ns         3.31 ns
bm_ranges_fill/4               6.53 ns         3.27 ns
bm_ranges_fill/5               8.12 ns         3.33 ns
bm_ranges_fill/6               9.76 ns         3.32 ns
bm_ranges_fill/7               11.6 ns         3.29 ns
bm_ranges_fill/8               13.2 ns         3.26 ns
bm_ranges_fill/16              26.3 ns         3.26 ns
bm_ranges_fill/64               104 ns         4.92 ns
bm_ranges_fill/512              716 ns         4.47 ns
bm_ranges_fill/4096            5772 ns         8.21 ns
bm_ranges_fill/32768          45778 ns         33.1 ns
bm_ranges_fill/262144        351422 ns          241 ns
bm_ranges_fill/1048576      1404710 ns          965 ns
```
2024-03-17 20:00:54 +01:00
Mark de Wever
0847c903c8 Revert "[libc++] Fix tests on musl (#85085)"
This reverts commit b61fb18456ecd798b2fc340367018ab3109ebfae.

This commit landed with build failures in the pre-commit CI
https://buildkite.com/llvm-project/libcxx-ci/builds/34153
2024-03-16 20:22:49 +01:00
Nikolas Klauser
f694f632d9
[libc++] Add <locale> include in <chrono> (#85521)
I accidentally removed this transitive include in #85478.
2024-03-16 16:40:36 +01:00
Nikolas Klauser
5bcb78141c
[libc++] Remove <locale> includes from <format> (#85478)
This reduces the include time from 767ms to 691ms.
2024-03-16 13:45:24 +01:00
Jakub Mazurkiewicz
12978b3e23
[libc++] P2602R2 Poison Pills are Too Toxic (#74534)
Implements [P2602R2 Poison Pills are Too
Toxic](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2602r2.html)
as a DR in C++20 mode.
2024-03-16 12:16:36 +00:00
Marc Auberer
864a886105
[libc++] Add [[nodiscard]] to static numeric limit functions (#83748)
Fixes #83695
2024-03-15 17:19:58 +01:00
Mark de Wever
abe292f9f8
[libc++] Enables TZDB tests. (#82108)
With the timezone information available in the CI these tests can be
enabled again.

Fixes: https://github.com/llvm/llvm-project/issues/81654
2024-03-15 08:17:08 +01:00
Nikolas Klauser
95c1313f25
[libc++] Remove a few includes from <__functional/hash.h> (#83254)
This also moves `__all` from `sfinae_helpers.h` to `conjunction.h`.
2024-03-14 19:49:37 +01:00
Mark de Wever
5afb937d8a
[libc++] Implements filebuf unbuffered. (#76629)
When calling setbuf(nullptr, 0) before performing file operations it
should set the file to unbuffered mode. Currently the code avoids
buffering internally, but the underlying stream still can buffer.

This is addressed by disabling the buffering of the underlying stream.

Fixes: https://github.com/llvm/llvm-project/issues/60509
2024-03-14 17:55:05 +01:00
Nikolas Klauser
4528c44d0a
[libc++] Remove <tuple> include from <__format/concepts.h> (#80214)
This also moves `tuple_size_v` into `tuple_size` as a drive-by.
2024-03-14 12:04:41 +01:00
Alastair Houghton
b61fb18456
[libc++] Fix tests on musl (#85085)
One or two of the tests need slight tweaks to make them pass when
building with musl.

rdar://118885724
2024-03-13 14:48:13 -04:00
Louis Dionne
9e406ef4f4
[libc++] Remove _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT (#83928)
This was slated for removal in LLVM 19.
2024-03-13 09:00:53 -04:00
Mark de Wever
e09761944c
[libc++] Improves UB handling in ios_base destructor. (#76525)
Destroying an ios_base object before it is properly initialized is
undefined behavior. Unlike typical C++ classes the initialization is not
done in the constructor, but in a dedicated init function. Due to
virtual inheritance of the basic_ios object in ostream and friends this
undefined behaviour can be triggered when inheriting from classes that
can throw in their constructor and inheriting from ostream.

Use the __loc_ member of ios_base as sentinel to detect whether the
object has or has not been initialized.

Addresses https://github.com/llvm/llvm-project/issues/57964
2024-03-12 18:04:14 +01:00
Mark de Wever
65eea3e5dc
[libc++][TZDB] Fixes parsing interleaved rules. (#84808)
Typically the rules in the database are contiguous, but that is not a
requirement. This fixes the case when they are not.

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-03-12 17:26:39 +01:00
David Benjamin
a83f8e0314
[libc++][hardening] Check bounds on arithmetic in __bounded_iter (#78876)
Previously, `__bounded_iter` only checked `operator*`. It allowed the
pointer to go out of bounds with `operator++`, etc., and relied on
`operator*` (which checked `begin <= current < end`) to handle
everything. This has several unfortunate consequences:

First, pointer arithmetic is UB if it goes out of bounds. So by the time
`operator*` checks, it may be too late and the optimizer may have done
something bad. Checking both operations is safer.

Second, `std::copy` and friends currently bypass bounded iterator
checks. I think the only hope we have to fix this is to key on `iter +
n` doing a check. See #78771 for further discussion. Note this PR is not
sufficient to fix this. It adds the output bounds check, but ends up
doing it after the `memmove`, which is too late.

Finally, doing these checks is actually *more* optimizable. See #78829,
which is fixed by this PR. Keeping the iterator always in bounds means
`operator*` can rely on some invariants and only needs to check `current
!= end`. This aligns better with common iterator patterns, which use
`!=` instead of `<`, so it's easier to delete checks with local
reasoning.

See https://godbolt.org/z/vEWrWEf8h for how this new `__bounded_iter`
impacts compiler output. The old `__bounded_iter` injected checks inside
the loops for all the `sum()` functions, which not only added a check
inside a loop, but also impeded Clang's vectorization. The new
`__bounded_iter` allows all the checks to be optimized out and we emit
the same code as if it wasn't here.

Not everything is ideal however. `add_and_deref` ends up emitting two
comparisons now instead of one. This is because a missed optimization in
Clang. I've filed #78875 for that. I suspect (with no data) that this PR
is still a net performance win because impeding ranged-for loops is
particularly egregious. But ideally we'd fix the optimizer and make
`add_and_deref` fine too.

There's also something funny going on with `std::ranges::find` which I
have not yet figured out yet, but I suspect there are some further
missed optimization opportunities.

Fixes #78829.

(CC @danakj)
2024-03-11 20:40:47 -07:00
David Benjamin
41658bafb7
[libc++][hardening] Add iterator validity checks on unordered containers (#80230)
These are simply null checks, so use `_LIBCPP_ASSERT_NON_NULL`. This
allows us to restore a bunch of the old debug tests. I've extended them
to also cover the const iterators, as those run through different
codepaths than the const ones.

This does the easier (and less important) half of #80212.
2024-03-11 18:39:21 -07:00
Louis Dionne
d2e57c5c36
[libc++] Re-enable the clang_modules_include test for Objective-C++ (#66801)
This reverts commit aa60b2687, which was a temporary workaround.
The underlying issue was fixed in Clang via c2c840bd92cf.

This was originally https://reviews.llvm.org/D158694.
2024-03-11 15:22:51 -04:00
Louis Dionne
18f49cf2e6
[libc++] Remove XFAIL for SIMD in optimized build (#84767)
It seems that updating the compiler in the CI resolved the issue, which
causes the test to be XPASSing now.

Fixes #74327
2024-03-11 15:21:38 -04:00
amilendra
6aef8dfe44
[libcxx] Update 128-bit-atomics feature test (#83841)
The `128-bit-atomics` libcxx feature is incorrectly named because tests
that are Xfailed with it is really using `int[128]`. Additionally,
because toolchain support for that feature is determined based on a much
smaller size (`char[16]`), tests would execute incorrectly without
required toolchain support.

So, rename `128-bit-atomics` as `1024-bit-atomics`, and use an
appropriate type to check for the presence of the feature.
2024-03-11 15:20:47 -04:00
A. Jiang
63ae5099b7
[libc++][test] Don't include test_format_context.h in parse.pass.cpp (#83734)
The `parse.pass.cpp` tests doen't need to call
`test_format_context_create` to create a `basic_format_context`, so they
shouldn't include `test_format_context.h`.

The `to_address` mechanism works around the iterator debugging
mechanisms of MSVC STL. Related to
[LWG3989](https://cplusplus.github.io/LWG/issue3989).

Discovered when implementing `formatter<tuple>` in MSVC STL. With the
inclusion removed, `std/utilities/format/format.tuple/parse.pass.cpp`
when using enhanced MSVC STL (and `/utf-8` option for MSVC).
2024-03-11 10:55:16 -04:00
Louis Dionne
02e0b7d405
[libc++] Add missing include in test (#84579)
That test is using std::toupper.
2024-03-11 09:51:59 -04:00
Nikolas Klauser
2a38551457
[libc++] Remove <tuple> from <variant> (#83183)
This moves a utility from `<tuple>` into an implementation detail header
and refactors the selection of the variant index type to use.
2024-03-11 14:04:51 +01:00
Mark de Wever
e19e8600cf
[RFC][libc++] Reworks clang-tidy selection. (#81362)
The current selection is done in the test scripts which gives the user
no control where to find clang-tidy. The version selection itself is
hard-coded and not based on the version of clang used.

This moves the selection to configuration time and tries to find a
better match.
- Mixing the version of clang-tidy and the clang libraries causes ODR
violations. This results in practice in crashes or incorrect results.
- Mixing the version of clang-tidy and the clang binary sometimes causes
issues with supported diagnostic flags. For example, flags tested
against clang 17 may not be available in clang-tidy 16.

Currently clang-tidy 18.1 can be used, it tests against the clang
libraries version 18. This is caused by the new LLVM version numbering
scheme.

The new selection tries to match the clang version or the version of the
HEAD and the last 3 releases. (During the release period libc++ supports
4 versions instead of the typical 3 versions.)
2024-03-09 18:03:52 +01:00
Nikolas Klauser
ee22e25564
[libc++] Remove <array> include from <span> (#83742)
This reduces the include time of `<span>` from 122ms to 78ms.
2024-03-09 12:49:36 +01:00
Stephan T. Lavavej
1c7607e8ee
[libc++][test] Fix MSVC warning C4127 in array.cons/initialization.pass.cpp (#79793)
This fixes MSVC warning C4127: conditional expression is constant.

Testing `TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED` by itself doesn't
emit this warning, but the condition here is more complicated. I'm
expanding the macro and mechanically simplifying the resulting code.

(Yeah, this warning is often annoying, and I introduced
`TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED` to avoid this warning
elsewhere, so it's disappointing that it doesn't make the compiler happy
here. If this change is undesirable, I can replace it with
`ADDITIONAL_COMPILE_FLAGS(cl-style-warnings)`, but ideally I'd like to
avoid having to suppress it.)

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-03-09 02:31:58 -08:00
Eric Fiselier
0bbada93a5 Actually disable the module generation tests.
LIT was never really meant to generate tests during discovery,
and we probably shouldn't be doing this.

This hack is even worse than the initial attempt because it buries the
"UNSUPPORTED" at the bottom of the test.
2024-03-08 12:17:07 -05:00
Louis Dionne
599ab6d63e Revert "[libc++] Disable module_std and module_std_compat tests"
It looks like that broke the CI even more. Reverting until I can
investigate.
2024-03-08 12:09:35 -05:00
Louis Dionne
9d5fdad7e5 [libc++] Disable module_std and module_std_compat tests
Those have been crippling the CI for over a week now. This is the only
solution I see until we gain a better understanding of why they fail.
Otherwise all other patches are blocked on these spurious failures in
the stage1 of the CI.
2024-03-08 11:05:19 -05:00
Will Hawkins
ba2236d300
[libcxx][NFC] Consolidate testing concept CanBePiped (#80154)
Almost every test needed a CanBePiped concept and each implemented it
separately, but identically. Consolidate all implementations into
test_range.h.
2024-03-08 09:25:51 -05:00
Louis Dionne
292a28df6c
[libc++] Enable availability based on the compiler instead of __has_extension (#84065)
__has_extension(...) doesn't work as intended when -pedantic-errors is
used with Clang. With that flag, __has_extension(...) is equivalent to
__has_feature(...), which means that checks like

    __has_extension(pragma_clang_attribute_external_declaration)

will return 0. In turn, this has the effect of disabling availability
markup in libc++, which is undesirable.

rdar://124078119
2024-03-07 15:12:21 -05:00
Lei Huang
e4d4cfa5a0
[libc++] Fixes time formatter test output for Linux on PowerPC (#75526)
Fix output to match actual.
2024-03-07 09:32:43 -05:00
Hristo Hristov
80f9458cf3
[libc++][sstream] P2495R3: Interfacing stringstreams with string_view (#80552)
Implements P2495R3 <https://wg21.link/P2495R3>
- https://eel.is/c++draft/version.syn#headerref:%3csstream%3e
- https://eel.is/c++draft/stringbuf
- https://eel.is/c++draft/stringbuf.general
- https://eel.is/c++draft/stringbuf.cons
- https://eel.is/c++draft/stringbuf.members
- https://eel.is/c++draft/istringstream
- https://eel.is/c++draft/istringstream.general
- https://eel.is/c++draft/istringstream.cons
- https://eel.is/c++draft/istringstream.members
- https://eel.is/c++draft/ostringstream
- https://eel.is/c++draft/ostringstream.general
- https://eel.is/c++draft/ostringstream.cons
- https://eel.is/c++draft/ostringstream.members
- https://eel.is/c++draft/stringstream
- https://eel.is/c++draft/stringstream.general
- https://eel.is/c++draft/stringstream.cons
- https://eel.is/c++draft/stringstream.members

References:
- https://eel.is/c++draft/string.streams
2024-03-05 08:49:49 +02:00
Louis Dionne
6fd27d5b03
[libc++] Don't generate the modulemap file (#80352)
We actually didn't generate anything in that file, so generating it via
CMake is useless.
2024-03-04 18:16:16 -05:00
Jake Egan
98418c27bc
[libc++][AIX] Use input redirection instead of piping for cin tests (#83184)
When echo is used for piping, lit uses the system echo rather than the
builtin echo. The system echo on AIX doesn't support the `-n` option,
which causes these tests to fail. Use input redirection, so the builtin
echo can be used.
2024-03-04 13:06:05 -05:00
Po-yao Chang
b29301cd40
[libc++][format] Handle range-underlying-spec (#81914)
An immediate colon signifeis that the range-format-spec contains only
range-underlying-spec.

This patch allows this code to compile and run:
```c++
std::println("{::<<9?}", std::span<const char>{"Hello", sizeof "Hello"});
```
2024-03-04 08:05:01 +08:00
Nikolas Klauser
33de5a316c
[libc++] Rename __fwd/hash.h to __fwd/functional.h and add reference_wrapper (#81445)
We forward declare `reference_wrapper` in multiple places already. This
moves the declaration to the canonical place and removes unnecessary
includes of `__functional/reference_wrapper.h`.
2024-03-03 20:45:17 +01:00
ZijunZhaoCCK
7d7d4752a8
[libc++] Set feature test macros __cpp_lib_ranges_contains and__cpp_lib_ranges_starts_ends_with (#81816)
ranges::contains: fdd089b50063
ranges::starts_with: 205175578e0d
ranges::ends_with: 0218ea4aaa54

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-02-29 16:06:32 -08:00
Louis Dionne
37dca605c9
[libc++] Clean up includes of <__assert> (#80091)
Originally, we used __libcpp_verbose_abort to handle assertion failures.
That function was declared from all public headers. Since we don't use
that mechanism anymore, we don't need to declare __libcpp_verbose_abort
from all public headers, and we can clean up a lot of unnecessary
includes.

This patch also moves the definition of the various assertion categories
to the <__assert> header, since we now rely on regular IWYU for these
assertion macros.

rdar://105510916
2024-02-29 10:12:22 -05:00
Dominik Wójt
d1a461dbb2
[libc++] tests with picolibc: prevent looking for unneeded "rt" library (#82262)
Picolibc does not provide the clock_gettime function nor the "rt" library.
check_library_exists was invalidly detecting the "rt" library due to cmake issue 
present, when cross-compiling[1]. This resulted with "chrono.cpp" trying to link
to the "rt" library and following error:
    unable to find library from dependent library specifier: rt

[1] https://gitlab.kitware.com/cmake/cmake/-/issues/18121
2024-02-29 08:54:58 +01:00
Nikolas Klauser
1530034166
[libc++] Remove unnecessary includes from <atomic> (#82880)
This reduces the include time of `<atomic>` from 135ms to 88ms.
2024-02-28 21:14:35 +01:00