Commit Graph

8475 Commits

Author SHA1 Message Date
Louis Dionne a34f246899 [libc++][ABI BREAK] Do not use the C++03 emulation for std::nullptr_t by default
We only support Clangs that implement nullptr as an extension in C++03 mode,
and we don't support GCC in C++03 mode. Hence, this patch disables the
use of the std::nullptr_t emulation in C++03 mode by default. Doing that
is technically an ABI break since it changes the mangling for std::nullptr_t.
However:

(1) The only affected users are those compiling in C++03 mode that have
    std::nullptr_t as part of their ABI, which should be reasonably rare.

(2) Those users already have a lingering problem in that their code will
    be incompatible in C++03 and C++11 modes because of that very ABI break.
    Hence, the only users that could really be inconvenienced about this
    change is those that planned on compiling in C++03 mode forever - for
    other users, we're just breaking them now instead of letting them break
    themselves later on when they try to upgrade to C++11.

(3) The ABI break will cause a linker error since the mangling changed,
    and will not result in an obscure runtime error.

Furthermore, if anyone is broken by this, they can define the
_LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION macro to return to the
previous behavior. We will then remove that macro after shipping
this for one release if we haven't seen widespread issues.

Concretely, the motivation for making this change is to make our own ABI
consistent in C++03 and C++11 modes and to remove complexity around the
definition of nullptr.

Furthermore, we could investigate making nullptr a keyword in C++03 mode
as a Clang extension -- I don't think that would break anyone, since
libc++ already defines nullptr as a macro to something else. Only users
that do not use libc++ and compile in C++03 mode could potentially be
broken by that.

Differential Revision: https://reviews.llvm.org/D109459
2021-11-30 06:01:45 -05:00
Louis Dionne a8278a747d [libc++] Fix incorrect REQUIRES on a locale-dependent test
The test doesn't depend specifically on the en_US.UTF-8 locale, instead
it depends on whether localization support exists, period.

Differential Revision: https://reviews.llvm.org/D114708
2021-11-29 13:42:57 -05:00
Mark de Wever cb68fc814a [libc++] Add myself to the credits.
Noticed while updating the credits for the to_chars patch.
2021-11-28 15:24:45 +01:00
Mark de Wever 730dccb986 [libc++] Remove support for Clang 9 and older.
I encountered this while reviewing an unrelated patch. Will land after
the CI passes.

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D114673
2021-11-28 15:17:05 +01:00
Mark de Wever 01631ffcfc [libc++][format] Adds formatting benchmarks.
These benchmarks will be used to test the performance inpact of the next
set of optimization patches.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D110501
2021-11-28 13:12:53 +01:00
Konstantin Boyarinov 56c8ad237a [libcxx][NFC] Add tests for associative containers key_comp and value_comp
Add missing tests to improve associative containers code coverage:
 - Tests for key_comp() and value_comp() observers
 - Tests for std::map and std::multimap value_compare member class

Reviewed by: ldionne, rarutyun, #libc

Differential Revision: https://reviews.llvm.org/D113998
2021-11-27 01:46:22 +03:00
Louis Dionne 5c454033dd [libc++] Trigger rebuild of the Docker image so we get a new nightly Clang 2021-11-26 12:57:30 -05:00
Louis Dionne f18f9ce366 [libc++] Properly handle errors happening during Lit configuration
Instead of silently swallowing errors that happen during Lit configuration
(for example trying to obtain compiler macros but compiling fails), raise
an exception with some amount of helpful information.

This should avoid the possibility of silently configuring Lit in a bogus
way, and also provides more helpful information when things fail.

Note that this requires a bit more finesse around how we handle some
failing configuration checks that we would previously return None for.

Differential Revision: https://reviews.llvm.org/D114010
2021-11-26 11:03:15 -05:00
Louis Dionne 7dc9a03cfd [libc++] Add missing __format__ attributes
-Wformat-nonliteral was turned on in https://reviews.llvm.org/D112927,
however we forgot to apply some __format__ attributes in Linux specific
code paths, which led to warnings when building on Linux. This patch
addresses that oversight.

Differential Revision: https://reviews.llvm.org/D113876
2021-11-26 11:03:14 -05:00
Mikhail Maltsev d8f3cdfed0 [libcxx] Implement three-way comparison for std::reverse_iterator
This patch implements operator<=> for std::reverse_iterator and
also adds a test that checks that three-way comparison of different
instantiations of std::reverse_iterator works as expected (related to
D113417).

Reviewed By: ldionne, Quuxplusone, #libc

Differential Revision: https://reviews.llvm.org/D113695
2021-11-26 10:12:19 +00:00
Louis Dionne ebfeeec4c4 [libunwind] Fix testing with sanitizers enabled
When testing with sanitizers enabled, we need to link against a plethora
of system libraries. Using `-nodefaultlibs` like we used to breaks this,
and we would have to add all these system libraries manually, which is
not portable and error prone. Instead, stop using `-nodefaultlibs` so
that we get the libraries added by default by the compiler.

The only caveat with this approach is that we are now relying on the
fact that `-L <path-to-local-libunwind>` will cause the just built
libunwind to be selected before the system implementation (either of
libunwind or libgcc_s.so), which is somewhat fragile.

This patch also turns the 32 bit multilib build into a soft failure
since we are in the process of removing it anyway, see D114473 for
details. This patch is incompatible with the 32 bit multilib build
because Ubuntu does not provide a proper libstdc++ for 32 bits, and
that is required when running with sanitizers enabled.

Differential Revision: https://reviews.llvm.org/D114385
2021-11-25 15:28:17 -05:00
Louis Dionne 151a7dafd3 [libc++] Fix ssize test that made an assumption about ptrdiff_t being 'long'
On some platforms like armv7m, the size() method of containers returns
unsigned long, while ptrdiff_t is just int. Hence, std::ssize_t ends up
being long, which is not the same as ptrdiff_t. This is usually not an
issue because std::ptrdiff_t is long, so everything works out, but it
breaks on some more exotic architectures.

Differential Revision: https://reviews.llvm.org/D114563
2021-11-25 13:12:47 -05:00
Joe Loser 3e7452a812
[libc++] Avoid overload resolution in path comparison operators
Rework `std::filesystem::path::operator==` and friends to avoid overload
resolution and atomic constraint caching issues shown from
https://reviews.llvm.org/D113161.

Always call `__compare(string_view)` from the comparison operators which avoids
overload resolution.

Differential Revision: https://reviews.llvm.org/D114570
2021-11-25 11:40:55 -05:00
Joe Loser 68e7e76a9b
[libc++] Fix constraints for string_view's iterator/sentinel constructor
The `string_view` constructor taking an iterator/sentinel uses concepts
instead of type traits like the Standard states. Using `same_as` instead
of `is_same_v` should be harmless. Prefer `std::is_same_v` instead which is
cheaper to compile. Replace `convertible_to` with `is_convertible_v` as
well.

This observation came up while working on
https://reviews.llvm.org/D113161

Differential Revision: https://reviews.llvm.org/D114561
2021-11-25 11:39:59 -05:00
Johan Berg 68e2231f87 [libc++] Value-initialize unique_ptr's deleter_type
According to the C++ standard, the stored pointer and the stored deleter
should be value-initialized.

Differential Revision: https://reviews.llvm.org/D113612
2021-11-24 17:31:34 -05:00
Louis Dionne 7a0584fe3f [libc++] Fix backdeployment annotations for std::filesystem
In 1fa27f2a10, we made <filesystem>'s iterator types model concepts
from <ranges>, but we forgot to add the appropriate availability
annotations. This broke back-deployment to platforms that don't have
<filesystem> for which we have availability annotations.

For some reason, this wasn't caught by our back-deployment CI.
I believe this is due to the fact that we use a slightly older
compiler in the CI, and perhaps that compiler does not honour
our `#pragma clang attribute push` properly.

Differential Revision: https://reviews.llvm.org/D114456
2021-11-24 16:58:15 -05:00
Louis Dionne f244166c47 [libc++] Handle armv7m in two architecture dependent tests 2021-11-24 16:40:26 -05:00
Louis Dionne 3a183a49f2 [libc++] Fix two tests that were failing in freestanding mode
We were defining `main()` but never returning from it.
2021-11-24 16:40:26 -05:00
Louis Dionne 13fa4fcfe7 [libc++] Tidy up how %T and %t are created during configuration checks
Instead of having ad-hoc cleanup in various places, handle all creation
and removal of temporary files and directories inside _makeConfigTest.

As a fly-by, also remove testPrefix since we don't keep any source file
around anymore. Setting a prefix for the files is hence not useful anymore.

Differential Revision: https://reviews.llvm.org/D114390
2021-11-23 09:51:22 -05:00
Christopher Di Bella b8bba3d801 [libcxx][NFC] adds var-const@ as the owner for the uninitialised algos 2021-11-22 18:44:13 +00:00
Christopher Di Bella c5bf8d6f76 [libcxx][NFC] adds status entry for ranges algorithms
Differential Revision: https://reviews.llvm.org/D114295
2021-11-22 18:35:11 +00:00
Louis Dionne c0efe8f266 [libc++][NFC] Reformat comment about D68480 support 2021-11-22 13:34:18 -05:00
Arthur O'Dwyer d8380ad977 [libc++] [P1614] Implement [cmp.alg]'s std::{strong,weak,partial}_order.
This does not include `std::compare_*_fallback`; those are coming later.

There's still an open question of how to implement std::strong_order
for `long double`, which has 80 value bits and 48 padding bits on x86-64,
and which is presumably *not* IEEE 754-compliant on PPC64 and so on.
So that part is left unimplemented.

Differential Revision: https://reviews.llvm.org/D110738
2021-11-22 13:24:28 -05:00
Arthur O'Dwyer 344cef6695 [libc++] Granularize the <random> header. NFCI.
Actually there's one functional change here, which is that users can
no longer depend on <random> to include all of C++20 <concepts>. That
inclusion is so new that we believe nobody should be depending on it
yet, even in the presence of Hyrum's Law. We keep the includes of <vector>,
<algorithm>, etc., so as not to break pre-C++20 Hyrum's Law users.

Differential Revision: https://reviews.llvm.org/D114281
2021-11-22 13:24:27 -05:00
Louis Dionne e7cee55c9d [libc++] Remove uses of printf in some test support headers
In the test suite, we generally don't use printf or other reporting
utilities. It's not that it wouldn't be useful, it's just that some
platforms don't support IO.

Instead, we try to keep test cases small and self-contained so that
we can reasonably easily reproduce failures locally and debug them.
This patch removes printf in some of the last places in the test suite
that used it. The only remaining places are in a deque test and in the
filesystem tests. The filesystem tests are arguably fine to keep using
IO, since we're testing <filesystem>. The deque test will be handled
separately.

Differential Revision: https://reviews.llvm.org/D114282
2021-11-22 12:01:18 -05:00
Nikolas Klauser 04a6dc06a0 [libc++] [NFC] Mark P0858R0 as implemented
P0858R0 seems to be implemented. D93830 sets `__cpp_lib_string_view` and D80452 sets `__cpp_lib_array_constexpr`.

Reviewed By: Quuxplusone, Mordante, ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D114344
2021-11-22 17:58:22 +01:00
Mark de Wever cc9fdedba7 [libc++] Improve CMake include directory search.
This patch has been tested in D70631, but it should be reviewed
separately.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D114248
2021-11-22 17:35:49 +01:00
Joe Loser a60b63940a
[libc++][NFC] Sort includes in __ranges/concepts.h
Differential Revision: https://reviews.llvm.org/D114328
2021-11-21 19:34:02 -05:00
Nikolas Klauser 1dc62f2653 [libc++] Implement P1272R4 (std::byteswap)
Implement P1274R4

Reviewed By: Quuxplusone, Mordante, #libc

Spies: jloser, lebedev.ri, mgorny, libcxx-commits, arichardson

Differential Revision: https://reviews.llvm.org/D114074
2021-11-22 01:28:18 +01:00
Joe Loser dca681fee9
[libc++][NFC] Fix typo in ranges::iterator_t synopsis
The `iterator_t` alias template is on `T` not a `R` like the other
neighboring alias templates. Fix the typo.
2021-11-20 19:15:00 -05:00
Arthur O'Dwyer e74114add3 [libc++] [doc] Mark some spaceship-related LWG issues as "Complete."
LWG3330 has been "Completed" since D99309, which was in the 13.x timeframe.
Reviewed as part of D110738.
2021-11-20 18:16:22 -05:00
Arthur O'Dwyer 401b76fdf2 [libc++] [test] Eliminate libcpp-no-noexcept-function-type and libcpp-no-structured-bindings.
At this point, every supported compiler that claims a -std=c++17 mode
should also support these features.

Differential Revision: https://reviews.llvm.org/D113436
2021-11-20 11:44:57 -05:00
Louis Dionne e059329b83 [libc++][NFC] Add missing include in test 2021-11-19 16:01:55 -05:00
Arthur O'Dwyer b07b5bd727 [libc++] Test that our algorithms never copy a user-provided comparator.
This is not mandated by the standard, so it goes in libcxx/test/libcxx/.
It's certainly arguable that the algorithms changed here
(`is_heap`, `is_sorted`, `min`, `max`) are harmless and we should
just let them copy their comparators once. But at the same time,
it's nice to have all our algorithms be 100% consistent and never
copy a comparator, not even once.

Differential Revision: https://reviews.llvm.org/D114136
2021-11-19 15:03:24 -05:00
Louis Dionne e0f58444e1 [libc++] Fix feature test macro for __cpp_lib_to_chars
We would have been defining it in <utility> instead of <charconv>. For
the time being, this doesn't change anything since we don't implement
the feature test macro anyways.

Also, as a fly-by, this removes obsolete feature test macro tests. There
was a brief time back in the days when we wrote feature test macro tests
manually. In particular, we had test files for __cpp_lib_to_chars and
__cpp_lib_memory_resource. Since we now have a principled way of generating
these tests with scripts, this commit removes the obsolete (and empty)
tests for these two feature test macros.

Differential Revision: https://reviews.llvm.org/D114243
2021-11-19 14:26:34 -05:00
Louis Dionne e1ce3dabf0 [libc++] Fix some tests that were broken in the single-threaded configuration
We never noticed it because our CI doesn't actually build against a C
library that doesn't have threading functionality, however building
against a truly thread-free platform surfaces these issues.

Differential Revision: https://reviews.llvm.org/D114242
2021-11-19 14:24:15 -05:00
Louis Dionne 1b4c0cb391 [libc++] Avoid potential truncation warnings in std::abs test
One some platforms, -Wimplicit-int-conversion is enabled by default,
which can lead to additional warnings being triggered in this test.
Since we're only trying to test errors related to calling abs(), the
assignment is superfluous.

As a fly-by fix, correct one instance of ::abs to std::abs and made
the test a .verify.cpp test instead.

Differential Revision: https://reviews.llvm.org/D114244
2021-11-19 14:22:26 -05:00
Mark de Wever ed86610c7b [libc++][nfc] Move functions to a generic place.
This allows the floating-point formatter to use the same functions as
the integral formatter. This was tested in D114001.
2021-11-19 16:38:35 +01:00
Mark de Wever 3624c4d845 [libc++] Adds (to|from)_chars_result operator==.
Implements part of P1614 The Mothership has Landed.

Reviewed By: #libc, Quuxplusone, Mordante

Differential Revision: https://reviews.llvm.org/D112366
2021-11-19 16:29:33 +01:00
Kent Ross 870dfa6b08 [libc++][doc] Mark project for [cmp.concept] done
Mark [cmp.concept] implementation as completed in our documentation.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D114203
2021-11-18 20:15:54 -08:00
Konstantin Varlamov 3b463c4528 [libc++][NFC] Assign some Ranges tasks to varconst.
Specifically:
- [special.mem.concepts];
- [specialized.algorithms].
2021-11-18 15:15:21 -08:00
Fabian Wolff dc1c27149f [libc++] Cast to the right `difference_type` in various algorithms
Differential Revision: https://reviews.llvm.org/D113868
2021-11-18 17:07:36 -05:00
Muiez Ahmed 27ea67136e [SystemZ][z/OS] Fix filesystem testing
This patch resolves many of the failures in the `filesystems/` buckets in the libc++ tests. It adds the correct flag to `fopen` and marks a test case as unsupported. In particular, that test assumes time is stored as a 64 bit value when on MVS it is stored as 32 bit.

Differential Revision: https://reviews.llvm.org/D113298
2021-11-18 15:57:50 -05:00
Muiez Ahmed 049f6c29a6 [libc++] Resolve missing table_size symbol
The aim of this patch is to resolve the missing `table_size` symbol (see reduced test case). That const variable is declared and defined in //libcxx/include/locale//; however, the test case suggests that the symbol is missing. This is due to a C++ pitfall (highlighted [[ https://quuxplusone.github.io/blog/2020/09/19/value-or-pitfall/ | here ]]). In summary, assigning the reference of `table_size` doesn't enforce the const-ness and expects to find `table_size` in the DLL. The fix is to use `constexpr` or have an out-of-line definition in the src (for consistency).

Differential Revision: https://reviews.llvm.org/D110647
2021-11-18 15:49:45 -05:00
Arthur O'Dwyer 1ce516d43f [libc++] Minor fixups in the new introsort code.
Differential Revision: https://reviews.llvm.org/D114133
2021-11-18 11:01:41 -05:00
Arthur O'Dwyer 4a8734deb7 [libc++] [test] Add "robust_re_difference_type.compile.pass.cpp" for all the algorithms.
Also, mark these tests as compile-only. They actually are safe to run — notice that
the code "runs" at constexpr-time in C++20, without error — because both of the
input ranges are entirely filled with nullptr, so no matter how you shuffle the
elements, they remain sorted and partitioned and heapified and everything.
But there's no real reason to run them at runtime, so let's just avoid the distraction.

Test cases that fail in trunk right now are commented out with `TODO FIXME`.

Differential Revision: https://reviews.llvm.org/D113906
2021-11-18 00:12:41 -05:00
Louis Dionne 92832e4889 [libc++] Enable <atomic> when threads are disabled
std::atomic is, for the most part, just a thin veneer on top of compiler
builtins. Hence, it should be available even when threads are not available
on the system, and in fact there has been requests for such support.

This patch:
- Moves __libcpp_thread_poll_with_backoff to its own header so it can
  be used in <atomic> when threads are disabled.
- Adds a dummy backoff policy for atomic polling that doesn't know about
  threads.
- Adjusts the <atomic> feature-test macros so they are provided even when
  threads are disabled.
- Runs the <atomic> tests when threads are disabled.

rdar://77873569

Differential Revision: https://reviews.llvm.org/D114109
2021-11-17 23:02:58 -05:00
Chuanqi Xu af9f3c6d86 [Coroutine] Warn deprecated 'std::experimental::coro' uses
Since we've decided the to not support std::experimental::coroutine*, we
should tell the user they need to update.

Reviewed By: Quuxplusone, ldionne, Mordante

Differential Revision: https://reviews.llvm.org/D113977
2021-11-18 09:41:01 +08:00
Louis Dionne eb8650a757 [runtimes][NFC] Remove filenames at the top of the license notice
We've stopped doing it in libc++ for a while now because these names
would end up rotting as we move things around and copy/paste stuff.
This cleans up all the existing files so as to stop the spreading
as people copy-paste headers around.
2021-11-17 16:30:52 -05:00
Louis Dionne 95741660b4 [libc++][NFC] Re-indent and re-order includes in uses_alloc_types.h 2021-11-17 16:13:58 -05:00
Louis Dionne 3e957e5d66 [libc++] Refactor tests for trivially copyable atomics
- Replace irrelevant synopsis by a comment
- Use a .verify.cpp test instead of .compile.fail.cpp
- Remove unnecessary includes in one of the tests (was a copy-paste error)

Differential Revision: https://reviews.llvm.org/D114094
2021-11-17 13:32:12 -05:00
Louis Dionne c0f87e8382 [libc++] Remove _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
All supported compilers support spaceship in C++20 nowadays.

Differential Revision: https://reviews.llvm.org/D113938
2021-11-17 10:59:57 -05:00
Martin Storsjö efbe9ae23f Revert "[runtimes] Fix building initial libunwind+libcxxabi+libcxx with compiler implied -lunwind"
This reverts commit 7c3d19ab7b.

This commit was reported as causing build problems for the amdgpu
buildbot in https://reviews.llvm.org/D113253#3137097.
2021-11-17 12:50:33 +02:00
Martin Storsjö f5ca3ac748 [libcxx] [ci] Add CI configurations for MinGW
Mention support for MinGW in the docs. Rename the existing windows
CI jobs to Clang-cl, as both Clang-cl and MinGW are equally much
"Windows", just different toolchain environments.

Add an XFAIL for a recently added test that fails in the MinGW DLL
configuration (with an explanation of what's causing the failure).

Differential Revision: https://reviews.llvm.org/D112215
2021-11-17 10:00:50 +02:00
Mircea Trofin b2fbd45d23 Revert "Reland "[benchmarks] Move libcxx's fork of google/benchmark and llvm/utils'"""
This reverts commit 1ee32055ea.

We hit additional bot failures; in particular, Fuchsia's seems to be
related to how CMakeLists are ingested, see https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8830380874445931681/overview
2021-11-16 16:35:06 -08:00
Martin Storsjö 7c3d19ab7b [runtimes] Fix building initial libunwind+libcxxabi+libcxx with compiler implied -lunwind
This does mostly the same as D112126, but for the runtimes cmake files.
Most of that is straightforward, but the interdependency between
libcxx and libunwind is tricky:

Libunwind is built at the same time as libcxx, but libunwind is not
installed yet. LIBCXXABI_USE_LLVM_UNWINDER makes libcxx link directly
against the just-built libunwind, but the compiler implicit -lunwind
isn't found. This patch avoids that by adding --unwindlib=none if
supported, if we are going to link explicitly against a newly built
unwinder anyway.

Differential Revision: https://reviews.llvm.org/D113253
2021-11-16 23:04:06 +02:00
Danila Kutenin a45d2287ad [libc++] Unspecified behavior randomization in libc++
This effort is dedicated to deflake the tests of the users which depend
on the unspecified behavior of algorithms and containers. This also
might help updating the sorting algorithm in libcxx which has the
quadratic worst case in the future or at least create a new one under
flag.

For detailed design, please see the design doc I provide in the patch.

Differential Revision: https://reviews.llvm.org/D96946
2021-11-16 15:55:33 -05:00
Louis Dionne df0c2b917d [libc++] Adjust comment about ABI change and std::bad_function_call 2021-11-16 15:32:15 -05:00
Konstantin Varlamov 434dc0a5bc [libc++] Always define a key function for std::bad_function_call in the dylib
However, whether applications rely on the std::bad_function_call vtable
being in the dylib is still controlled by the ABI macro, since changing
that would be an ABI break.

Also separate preprocessor definitions for whether to use a key function
and whether to use a `bad_function_call`-specific `what` message
(`what` message is mandated by [LWG2233](http://wg21.link/LWG2233)).

Differential Revision: https://reviews.llvm.org/D92397
2021-11-16 11:23:27 -08:00
Nikolas Klauser 1ff87ec235 [libc++] [NFC] Disable clang-tidy's readability-identifier-naming check
In libc++ most of the names are not conforming to the llvm style. Removing the readability-identifier-naming check removes almost all clang-tidy warnings. For example in `<string>` the warning count goes from 1001 warnings down to 7.

Reviewed By: #libc, Mordante, ldionne

Spies: Mordante, Quuxplusone, aheejin, libcxx-commits, carlosgalvezp

Differential Revision: https://reviews.llvm.org/D113849
2021-11-16 20:14:07 +01:00
Mircea Trofin 1ee32055ea Reland "[benchmarks] Move libcxx's fork of google/benchmark and llvm/utils'""
This reverts commit e7568b68da and relands
c6f7b720ec.

The culprit was: missed that libc also had a dependency on one of the
copies of `google-benchmark`

Also opportunistically fixed indentation from prev. change.

Differential Revision: https://reviews.llvm.org/D112012
2021-11-16 10:33:31 -08:00
Louis Dionne 5c539ea9f0 [libc++] Perform the bootstrapping build before legacy builds in CI
This is to help reduce latency by running longer jobs before shorter ones.
2021-11-16 12:44:22 -05:00
Mircea Trofin e7568b68da Revert "[benchmarks] Move libcxx's fork of google/benchmark and llvm/utils'"
This reverts commit c6f7b720ec.

Some buildbots are failing, will investigate and reland.
Example:
  https://lab.llvm.org/buildbot#builders/138/builds/14067
  https://lab.llvm.org/buildbot#builders/73/builds/20159
2021-11-16 09:28:50 -08:00
Mircea Trofin c6f7b720ec [benchmarks] Move libcxx's fork of google/benchmark and llvm/utils'
under third-party

This change:
- moves the libcxx copy of `google/benchmark` to
`third-party/benchmkark`
- points the 2 uses of the library (libcxx and llvm/utils) to this copy

We picked the licxx copy because it is the most up to date.

Differential Revision: https://reviews.llvm.org/D112012
2021-11-16 09:16:11 -08:00
Nilay Vaish 7f287390d7 [libc++] Add introsort to avoid O(n^2) behavior
This commit adds a benchmark that tests std::sort on an adversarial inputs,
and uses introsort in std::sort to avoid O(n^2) behavior on adversarial
inputs.

Inputs where partitions are unbalanced even after 2 log(n) pivots have
been selected, the algorithm switches to heap sort to avoid the
possibility of spending O(n^2) time on sorting the input.
Benchmark results show that the intro sort implementation does
significantly better.

Benchmarking results before this change. Time represents the sorting
time required per element:

----------------------------------------------------------------------------------------------------------
Benchmark                                                                Time             CPU   Iterations
----------------------------------------------------------------------------------------------------------
BM_Sort_uint32_QuickSortAdversary_1                                   3.75 ns         3.74 ns    187432960
BM_Sort_uint32_QuickSortAdversary_4                                   3.05 ns         3.05 ns    231211008
BM_Sort_uint32_QuickSortAdversary_16                                  2.45 ns         2.45 ns    288096256
BM_Sort_uint32_QuickSortAdversary_64                                  32.8 ns         32.8 ns     21495808
BM_Sort_uint32_QuickSortAdversary_256                                  132 ns          132 ns      5505024
BM_Sort_uint32_QuickSortAdversary_1024                                 498 ns          497 ns      1572864
BM_Sort_uint32_QuickSortAdversary_16384                               3846 ns         3845 ns       262144
BM_Sort_uint32_QuickSortAdversary_262144                             61431 ns        61400 ns       262144
BM_Sort_uint64_QuickSortAdversary_1                                   3.93 ns         3.92 ns    181141504
BM_Sort_uint64_QuickSortAdversary_4                                   3.10 ns         3.09 ns    222560256
BM_Sort_uint64_QuickSortAdversary_16                                  2.50 ns         2.50 ns    283639808
BM_Sort_uint64_QuickSortAdversary_64                                  33.2 ns         33.2 ns     21757952
BM_Sort_uint64_QuickSortAdversary_256                                  132 ns          132 ns      5505024
BM_Sort_uint64_QuickSortAdversary_1024                                 478 ns          477 ns      1572864
BM_Sort_uint64_QuickSortAdversary_16384                               3932 ns         3930 ns       262144
BM_Sort_uint64_QuickSortAdversary_262144                             61646 ns        61615 ns       262144

Benchmarking results after this change:

----------------------------------------------------------------------------------------------------------
Benchmark                                                                Time             CPU   Iterations
----------------------------------------------------------------------------------------------------------
BM_Sort_uint32_QuickSortAdversary_1                                   6.31 ns         6.30 ns    107741184
BM_Sort_uint32_QuickSortAdversary_4                                   4.51 ns         4.50 ns    158859264
BM_Sort_uint32_QuickSortAdversary_16                                  3.00 ns         3.00 ns    223608832
BM_Sort_uint32_QuickSortAdversary_64                                  44.8 ns         44.8 ns     15990784
BM_Sort_uint32_QuickSortAdversary_256                                 69.0 ns         68.9 ns      9961472
BM_Sort_uint32_QuickSortAdversary_1024                                 118 ns          118 ns      6029312
BM_Sort_uint32_QuickSortAdversary_16384                                175 ns          175 ns      4194304
BM_Sort_uint32_QuickSortAdversary_262144                               210 ns          210 ns      3407872
BM_Sort_uint64_QuickSortAdversary_1                                   6.75 ns         6.73 ns    103809024
BM_Sort_uint64_QuickSortAdversary_4                                   4.53 ns         4.53 ns    160432128
BM_Sort_uint64_QuickSortAdversary_16                                  2.98 ns         2.97 ns    234356736
BM_Sort_uint64_QuickSortAdversary_64                                  44.3 ns         44.3 ns     15990784
BM_Sort_uint64_QuickSortAdversary_256                                 69.2 ns         69.2 ns     10223616
BM_Sort_uint64_QuickSortAdversary_1024                                 119 ns          119 ns      6029312
BM_Sort_uint64_QuickSortAdversary_16384                                173 ns          173 ns      4194304
BM_Sort_uint64_QuickSortAdversary_262144                               212 ns          212 ns      3407872

Differential Revision: https://reviews.llvm.org/D113413
2021-11-16 11:38:46 -05:00
Louis Dionne 4eda928660 [libc++] Add missed comment in https://reviews.llvm.org/D113910 2021-11-16 11:36:06 -05:00
Mark de Wever bfc253c000 [libc++][nfc] Improve standard conformance.
The return type of the deleted functions doesn't match the synopsis in
the standard.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D114000
2021-11-16 17:30:35 +01:00
Mark de Wever 3ddede8bfa [libc++][doc] Update format implementation status. 2021-11-16 17:29:40 +01:00
Nilay Vaish d17d89f4eb [libc++] Remove not needed call to __is_long()
The string is known to be long since __grow_by unconditionally calls
__set_long_cap().

Differential Revision: https://reviews.llvm.org/D113910
2021-11-16 11:26:13 -05:00
Matheus Izvekov 35f798d05d
[libcxx] CI: only build native target for bootstrapping-build
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D113950
2021-11-16 17:22:30 +01:00
Mark de Wever 0e50216f22 [libc++][format][nfc] Remove dead code.
This was an early part of the prototype. This has never been shipped
enabled and the final version of this code looks completely different.
2021-11-16 16:02:26 +01:00
Mark de Wever 59a98dc208 [libc++][doc] Fix copy pasted comment. 2021-11-16 15:56:59 +01:00
Mark de Wever f0bb6c760c [libc++][doc] Add a todo.
As suggested in D113831.
2021-11-16 15:56:29 +01:00
Mark de Wever 5baa4ee30b [libc++][NFC] Move format_to_n_result.
Places `format_to_n_result` to its own file. While working on D112361 it
turns out the type will be used outside the format header.

Reviewed By: #libc, Quuxplusone, Mordante

Differential Revision: https://reviews.llvm.org/D113831
2021-11-16 15:51:49 +01:00
Zbigniew Sarbinowski 422cf2b506 [SystemZ][z/OS] Fix warnings from unsigned int to long in 32-bit mode
This patch fixes the warnings which shows up when libcxx library started to be compiled in 32-bit mode on z/OS.
More specifically, the assignment from unsigned int to time_t aka long was flags as follows:
 ```
libcxx/include/c++/v1/__support/ibm/nanosleep.h:31:11: warning: implicit conversion changes signedness: 'unsigned int' to 'time_t' (aka 'long') [-Wsign-conversion]
  __sec = sleep(static_cast<unsigned int>(__sec));
        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libcxx/include/c++/v1/__support/ibm/nanosleep.h:36:36: warning: implicit conversion changes signedness: 'unsigned int' to 'long' [-Wsign-conversion]
      __rem->tv_nsec = __micro_sec * 1000;
                     ~ ~~~~~~~~~~~~^~~~~~
libcxx/include/c++/v1/__support/ibm/nanosleep.h:47:36: warning: implicit conversion changes signedness: 'unsigned int' to 'long' [-Wsign-conversion]
      __rem->tv_nsec = __micro_sec * 1000;
                     ~ ~~~~~~~~~~~~^~~~~~
3 warnings generated.
```

Here is a small test case illustrating the issue:

```
typedef long    time_t ;
unsigned int sleep(unsigned int );
int main() {
  time_t sec = 0;
#ifdef FIX
  sec = static_cast<time_t>(sleep(static_cast<unsigned int>(sec)));
#else
  sec = sleep(static_cast<unsigned int>(sec));
#endif
}
```
clang++ -c -Wsign-conversion -m32 t.C
```
t.C:8:9: warning: implicit conversion changes signedness: 'unsigned int' to 'time_t' (aka 'long') [-Wsign-conversion]
  sec = sleep(static_cast<unsigned int>(sec));
      ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reviewed By: ldionne, #libc, Quuxplusone, Mordante

Differential Revision: https://reviews.llvm.org/D112837
2021-11-16 13:51:35 +00:00
Chuanqi Xu 2e6ae1d3f2 [libcxx] [Coroutine] Conform Coroutine Implementation
Since coroutine is merged in C++ standard and the support for coroutine
seems relatively stable. It's the time to move the implementation of
coroutine out of the experimental directory and the std::experimental
namespace. This patch creates header <coroutine> with conformed
implementation with C++ standard. To avoid breaking user's code too
fast, the <experimental/coroutine> header is remained. Note that
<experimental/coroutine> is deprecated and it would be removed in
LLVM15.

Reviewed By: Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D109433
2021-11-16 14:13:13 +08:00
Matheus Izvekov c9e46219f3
[clang] retain type sugar in auto / template argument deduction
This implements the following changes:
* AutoType retains sugared deduced-as-type.
* Template argument deduction machinery analyses the sugared type all the way
down. It would previously lose the sugar on first recursion.
* Undeduced AutoType will be properly canonicalized, including the constraint
template arguments.
* Remove the decltype node created from the decltype(auto) deduction.

As a result, we start seeing sugared types in a lot more test cases,
including some which showed very unfriendly `type-parameter-*-*` types.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Reviewed By: rsmith, #libc, ldionne

Differential Revision: https://reviews.llvm.org/D110216
2021-11-15 23:07:45 +01:00
Louis Dionne 855a419b92 [libc++] Add missing _LIBCPP_HIDE_FROM_ABI to __rewrap_iter 2021-11-15 10:10:33 -05:00
Mikhail Maltsev 6938270fa6 [libcxx] Fix enable_if condition of std::reverse_iterator::operator=
The template std::is_assignable<T, U> checks that T is assignable from
U. Hence, the order of operands in the instantiation of
std::is_assignable in the std::reverse_iterator::operator= condition
should be reversed.

This issue remained unnoticed because std::reverse_iterator has an
implicit conversion constructor. This patch adds a test to check that
the assignment operator is used directly, without any implicit
conversions. The patch also adds a similar test for
std::move_iterator.

Reviewed By: Quuxplusone, ldionne, #libc

Differential Revision: https://reviews.llvm.org/D113417
2021-11-15 13:08:36 +00:00
Matheus Izvekov 6438a52df1
Revert "[clang] retain type sugar in auto / template argument deduction"
This reverts commit 4d8fff477e.
2021-11-15 00:29:05 +01:00
Mark de Wever b19e823ff9 [libc++][NFC] Fixes code alignment.
D112904 fixed some code alignment issues, but it seems only line was
omitted. (Found while resolving merge conflicts for my own patches.)
2021-11-13 19:11:24 +01:00
Matheus Izvekov 4d8fff477e
[clang] retain type sugar in auto / template argument deduction
This implements the following changes:
* AutoType retains sugared deduced-as-type.
* Template argument deduction machinery analyses the sugared type all the way
down. It would previously lose the sugar on first recursion.
* Undeduced AutoType will be properly canonicalized, including the constraint
template arguments.
* Remove the decltype node created from the decltype(auto) deduction.

As a result, we start seeing sugared types in a lot more test cases,
including some which showed very unfriendly `type-parameter-*-*` types.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D110216
2021-11-13 03:35:22 +01:00
David Tenty 4602f52d48 [libcxx][AIX] XFAIL tests enabled by locale.fr_FR.UTF-8
We missed the tests in the earlier XFAIL-ing because the locale.fr_FR.UTF-8
feature wasn't available, but since an upgrade these are now showing up
on the CI.

Differential Revision: https://reviews.llvm.org/D113791
2021-11-12 16:28:24 -05:00
Alfsonso Gregory f46f93b478 [libc++][NFC] Resolve Python 2 FIXME
We don't use Python 2 anymore, so let us do the recommended fix instead
of using the workaround made for Python 2.

Differential Revision: https://reviews.llvm.org/D107715
2021-11-12 13:55:22 -05:00
Brian Cain 2d0aede515 [libcxx] Change the type of __size to correspond
__size was declared as unsigned which was compatible with
2021-11-12 08:30:38 -08:00
Daniel McIntosh 75ecd1f38c [libcxx][format] Fix how we handle char traits in formatter<string> and formatter<string_view>
Right now we drop the char_traits template argument, which presumes that
string<_CharT, _Traits> and string<_CharT> are interchangeable.

Reviewed By: Mordante, #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D112017
2021-11-11 14:49:40 -05:00
Louis Dionne dce5fc56b6 [libc++] Implement file_clock::{to,from}_sys
This is part of https://wg21.link/P0355R7. I am adding these methods
to provide an alternative for the {from,to}_time_t methods that were
removed in https://llvm.org/D113027.

Differential Revision: https://reviews.llvm.org/D113430
2021-11-11 14:17:02 -05:00
Louis Dionne 4e70b50b74 [libc++] Disallow running the libc++ benchmarks in standalone builds
We are trying to remove duplication of third-party code in
https://reviews.llvm.org/D112012, which will move the Google
Benchmark code outside of the `libcxx/` directory. That breaks
running the benchmarks in the Standalone build. Since we have
deprecated the Standalone build anyway, this patch just removes
support for the benchmark in Standalone mode until we remove that
mode entirely.

Differential Revision: https://reviews.llvm.org/D113503
2021-11-11 14:13:36 -05:00
Louis Dionne 3016ceb30d [libc++] Allow running the bootstrapping CI build on Darwin
Instead of hard-coding the target for our CI nodes, use the default
compiler triple. Also, allow building compiler-rt for the single
specified triple in case we're running on Darwin (otherwise, the
bootstrapping build complains).

Differential Revision: https://reviews.llvm.org/D113683
2021-11-11 14:12:34 -05:00
Nikolas Klauser b57c22ade8 [libc++] Implement P2186R2 (Remove Garbage Collection)
Reviewed By: Quuxplusone, #libc, ldionne

Differential Revision: https://reviews.llvm.org/D112869
2021-11-11 19:03:00 +01:00
Mark de Wever 4732dd3010 [libc++] Use addressof in list.
This addresses the usage of `operator&` in `<list>`.

(Note there are still more headers with the same issue.)

Reviewed By: #libc, Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D112654
2021-11-11 18:56:08 +01:00
Mark de Wever f7345de64f [libc++] Use addressof in forward_list.
This addresses the usage of `operator&` in `<forward_list>`.

(Note there are still more headers with the same issue.)

Reviewed By: #libc, Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D112660
2021-11-11 18:47:15 +01:00
Nikolas Klauser f0d5a60fc1 [libc++] Implement P1147R1 (Printing volatile T*)
Differential Revision: https://reviews.llvm.org/D113482
2021-11-11 11:10:29 -05:00
Louis Dionne 4d8db4a997 [libc++] Fix GDB pretty printer test on 32 bit targets
On 32 bit targets, size_t is unsigned int, not unsigned long, so
std::bitset's template argument gets printed with a `u` suffix,
not `ul`.
2021-11-11 11:09:36 -05:00
MarcoFalke faa019c0e3
[libc++] Fix segmentation fault in __do_put_integral
6 chars are not sufficient to represent all formats for 64 bit integers.

This was accidentally introduced in commit b889cbf366 (https://reviews.llvm.org/D112830).

This causes failures in downstream projects, for example:

* https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=40817
* https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=40841

Differential Revision: https://reviews.llvm.org/D113600
2021-11-10 21:26:05 +01:00
Sean Fertile e068c84762 [libc++][AIX] Alignment of bool on AIX is 1
Update test so that we check for a 1 byte alignment on AIX PPC32.

Differential Revision: https://reviews.llvm.org/D112087
2021-11-10 13:01:32 -05:00
David Tenty 2b416b4647 [libcxx][CI][AIX] Switch to LLVM_ENABLE_RUNTIMES
and to the new `runtimes` top level CMakeLists.txt since the old path is now deprecated. This requires a slight adjustment of the libcxxabi CMake, since there are required macro definitions we previously got via the `llvm/CMakeList.txt` path.

Reviewed By: ldionne, #libc, #libc_abi

Differential Revision: https://reviews.llvm.org/D113403
2021-11-09 16:04:10 -05:00
Mark de Wever 65fceaebc7 [libc++] Adds missing forward_list merge tests.
During the review of D112660 it turned out the tests for
`std::forward_list::merge` are incomplete.

Adds tests for the rvalue reference overloads. The tests are extended to
better test the Effects [forward.list.ops]/25 and Remarks
[forward.list.ops]/27 of the function:
- x is empty after the merge.
- Pointers and references to the moved elements of x now refer to those
  same elements but as members of *this.
- Iterators referring to the moved elements will continue to refer to
  their elements, but they now behave as iterators into *this, not into x.
- The algorithm is stable.

Reviewed By: Quuxplusone, #libc, ldionne

Differential Revision: https://reviews.llvm.org/D113364
2021-11-09 20:12:02 +01:00
Louis Dionne 181763d475 [libc++] Simplify selftest to avoid passing arguments to it
This makes the test pass on executors that don't support passing additional
arguments.

Differential Revision: https://reviews.llvm.org/D113483
2021-11-09 13:18:23 -05:00
Louis Dionne a4ba780510 [libc++] Enable -Wformat-nonliteral when building libc++
Using user-provided data as a format string is a well known source of
security vulnerabilities. For this reason, it is a good idea to compile
our code with -Wformat-nonliteral, which basically warns if a non-constant
string is used as a format specifier. This is the compiler’s best signal
that a format string call may be insecure.

I audited the code after adding the warning and made sure that the few
places where we used a non-literal string as a format string were not
potential security issues. I either disabled the warning locally for
those instances or fixed the warning by using a literal. The idea is
that after we add the warning to the build, any new use of a non-literal
string in a format string will trigger a diagnostic, and we can either
get rid of it or disable the warning locally, which is a way of
acknowledging that it has been audited.

I also looked into enabling it in the test suite, which would perhaps
allow finding additional instances of it in our headers, however that
is not possible at the moment because Clang doesn't support putting
__attribute__((__format__(...))) on variadic templates, which would
be needed.

rdar://84571685

Differential Revision: https://reviews.llvm.org/D112927
2021-11-09 13:17:45 -05:00
Mark de Wever 1e78d5d008 [libc++] Fix lifetime issues of temporaries.
The ASAN build failed due to using pointers to a temporary whose
lifetime had expired.

Updating the libc++ Docker image to Ubuntu Focal caused some breakage.
This was temporary disabled in D112737. This re-enables two of these
tests.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D113137
2021-11-09 19:01:22 +01:00
Mark de Wever a948a0a23c [libc++] Mark a failing test.
The tests fails in debug mode since it manipulates an iterator to a
`std::string` returned from the dylib. This is a known issue for the
debug iterators.

Updating the libc++ Docker image to Ubuntu Focal caused some breakage.
This was temporary disabled in D112737. This re-enables one of these
tests.

Reviewed By: ldionne, #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D113139
2021-11-09 19:00:09 +01:00
Mark de Wever 3ca520f19f [libc++][cmake] Improves benchmark build.
The CMake dependencies don't properly list the libc++ headers. When a
libc++ header is modified the affected benchmarks aren't rebuild. This
makes testing benchmarks tricky and may cause accidentally not using the
latest modifications during testing. This change causes CMake to
determine the proper dependencies.

This shouldn't affect the CI build.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D113419
2021-11-09 18:57:44 +01:00
Konstantin Varlamov 68072a7166 [libc++] P0433R2: test that deduction guides are properly SFINAEd away.
Deduction guides for containers should not participate in overload
resolution when called with certain incorrect types (e.g. when called
with a template argument in place of an `InputIterator` that doesn't
qualify as an input iterator). Similarly, class template argument
deduction should not select `unique_ptr` constructors that take a
a pointer.

The tests try out every possible incorrect parameter (but never more
than one incorrect parameter in the same invocation).

Also add deduction guides to the synopsis for associative and unordered
containers (this was accidentally omitted from [D112510](https://reviews.llvm.org/D112510)).

Differential Revision: https://reviews.llvm.org/D112904
2021-11-09 09:32:24 -08:00
Martin Storsjö b1c9d3d29a [libcxx] Add a dependency on unwind in cxx_static, if LIBCXXABI_USE_LLVM_UNWINDER is set
Even if building cxx_static in itself doesn't actually link in the
requested unwinder, add a synthetic dependency so that building
cxx_static makes sure that the unwinder that was requested to be used
also gets built.

This makes sure that tests (when run with just a plain "ninja check-cxx")
actually use the newly built unwinder, as intended.

Differential Revision: https://reviews.llvm.org/D113467
2021-11-09 17:44:48 +02:00
Arthur O'Dwyer 9a3cb73460 [libc++] [test] Eliminate the libcpp-no-if-constexpr feature flag.
At this point, every supported compiler that claims a -std=c++17 mode
should also support `if constexpr`. This was an issue for GCC 5
and GCC 6, but hasn't been an issue since GCC 7. (Our current
minimum supported GCC version, IIUC, is GCC 10 or 11.)

Differential Revision: https://reviews.llvm.org/D113348
2021-11-08 16:58:47 -05:00
Louis Dionne 1837a837b3 [libc++] Trigger a rebuild of the CI Docker images 2021-11-08 14:34:24 -05:00
David Tenty 28b3cac7cf [libc++][CI] Add AIX pipeline config
This changes adds the pipeline config for both 32-bit and 64-bit AIX targets. As well, we add a lit feature `LIBCXX-AIX-FIXME` which is used to mark the failing tests which remain to be investigated on AIX, so that the CI produces a clean build.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D111359
2021-11-08 10:30:27 -05:00
Konstantin Varlamov 12b55821a5 [libc++][NFC] Inline most of `__vector_base` into `vector`.
`__vector_base` exists for historical reasons and cannot be eliminated
entirely without breaking the ABI. Member variables are left
untouched -- this patch only does changes that clearly cannot affect the
ABI.

Differential Revision: https://reviews.llvm.org/D112976
2021-11-08 00:45:48 -08:00
Konstantin Varlamov d7ab283996 Revert "[libc++] Always define a key function for std::bad_function_call in the dylib"
This reverts commit bc74231756. It was
committed accidentally.
2021-11-08 00:44:47 -08:00
Louis Dionne bc74231756 [libc++] Always define a key function for std::bad_function_call in the dylib
However, whether applications rely on the std::bad_function_call vtable
being in the dylib is still controlled by the ABI macro, since changing
that would be an ABI break.

Differential Revision: https://reviews.llvm.org/D92397
2021-11-08 00:31:00 -08:00
Mark de Wever 69603ae90f [libc++][doc] Don't mention Prague twice. 2021-11-07 16:21:05 +01:00
Nikolas Klauser 9a140a1586 [libc++] Make test_allocator constexpr-friendly for constexpr string/vector
Make test_allocator etc. constexpr-friendly so they can be used to test constexpr string and possibly constexpr vector

Reviewed By: Quuxplusone, #libc, ldionne

Differential Revision: https://reviews.llvm.org/D110994
2021-11-07 16:15:28 +01:00
Arthur O'Dwyer c92a253cf0 [libc++] Fix hang in counting_semaphore::try_acquire
Before this patch, `try_acquire` blocks instead of returning false.
This is because `__libcpp_thread_poll_with_backoff` interprets zero
as meaning infinite, causing `try_acquire` to wait indefinitely.

Thanks to Pablo Busse (pabusse) for the patch!

Differential Revision: https://reviews.llvm.org/D98334
2021-11-05 15:57:46 -04:00
Martin Storsjö 2d8ec3c61d [libcxx] [test] Narrow down XFAILs regarding a MSVC mode specific bug to "windows-dll && msvc"
These tests don't fail when only windows-dll is set in mingw mode, as the
bug is specific to MSVC mode.

Differential Revision: https://reviews.llvm.org/D112348
2021-11-05 21:43:29 +02:00
Quinn Pham c71fbdd87b [NFC] Inclusive language: Remove instances of master in URLs
[NFC] This patch fixes URLs containing "master". Old URLs were either broken or
redirecting to the new URL.

Reviewed By: #libc, ldionne, mehdi_amini

Differential Revision: https://reviews.llvm.org/D113186
2021-11-05 08:48:41 -05:00
Daniel McIntosh 41481b7db5 [libcxx][NFC] tidy up money_get::__do_get's sign parsing
Same logic, but much easier to read this way

Reviewed By: ldionne, #libc, Mordante

Differential Revision: https://reviews.llvm.org/D112958
2021-11-04 17:55:28 -04:00
Mark de Wever 5de4864f74 [libc++] Improve no wide characters configuration.
When wide characters are supported libc++ manually translates a
`narrow non-breaking space` and a `non-breaking space` to a space.
This behaviour wasn't available when wide characters were disabled.
This enables an emulation for that configuration.

Updating the libc++ Docker image to Ubuntu Focal caused some breakage.
This was temporary disabled in D112737. This re-enables four of these
tests.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D113133
2021-11-04 19:35:06 +01:00
Arthur O'Dwyer d0eaf75320 [libc++] Remove non-atomic "platform" semaphore implementations.
These can't be made constexpr-constructible (constinit'able),
so they aren't C++20-conforming. Also, the platform versions are
going to be bigger than the atomic/futex version, so we'd have
the awkward situation that `semaphore<42>` could be bigger than
`semaphore<43>`, and that's just silly.

Differential Revision: https://reviews.llvm.org/D110110
2021-11-04 14:33:34 -04:00
Martin Storsjö 341cc1b411 [libcxx] Remove nonstandard _FilesystemClock::{to,from}_time_t
These are not standard methods, neither libstdc++ nor MSVC STL provide
them.

In practice, one of them was untested and the other one was only used in
one single test.

Differential Revision: https://reviews.llvm.org/D113027
2021-11-04 10:24:47 +02:00
Louis Dionne 9904bcf2a4 [libc++] Fix GDB pretty printer tests for older Clangs and GCC
This was missed by https://llvm.org/D111477, which broke the CI.

Differential Revision: https://reviews.llvm.org/D113112
2021-11-03 13:02:04 -04:00
Konstantin Boyarinov d7ac595fc5 [libcxx][test][NFC] More tests for containers comparisons
Add more missing tests for comparisons to improve code coverage (follow-up for D111738)

Reviewed By: ldionne, rarutyun, #libc

Differential Revision: https://reviews.llvm.org/D112424
2021-11-03 16:15:10 +03:00
David Spickett 52615df0f2 [libcxx][utils] Note read only mount and ptrace permission in container script
Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D110938
2021-11-03 10:09:15 +00:00
Martin Storsjö dd5ce506f7 [libcxx] [test] Remove a LIBCXX-WINDOWS-FIXME, don't test an unsupported strftime() pattern
Testing the unsupported pattern can trigger the invalid parameter handler,
which depending on CRT configuration can abort the process.

Differential Revision: https://reviews.llvm.org/D112352
2021-11-02 21:53:15 +02:00
David Blaikie 8bf1244538 DebugInfo: workaround for context-sensitive use of non-type-template-parameter integer suffixes
There's a nuanced check about when to use suffixes on these integer
non-type-template-parameters, but when rebuilding names for
-gsimple-template-names there isn't enough data in the DWARF to
determine when to use suffixes or not. So turn on suffixes always to
make it easy to match up names in llvm-dwarfdump --verify.

I /think/ if we correctly modelled auto non-type-template parameters
maybe we could put suffixes only on those. But there's also some logic
in Clang that puts the suffixes on overloaded functions - at least
that's what the parameter says (see D77598 and printTemplateArguments
"TemplOverloaded" parameter) - but I think maybe it's for anything that
/can/ be overloaded, not necessarily only the things that are overloaded
(the argument value is hardcoded at the various callsites, doesn't seem
to depend on overload resolution/searching for overloaded functions). So
maybe with "auto" modeled more accurately, and differentiating between
function templates (always using type suffixes there) and class/variable
templates (only using the suffix for "auto" types) we could correctly
use integer type suffixes only in the minimal set of cases.

But that seems all too much fuss, so let's just put integer type
suffixes everywhere always in the debug info of integer non-type
template parameters in template names.

(more context:
* https://reviews.llvm.org/D77598#inline-1057607
* https://groups.google.com/g/llvm-dev/c/ekLMllbLIZg/m/-dhJ0hO1AAAJ )

Differential Revision: https://reviews.llvm.org/D111477
2021-11-01 17:08:26 -07:00
Louis Dionne d5b40a30b5 [libc++] Add missing annotations for TEST_HAS_NO_WIDE_CHARACTERS
Those tests would pass when run on a C Standard Library that actually
provides wide characters, but fail when run on top of one that doesn't.
It's really difficult to test this 100% perfectly in the CI without
introducing an actual platform that doesn't provide these declarations.

Differential Revision: https://reviews.llvm.org/D112937
2021-11-01 14:10:32 -04:00
Louis Dionne b889cbf366 [libc++] Refactor num_put::do_put to reduce duplication
I was going to make a change in that area of the code and I noticed that
we basically duplicated the same code 5 times to handle integral types
and floating point types. This commit simply pulls the duplication into
a function.

Differential Revision: https://reviews.llvm.org/D112830
2021-11-01 10:05:10 -04:00
Nikolas Klauser dd189fb475 [libc++] reformatted test_allocator.h
reformatted test_allocator.h by request of @ldionne for D110994

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D112219
2021-10-30 12:54:23 +02:00
Mark de Wever e958242d47 [libc++][format] Mark LWG-issues as complete.
Most of the code has been implemented using the eel.is draft. It seems
some issues were inplemented but not marked as completed yet.

Note the wording of LWG-3372 has been implemented, but has been changed
in the current draft due to P2216, see D110494.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D112363
2021-10-30 12:52:30 +02:00
Mark de Wever 5468dfb973 [libc++][format] Use preferred_name attribute.
This was suggested by @vitaut in D110494.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D112362
2021-10-30 12:51:56 +02:00
Mark de Wever 4cb3d7d7b4 [libc++] Update clang-format to C++20.
We now use clang-format-13 which has the option SpacesInAngles. This
allows us to switch the default language version to C++20, which should
avoid breaking code when formatting due to the adding of whitespace.
For example `u8"foo"` no longer is formatted as `u8 "foo"`.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D112728
2021-10-30 12:50:57 +02:00
Mark de Wever 7ee5e7e97c [libc++] Remove Clang-11 support.
Since we no longer officially support Clang 11 remove the work-arounds
for this version.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D112727
2021-10-30 12:50:22 +02:00
Kazu Hirata 3cfc1757c5 Ensure newlines at the end of files (NFC) 2021-10-29 20:26:09 -07:00
Joe Loser 40a6be4346
[libc++] Ensure valid view for view_interface template parameter
Some types that inherit from `view_interface` do not meet the
preconditions. This came up during discussion
in https://reviews.llvm.org/D112631. Currently, the behavior is IFNDR,
but the preconditions can be easily checked, so let's do so.

In particular, we know each public member function calls the
`__derived()` private function, so we can do the check there. We
intentionally do it as a `static_assert` instead of a `requires` clause
to avoid hard erroring in some cases, such as with incomplete types. An
example hard error is:

```
llvm-project/build/include/c++/v1/__ranges/view_interface.h:48:14: note: because 'sizeof(_Tp)' would be invalid: invalid application of 'sizeof' to an incomplete type 'MoveOnlyForwardRange'
  requires { sizeof(_Tp); } &&
             ^
llvm-project/build/include/c++/v1/__ranges/view_interface.h:73:26: error: no matching member function for call to '__derived'
    return ranges::begin(__derived()) == ranges::end(__derived());
                         ^~~~~~~~~
llvm-project/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp:187:31: note: in instantiation of function template specialization 'std::ranges::view_interface<MoveOnlyForwardRange>::empty<Mov
eOnlyForwardRange>' requested here
  assert(!std::move(moveOnly).empty());
```

Reviewed By: Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D112665
2021-10-29 19:04:54 -04:00
Arthur O'Dwyer 0412c007e3 [libc++] Implement LWG3369, tweak CTAD for std::span.
The original bug doesn't reproduce on Clang, allegedly because of
https://bugs.llvm.org/show_bug.cgi?id=44484
We already test STL's exact test case, in "span.cons/deduct.pass.cpp",
which I'm touching just for the heck of it.

Differential Revision: https://reviews.llvm.org/D111838
2021-10-29 14:15:41 -06:00
Arthur O'Dwyer d6b826ebb2 [libc++] [doc] Mark LWG3398 as complete.
This was done in D108054.
2021-10-29 14:15:41 -06:00
Joe Loser 2d83392a88
[libc++] Mark LWG3211 as complete: default constructor of tuple<> should be trivial
`libc++` has had the guarantee of the default constructor of `tuple<>` being
trivial since 405570dc7a. Now, the
standard mandates it as of LWG3211. So, move the file out of
`libcxx/test/libcxx` and into `libcxx/test/std` since it's no longer
`libc++`-specific. Rename it to be `.compile.pass.cpp` instead of
`.pass.cpp` while we're at it.

Reviewed By: ldionne, Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D112743
2021-10-29 12:08:51 -04:00
Martin Storsjö a21a6ed8c2 [libcxx] [test] Change LIBCXX-WINDOWS-FIXME into XFAIL: msvc for cases that succeed in mingw configurations
Add comments about the reasons for the XFAILs where there was none before.

Differential Revision: https://reviews.llvm.org/D112211
2021-10-29 09:32:37 +03:00
Louis Dionne a55632a069 [libc++] Temporarily mark tests as UNSUPPORTED to get the CI green
After recent changes to the Docker image, all hell broke loose and the
CI started failing. This patch marks a few tests as unsupported until
we can figure out what the issues are and fix them.

In the future, it would be ideal if the nodes could pick up the Dockerfile
present in the revision being tested, which would allow us to test changes
to the Dockerfile in the CI, like we do for all other code changes.

Differential Revision: https://reviews.llvm.org/D112737
2021-10-28 16:30:42 -04:00
Xiang Gao de493a26b9 [libc++] Fix buggy numerics of tanh(complex) at inf
Because:
    lim[x->inf, tanh(x+iy)] = 1
    lim[x->-inf, tanh(x+iy)] = -1

See also https://github.com/NVIDIA/libcudacxx/pull/210

Differential Revision: https://reviews.llvm.org/D112252
2021-10-28 16:10:56 -04:00
Xiang Gao f21c247300 [libc++] Fix numeric of exp(complex) at inf
This fixes the bug that exp({501, 0}) returns {inf, nan} instead
of {inf, 0}.

Differential Revision: https://reviews.llvm.org/D112277
2021-10-28 16:10:55 -04:00
Joe Loser 93df7b9f75
[libc++][ABI Break] Make is_error_condition_enum_v and is_error_code_enum_v bool, not size_t
`is_error_condition_enum_v` and `is_error_code_enum_v` are currently of
type `size_t`, but the standard mandates they are of type `bool`.

This is an ABI break technically since the size of these variable
templates has changed. Document it as such in the release notes.

Fixes https://bugs.llvm.org/show_bug.cgi?id=50755

Reviewed By: ldionne, Quuxplusone, #libc, var-const

Differential Revision: https://reviews.llvm.org/D112553
2021-10-28 15:38:17 -04:00
Konstantin Varlamov f9f97cae82 [libc++] P0433R2: add the remaining deduction guides.
Add deduction guides to `valarray` and `scoped_allocator_adaptor`. This largely
finishes implementation of the paper:

* deduction guides for other classes mentioned in the paper were
  implemented previously (see the list below);
* deduction guides for several classes contained in the proposal
  (`reference_wrapper`, `lock_guard`, `scoped_lock`, `unique_lock`,
  `shared_lock`) were removed by [LWG2981](https://wg21.link/LWG2981).

Also add deduction guides to the synopsis for the few classes (e.g. `pair`)
where they were missing.

The only part of the paper that isn't fully implemented after this patch is
making sure certain deduction guides don't participate in overload resolution
when given incorrect template parameters.

List of significant commits implementing the other parts of P0433 (omitting some
minor fixes):

* [pair](af65856eec)
* [basic_string](6d9f750dec)
* [array](0ca8c0895c)
* [deque](dbb6f8a817)
* [forward_list](e076700b77)
* [list](4a227e582b)
* [vector](df8f754792)
* [queue/stack/priority_queue](5b8b8b5dce)
* [basic_regex](edd5e29cfe)
* [optional](f35b4bc395)
* [map/multimap](edfe8525de)
* [set/multiset](e20865c387)
* [unordered_set/unordered_multiset](296a80102a)
* [unordered_map/unordered_multimap](dfcd4384cb)
* [function](e1eabcdfad)
* [tuple](1308011e1b)
* [shared_ptr/weak_ptr](83564056d4)

Additional notes:
* It was revision 2 of the paper that was voted into the Standard.
  P0433R3 is a separate paper that is not part of the Standard.
* The paper also mandates removing several `make_*_searcher` functions
  (e.g. `make_boyer_moore_searcher`) which are currently not implemented
  (except in `experimental/`).
* The `__cpp_lib_deduction_guides` feature test macro from the paper was
  accidentally omitted from the Standard.

Differential Revision: https://reviews.llvm.org/D112510
2021-10-28 11:09:51 -07:00
Louis Dionne 4ee17b71f6 [libc++] Update the CI Docker image to Focal
Differential Revision: https://reviews.llvm.org/D112726
2021-10-28 13:21:09 -04:00
Mark de Wever 04a9a25d7c [libc++][ci] Update to Clang 13.
Per our support plan we should now support Clang 12 and 13. Adjust the
documentation and the CI runners. The change indirectly moves the main
CI runners to use the Clang 14 nightly builds.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D112360
2021-10-28 17:37:32 +02:00
Petr Hosek 22acda48ff [CMake] Cache the compiler-rt library search results
There's a lot of duplicated calls to find various compiler-rt libraries
from build of runtime libraries like libunwind, libc++, libc++abi and
compiler-rt. The compiler-rt helper module already implemented caching
for results avoid repeated Clang invocations.

This change moves the compiler-rt implementation into a shared location
and reuses it from other runtimes to reduce duplication and speed up
the build.

Differential Revision: https://reviews.llvm.org/D88458
2021-10-27 17:53:03 -07:00
Louis Dionne 2999b7307f [libc++] Make __decay_copy constexpr
This is going to be necessary to implement some range adaptors.
As a fly-by fix, rename _LIBCPP_INLINE_VISIBILITY to _LIBCPP_HIDE_FROM_ABI
and remove a redundant inline keyword.

Differential Revision: https://reviews.llvm.org/D112650
2021-10-27 17:32:08 -04:00
Joe Loser c3cd5f5b4f
[libc++][test] Fix invalid test for views::view_interface
The type `MoveOnlyForwardRange` violates the precondition stated in
`view.interface.general`. Specifically, the type passed to
`view_interface` shall model the `view` concept. In turn, this requires the
type to satisfy `movable` concept (and others), but this type
`MoveOnlyForwardRange` does not satisfy the `movable` concept.

Add a move assignment operator so that `MoveOnlyForwardRange` satisfies the
`movable` concept. While we're here, ensure the neighboring types that inherit
from `view_interface` also satisfy the `view` concept to avoid similar issues.

Fixes https://bugs.llvm.org/show_bug.cgi?id=50720

Reviewed By: Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D112631
2021-10-27 17:12:42 -04:00
Joe Loser 7ad00511e4
[libc++][NFC] Mark LWG2731 as complete
Mark LWG2731 as complete. The type alias `mutex_type` is only provided if
`scoped_lock` is given one mutex type and it has been implemented that
way since the beginning of Clang 5 it seems. There already are tests for
verifying existence (and lack thereof) for `mutex_type` type alias
depending on the number of mutex types, so there is nothing to
do for this LWG issue.

Reviewed By: Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D112462
2021-10-26 13:46:00 -04:00
Louis Dionne b2d25ef2d1 [libc++] Implement shared_ptr methods inline in the class
This patch refactors the shared_ptr methods from being defined out-of-line
to being defined inline in the class, like what we do for all new code in
the library. The benefits of doing that are that code is not as scattered
around and is hence easier to understand, and it avoids a ton of duplication
due to SFINAE checks. Defining the method where it is declared also removes
the possibility for mismatched attributes.

As a fly-by change, this also:

- Adds a few _LIBCPP_HIDE_FROM_ABI attributes
- Uses __enable_if_t instead of enable_if as a function argument, to match
  the style that we use everywhere else.

Differential Revision: https://reviews.llvm.org/D112478
2021-10-26 13:11:10 -04:00
Louis Dionne 6d52773547 [libc++] Include nasty_macros.h when running tests with from-scratch configs
This was forgotten when setting up the from-scratch configs.

Differential Revision: https://reviews.llvm.org/D112460
2021-10-26 10:31:03 -04:00
Joe Loser d081d75dc8
[libc++][NFC] Remove unimplemented parts of chrono synopsis
Several parts in the `chrono` synopsis for C++20 are not yet
implemented. The current recommendation is that things are added to the
synopsis when implemented -- not beforehand. As such, remove the
not-yet-implemented parts to avoid confusion.

Reviewed By: ldionne, Quuxplusone, #libc

Differential Revision: https://reviews.llvm.org/D111922
2021-10-25 11:16:40 -04:00
Konstantin Varlamov 065ac30026 [libc++] LWG3001: add `remove_extent_t` to `weak_ptr::element_type`.
Also fix a few places in the `shared_ptr` implementation where
`element_type` was passed to the `__is_compatible` helper. This could
result in `remove_extent` being applied twice to the pointer's template
type (first by the definition of `element_type` and then by the helper),
potentially leading to somewhat less readable error messages for some
incorrect code.

Differential Revision: https://reviews.llvm.org/D112092
2021-10-25 11:15:54 -04:00
Louis Dionne 5c46986cc8 [libc++] Include revision numbers in the paper status lists
Several of our C++20 and C++2b papers were missing the actual revision
number that was voted in to the Standard. The revision number is quite
important because in a few cases, a paper has a revision *after* the
one that is voted into the Standard, which isn't voted into the Standard.
Hence, if we simply followed the wg21.link blindly and implemented that,
we'd end up implementing the latest revision of the paper, which might
not have been voted.

As a fly-by fix, I found out that P1664 had been withdrawn from the
straw polls and had never been voted into the Standard. This commit
removes that entry from our list.

Differential Revision: https://reviews.llvm.org/D112339
2021-10-25 10:55:35 -04:00
Kazu Hirata d8e4170b0a Ensure newlines at the end of files (NFC) 2021-10-23 08:45:29 -07:00
Louis Dionne a41837d1da [libc++][NFC] Remove duplicate Python imports 2021-10-22 16:16:28 -04:00
Louis Dionne 7ea5409e42 [libc++] Fix tests after aee4925507 2021-10-22 12:50:29 -04:00
Mark de Wever 7593f68a05 [libc++][nfc] Remove double spaces.
Based on the comment of @Quuxplusone in D111961. It seems no tests are
affected, but give it a run on the CI to be sure.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D112231
2021-10-22 17:26:13 +02:00
Mark de Wever 09dc8ab74c [libc++][doc] Fixes FeatureTestMacroTable.html.
`utils/generate_feature_test_macro_components.py` uses the wrong
indentation. `:name: feature-status-table :widths: auto` is rendered as
text instead of being used by Sphinx to render the table properly.

This fixes the identation in the souce and updates the generated output.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D112251
2021-10-22 17:25:43 +02:00
Konstantin Boyarinov c87a4a46b2 [libc++][test][NFC] Add tests for std::vector comparisons
Add missing tests for std::vector operator==, !=, <, <=, >, >=

Reviewed By: ldionne, rarutyun, Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D111738
2021-10-22 18:11:04 +03:00
Tom Stellard c16655f138 [docs] Remove Makefile.sphinx files
Does anyone still use these?  I want to make some changes to the sphinx
html generation and I don't want to have to implement the changes in
two places.

Reviewed By: sylvestre.ledru, #libc, ldionne

Differential Revision: https://reviews.llvm.org/D112030
2021-10-21 16:04:52 -07:00
Martin Storsjö f5ee1acc62 [libcxx] [test] Convert an XFAIL: LIBCXX-WINDOWS-FIXME into XFAIL: msvc with explanation
This test doesn't fail in mingw mode (which uses the same Itanium
name mangling and ABI as other platforms).

Differential Revision: https://reviews.llvm.org/D112210
2021-10-22 01:02:25 +03:00
Martin Storsjö 6836629f88 [libcxx] [test] Add a specific XFAIL for a MinGW env failure that is fixed in Clang 14
This issue only occurs when linked statically in MinGW configurations,
and has been fixed for Clang 14 by https://reviews.llvm.org/D109651.

Differential Revision: https://reviews.llvm.org/D112214
2021-10-21 23:29:54 +03:00
Martin Storsjö 3087a84889 [libcxx] [test] Add an XFAIL for the timespec test for MinGW targets
MinGW headers/libs lack timespec_get.

Differential Revision: https://reviews.llvm.org/D112213
2021-10-21 23:29:43 +03:00
David Blaikie aee4925507 Recommit: Compress formatting of array type names (int [4] -> int[4])
Based on post-commit review discussion on
2bd8493847 with Richard Smith.

Other uses of forcing HasEmptyPlaceHolder to false seem OK to me -
they're all around pointer/reference types where the pointer/reference
token will appear at the rightmost side of the left side of the type
name, so they make nested types (eg: the "int" in "int *") behave as
though there is a non-empty placeholder (because the "*" is essentially
the placeholder as far as the "int" is concerned).

This was originally committed in 277623f4d5

Reverted in f9ad1d1c77 due to breakages
outside of clang - lldb seems to have some strange/strong dependence on
"char [N]" versus "char[N]" when printing strings (not due to that name
appearing in DWARF, but probably due to using clang to stringify type
names) that'll need to be addressed, plus a few other odds and ends in
other subprojects (clang-tools-extra, compiler-rt, etc).
2021-10-21 11:34:43 -07:00
Petr Hosek ba4920e98e Revert "[CMake] Cache the compiler-rt library search results"
This reverts commit 0eed292fba, there
are compiler-rt build failures that appear to have been introduced
by this change.
2021-10-21 10:32:01 -07:00
Mark de Wever 56df1d80e2 [libc++] Use addressof in vector.
This addresses the usage of `operator&` in `<vector>`.

I now added tests for the current offending cases. I wonder whether it
would be better to add one addressof test per directory and test all
possible violations. Also to guard against possible future errors?

(Note there are still more headers with the same issue.)

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D111961
2021-10-21 17:28:17 +02:00
Louis Dionne 72117f2ffe [runtimes] Properly handle the sysroot/triple/gcc-toolchain
In 395271a, I simplified how we handled the target triple for the
runtimes. However, in doing so, we stopped considering the default
in CMAKE_CXX_COMPILER_TARGET, so we'd use the LLVM_DEFAULT_TARGET_TRIPLE
(which is the host triple) even if CMAKE_CXX_COMPILER_TARGET was specified.
This commit fixes that problem and also refactors the code so that it's
easy to see what the default value is.

The fact that nobody seems to have been broken by this makes me think
that perhaps nobody is using CMAKE_CXX_COMPILER_TARGET to specify the
triple -- but it should still work.

Differential Revision: https://reviews.llvm.org/D111672
2021-10-21 10:06:11 -04:00
Mikhail Maltsev 05a2d17668 [libcxx] Throw correct exception from std::vector::reserve
According to the standard [vector.capacity]/5, std::vector<T>::reserve
shall throw an exception of type std::length_error when the requested
capacity exceeds max_size().

This behavior is not implemented correctly: the function 'reserve'
simply propagates the exception from allocator<T>::allocate. Before
D110846 that exception used to be of type std::length_error (which is
correct for vector<T>::reserve, but incorrect for
allocator<T>::allocate).

This patch fixes the issue and adds regression tests.

Reviewed By: Quuxplusone, ldionne, #libc

Differential Revision: https://reviews.llvm.org/D112068
2021-10-21 10:40:48 +01:00
Mikhail Maltsev 49be23a1eb [libcxx] Support allocators with explicit c-tors in vector<bool>
std::vector<bool> rebinds the supplied allocator to construct objects
of type '__storage_type' rather than 'bool'. Allocators are allowed to
use explicit conversion constructors, so care must be taken when
performing conversions.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D112150
2021-10-21 10:38:56 +01:00
Louis Dionne 3cea2505fd [runtimes] Rename CI job from "Runtimes build" to "Bootstrapping build" 2021-10-20 17:43:55 -04:00
Louis Dionne 048688fd80 [libc++] Fix incorrect main() signatures in the tests
Those creep up from time to time. We need to use `int main(int, char**)`
because in freestanding mode, `main` doesn't get special treatment and
special mangling, so we setup a symbol alias from the mangled version of
`main(int, char**)` to `extern "C" main`. That only works if all the tests
are consistent about how they define their main function.
2021-10-20 16:26:34 -04:00
Muiez Ahmed 6b82adbb49 Raise compile error when using unimplemented functions
The path functions in this patch are unimplemented (as per the TODO comment from upstream). To avoid running into a linker error (missing symbol), this patch raises a compile error by commenting out the functions, which is more user friendly.

Differential Revision: https://reviews.llvm.org/D111892
2021-10-20 13:55:50 -04:00
Louis Dionne cbe3b6b21f [libc++] Move LIBCXX-DEBUG-FIXME to params.py
This temporary FIXME really belongs to the testing config, not to the
specific CMake cache that enables that configuration.

Differential Revision: https://reviews.llvm.org/D112031
2021-10-20 09:23:03 -04:00
Joe Loser 622c40722e
[libc++] Make __weekday_from_days private in weekday
`weekday` has a static member function `__weekday_from_days` which is
not part of the mandated public interface of `weeekday` according to the
standard. Since it is only used internally in the constructors of
`weekday`, let's make it private.

Reviewed By: ldionne, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D112072
2021-10-19 14:21:33 -04:00
Joe Loser 494dad6b72
[libc++][NFC] Mark LWG3573 as complete
Mark LWG3573 as complete. It involves a change in wording around when
`basic_string_view`'s constructor for iterator/sentinel can throw. The
current implementation is not marked conditionally `noexcept`, so there
is nothing to do here. Add a test that binds this behavior to verify the
constructor is not marked `noexcept(true)` when `end - begin` throws.

Reviewed By: ldionne, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D111925
2021-10-19 14:18:49 -04:00
Louis Dionne a039746e1c [runtimes] Trigger CI on changes to libunwind 2021-10-19 13:16:42 -04:00
Konstantin Varlamov b84da5ba6e [libc++] [test] Add tests for converting array types in shared_ptr.
The only possible kind of a conversion in initialization of a shared
pointer to an array is a qualification conversion (i.e., adding
cv-qualifiers). This patch adds tests for converting from `A[]` to
`const A[]` to the following functions:

```
template<class Y> explicit shared_ptr(Y* p);

template<class Y> shared_ptr(const shared_ptr<Y>& r);
template<class Y> shared_ptr(shared_ptr<Y>&& r);

template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r);
template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);

template<class Y> void reset(Y* p);
template<class Y, class D> void reset(Y* p, D d);
template<class Y, class D, class A> void reset(Y* p, D d, A a);
```

Similar tests for converting functions that involve a `weak_ptr` should
be added once LWG issue [3001](https://cplusplus.github.io/LWG/issue3001)
is implemented.

Differential Revision: https://reviews.llvm.org/D112048
2021-10-19 13:03:51 -04:00
Louis Dionne 6fd55bba61 [libunwind] Add a from-scratch config for running libunwind tests
Running tests for libunwind is a lot simpler than running tests for
libc++, so a simple Lit config file is sufficient. The benefit is that
we disentangle the libunwind test configuration from the libc++ and
libc++abi test configuration. The setup was too complicated, which led
to some bugs (notably we were running against the system libunwind on
Apple platforms).

Differential Revision: https://reviews.llvm.org/D111664
2021-10-19 12:03:58 -04:00
Joe Loser ca889733a2
[libc++][docs] Mark LWG3420 complete
Mark LWG3420 as complete. Currently, the `cpp17_iterator` concept
checks that the type looks like an iterator first before checking if it
is copyable.

Reviewed By: ldionne, Quuxplusone, #libc

Differential Revision: https://reviews.llvm.org/D111598
2021-10-19 09:52:35 -04:00
Petr Hosek 0eed292fba [CMake] Cache the compiler-rt library search results
There's a lot of duplicated calls to find various compiler-rt libraries
from build of runtime libraries like libunwind, libc++, libc++abi and
compiler-rt. The compiler-rt helper module already implemented caching
for results avoid repeated Clang invocations.

This change moves the compiler-rt implementation into a shared location
and reuses it from other runtimes to reduce duplication and speed up
the build.

Differential Revision: https://reviews.llvm.org/D88458
2021-10-18 14:44:07 -07:00
Mikhail Maltsev be10b1f1cc [libcxx] Make allocator<T>:allocate throw bad_array_new_length
Currently the member functions std::allocator<T>::allocate,
std::experimental::pmr::polymorphic_allocator::allocate and
std::resource_adaptor<T>::do_allocate throw an exception of type
std::length_error when the requested size exceeds the maximum size.

According to the C++ standard ([allocator.members]/4,
[mem.poly.allocator.mem]/1), std::allocator<T>::allocate and
std::pmr::polymorphic_allocator::allocate must throw a
std::bad_array_new_length exception in this case.

The patch fixes the issue with std::allocator<T>::allocate and changes
the type the exception thrown by
std::experimental::pmr::resource_adaptor<T>::do_allocate to
std::bad_array_new_length as well for consistency.

The patch resolves LWG 3237, LWG 3038 and LWG 3190.

Reviewed By: ldionne, #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D110846
2021-10-18 19:12:42 +01:00
Louis Dionne d0d9be337e [libc++][NFC] Reorganize release notes
Several entries were in the wrong place, such as API changes appearing
under "Build System Changes". This commit shuffles stuff so it sits under
the right section.
2021-10-18 13:59:31 -04:00
Louis Dionne 79175f336c [runtimes] Use the new "runtimes" build by default and deprecate other builds
This commit makes the new "runtimes" build (with <monorepo>/runtimes as
the root of the CMake invocation) the default way of building libc++.
The other supported way of building libc++ is the "bootstrapping" build,
where `<monorepo>/llvm` is used as the root of the CMake invocation.

All other ways of building libc++ are deprecated effective immediately.
There should be no use-case for building libc++ that isn't supported by
one of these two builds, and the two new builds work on all environments
and are lightweight. They will also make it possible to greatly simplify
the build infrastructure of the runtimes, which is currently way too
convoluted.

Differential Revision: https://reviews.llvm.org/D111356
2021-10-18 13:50:26 -04:00
Louis Dionne 7e5dbcdd59 [libc++][NFC] Fix typo in test 2021-10-18 11:21:30 -04:00
Louis Dionne 616a3cc01e [libc++] Add the std::views::reverse range adaptor
Differential Revision: https://reviews.llvm.org/D110426
2021-10-18 10:38:31 -04:00
Mark de Wever 3956a1f8b6 [libc++][doc] Adds more issue status labels.
A followup to D111458 adding more labels to LWG-issues. This should add
the labels for the not completed chrono, format, ranges, and spaceship
issues.

Some minor formatting cleanups along the way.

Reviewed By: #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D111935
2021-10-16 17:40:26 +02:00
Konstantin Varlamov a59c1a2138 [libc++] LWG3266: delete the to_chars(bool) overload.
This PR only updates the synopsis in `<charconv>` -- the current
implementation already [deletes](e9e6266c70/libcxx/include/charconv (L108))
the overload and has a [test](https://github.com/llvm/llvm-project/blob/main/libcxx/test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp)
for it (and this has been the case from the first [commit](https://reviews.llvm.org/D41458)
where `<charconv>` was added).

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D111845
2021-10-15 17:52:58 +02:00
Mark de Wever cef9978027 [libc++][doc] Use issue labels.
During the review of D111166 I had a private discussion with @ldionne to
avoid the duplication of the C++2b issues in the Ranges and Format
status pages. The main reason for duplicating them is to make it easier to
find them. The title of the paper may not always make it clear to which
project the paper belongs.

This commit removes all LWG-issues from the Ranges and Format status page
and adds labels for these issue in the C++20/C++23 issues list.

A quick scan revealed there are some issues that are missing a label since
they weren't on the ranges issue list. These can be labelled in a separate
commit. In that commit I'll also look for issues for the spaceship operator
and chrono.

Reviewed By: Quuxplusone, ldionne, #libc

Differential Revision: https://reviews.llvm.org/D111458
2021-10-15 17:30:33 +02:00
Mikhail Dvorskiy 6069a6a504 [pstl] Initial implementation of OpenMP backend, on behalf of Christopher Nelson nadiasvertex@gmail.com
Phabricator Review:
https://reviews.llvm.org/D99836

A couple of parallel patterns still remains serial - "Parallel partial sort", and "Parallel transform scan" - there are //TODOs in the code.
2021-10-15 15:36:07 +03:00
Louis Dionne 25cbf72162 [libc++] Use apple-install-libcxx.sh in the Apple/system CI job
That script is what we (need to) use to build libc++ for the system
configuration, so that's what we should test against. At some point
we may be able to fold all of that logic into the CMake build, and
when that happens the CI can go back to running CMake directly.

As a fly-by fix, stop mentioning x86_64 in the names of the Apple
jobs since they are not truly tied to any architecture.

Differential Revision: https://reviews.llvm.org/D111865
2021-10-15 06:08:25 -04:00
David Tenty 228b3b729d [libc++][AIX] Add scripts and config for building with the libcxx CI infrastructure
This initial change adds the AIX configuration to run-buildbot, an AIX
CMake cache file, and appropriate compiler and linker flags for testing
AIX to the lit "from scratch" configuration files. Either of the 32-bit or 64-bit configurations
can be built by setting `OBJECT_MODE` in the build environment (as is
typical for AIX).

Reviewed By: ldionne, #libc, #libc_abi

Differential Revision: https://reviews.llvm.org/D111244
2021-10-14 14:31:10 -04:00
Joe Loser 1fa27f2a10
[libc++] LWG3480: make (recursive_)directory_iterator C++20 ranges
Implement LWG3480 which enables `directory_iterator` and
`recursive_directory_iterator` to be both a `borrowed_range` and a
`view`.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D111644
2021-10-14 12:02:18 -04:00
Mark de Wever 25a3463c44 [libc++][NFC] Fixes placement of the return type. 2021-10-14 17:40:45 +02:00
Martin Storsjö a03e17d4d9 [libcxx] [test] Generalize the conditions for testing bitcasts between long double, double and int128
MSVC targets also have a 64 bit long double, as do MinGW targets on ARM.
This hasn't been noticed in CI because the MSVC configurations there run
with _LIBCPP_HAS_NO_INT128 defined.

This avoids assuming that either __int128_t or double is equal in size to
long double. i386 MinGW targets have sizeof(long double) == 10, which
doesn't match any of the tested types.

Differential Revision: https://reviews.llvm.org/D111671
2021-10-13 22:55:01 +03:00
Louis Dionne d1e0f02e0b [libc++abi][ci] Add a from-scratch config for libc++abi on Apple/system
I came across an issue where since we build the library for Apple with
the install name directory being /usr/lib, which means that if we don't
run the tests with DYLD_LIBRARY_PATH, we'll end up loading the
system-provided libc++abi when running the tests. That wreaks havoc.

Instead of fixing it in the legacy config file, this commit introduces
an Apple libc++abi config file that does the right thing.

Differential Revision: https://reviews.llvm.org/D111279
2021-10-13 08:07:40 -04:00
Joe Loser 8e92410ecc
[libc++][docs] Mark LWG3274 as complete
Mark LWG3274 as complete. The feature test macro `__cpp_lib_span` was added in
`6d2599e4f776d0cd88438cb82a00c4fc25cc3f67`.

https://wg21.link/p1024 mentions marking `span:::empty()` with
`[[nodiscard]]` which is not done yet. So, do that and add tests.

Reviewed By: ldionne, Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D111516
2021-10-12 22:31:32 -04:00
Mark de Wever 968e27397c [libc++] Use addressof to fix debug tests.
Fixes the tests added in D110852 for the debug iterators.

Similar issues with hijacking `operator&` still exist, they will be
addressed separately.

Reviewed By: #libc, ldionne, Quuxplusone

Differential Revision: https://reviews.llvm.org/D111564
2021-10-12 18:15:35 +02:00
David Tenty 1112b7bad8 [libcxx][AIX] Explicitly include localedef.h in locale.cpp
This header was transitively included to provide the definition of
__lc_ctype_ptr that we use on AIX, but that is fragile as it depends on
the settings of compatibility macros, so we explicitly include it here
to avoid that scenario.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D111239
2021-10-12 12:00:03 -04:00
Mark de Wever a76e698787 [libc++] Update atomic synopsis and tests.
While looking at LWG-2988 and P0558 it seems the issues were already
implemented, but the synopsis wasn't updated. Some of the tests didn't
validate the `noexcept` status. A few tests were missing completely:
- `atomic_wait_explicit`
- `atomic_notify_one`
- `atomic_notify_all`

Mark P0558 as complete, didn't investigate which version of libc++ first
includes this. It seems the paper has been retroactively applied. I
couldn't find whether this is correct, but looking at cppreference it
seems intended.

Completes
- LWG-2988 Clause 32 cleanup missed one typename
- P0558 Resolving atomic<T> named base class inconsistencies

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D103765
2021-10-12 17:28:08 +02:00
Martin Storsjö 6cac17e365 [libcxx] [test] Make windows triples in XFAILs less specific
This allows picking up on mingw triples that often use 'w64' instead
of 'pc' as the vendor part.

Differential Revision: https://reviews.llvm.org/D111297
2021-10-12 18:24:47 +03:00
Louis Dionne f4c1258d56 [libc++] Add an option to disable wide character support in libc++
Some embedded platforms do not wish to support the C library functionality
for handling wchar_t because they have no use for it. It makes sense for
libc++ to work properly on those platforms, so this commit adds a carve-out
of functionality for wchar_t.

Unfortunately, unlike some other carve-outs (e.g. random device), this
patch touches several parts of the library. However, despite the wide
impact of this patch, I still think it is important to support this
configuration since it makes it much simpler to port libc++ to some
embedded platforms.

Differential Revision: https://reviews.llvm.org/D111265
2021-10-12 06:08:23 -04:00
Joe Loser e889099986
[libc++][docs] Mark LWG3447 as complete
Mark LWG3447 as complete since it was not an issue since the original
implementation of `take_view` from
0f4b41e038. Currently, `take_view`'s
deduction guide does not constrain the range on the `range` concept.

Reviewed By: ldionne, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D111501
2021-10-11 21:40:46 -04:00
Joe Loser 0d450aa641
[libc++] P2401: conditional noexcept for std::exchange
Implement P2401 which adds a `noexcept` specification to
`std::exchange`. Treated as a defect fix which is the motivation for
applying this change to all standards mode rather than just C++23 or
later as the paper suggests.

Reviewed By: Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D111481
2021-10-11 14:34:45 -04:00
Joe Loser 70d7bef1e8
[libc++] Verify span and string_view are trivially copyable
Implement P2251 which requires `span` and `basic_string_view` to be
trivially copyable. They already are - this just adds tests to bind that
behavior.

Reviewed By: ldionne, Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D111197
2021-10-11 14:29:09 -04:00
David Spickett cd1bd95d87 [libcxx][pretty printers] Disable u16string tests
Due to reported failures in a local build.

FAIL: Something is wrong in the test framework.
Converting character sets: Invalid argument.

(was enabled in https://reviews.llvm.org/D111138)
2021-10-11 09:30:17 +01:00
Arthur O'Dwyer 3df094d31e [libc++] [P1614] Implement std::compare_three_way.
Differential Revision: https://reviews.llvm.org/D110735
2021-10-10 21:57:10 -04:00
Joe Loser 65d62e52a7
[libc++][test] Replace a TEST_NOEXCEPT_FALSE with noexcept(false). NFC.
Replace `TEST_NOEXCEPT_FALSE` directly with `noexcept(false)` in
optional hash test which is only run in C++17 or later.
`TEST_NOEXCEPT_FALSE` is only useful in C++03 context where `noexcept`
isn't supported by clang. `TEST_NOEXCEPT_FALSE` now only has one remaining use
in `hash_unique_ptr.pass.cpp`.
2021-10-10 14:46:35 -04:00
Joe Loser e53c9251fa
[libc++] Remove empty namespace std in type_traits. NFCI.
There is an empty `namespace std` in `type_traits` which was originally
used when `std::byte` was added in
c97d8aa866. At some point, the bitwise operators
on `std::byte` got relocated but this empty namespace was left around.
Remove it.

Reviewed By: Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D111512
2021-10-10 14:35:05 -04:00
Joe Loser 67964fc4b2
[libc++][NFC] Replace tab with whitespace in comment
There is a stray tab character in a comment block. Replace the tab
character with a space for consistency with other comments.
2021-10-10 12:53:35 -04:00
Mark de Wever dcbfceffde [libc++][nfc] Remove a duplicated include. 2021-10-10 14:21:01 +02:00
Joe Loser 903b30fea2
[libc++][test] Remove empty {ind.move.subsumption.compile.pass.cpp}
`{ind.move.subsumption.compile.pass.cpp}` was accidentally commited in
https://reviews.llvm.org/D102639. Per the conversation on Discord in
2021-10-09 17:20:19 -04:00
Mark de Wever a1f0f847ff [NFC][libc++] Update back_insert_iterator style.
As suggested in D110573 land the rename part separately.
2021-10-09 13:31:20 +02:00
Mark de Wever b67a8a6513 [libc++][doc] Update format status.
Updated based on recent commits.
2021-10-09 13:28:38 +02:00
Kent Ross b80f2dfd11 [libc++][spaceship] Implement std::tuple::operator<=>
Implement parts of P1614, including three-way comparison for tuples, and expand testing.

Reviewed By: ldionne, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D108250
2021-10-08 16:24:28 -07:00
Joe Loser 3a208c6894
[libc++] Implement P1394r4 for span: range constructor
Implement https://wg21.link/p1394 which allows span to be constructible
from any contiguous forwarding-range that has a compatible element type.

Fixes https://bugs.llvm.org/show_bug.cgi?id=51443

Reviewed By: ldionne, Quuxplusone, #libc

Differential Revision: https://reviews.llvm.org/D110503
2021-10-08 17:00:39 -04:00
Mark de Wever 352c3af3ab [libc++][doc] Update paper status.
Update the status with the approved papers and LWG-issues in the October 2021 plenary.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D111166
2021-10-08 20:22:44 +02:00
Martin Storsjö 1b53413a38 [libcxx] Fix a missed case needing "system header" markings for init_priority(100)
This was missed in D95972 / 7c49052b17,
as this codepath isn't exercised by CI yet.

Differential Revision: https://reviews.llvm.org/D111292
2021-10-08 20:35:55 +03:00
Mark de Wever aac5b84d4b [libc++] Improve atomic_fetch_(add|sub).*.
While looking at the review comments in D103765 there was an oddity in
the tests for the following functions:
- atomic_fetch_add
- atomic_fetch_add_explicit
- atomic_fetch_sub
- atomic_fetch_sub_explicit

Libc++ allows usage of
`atomic_fetch_add<int>(atomic<int*>*, atomic<int*>::difference_type);`
MSVC and GCC reject this code: https://godbolt.org/z/9d8WzohbE

This makes the atomic `fetch(add|sub).*` Standard conforming and removes the non-conforming extensions.

Fixes PR47908

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D103983
2021-10-08 17:41:57 +02:00
Louis Dionne 980c7f3249 [libc++] Remove the ad-hoc "unified standalone" build
It is not used anywhere anymore since we're using the new runtimes build
in <monorepo>/runtimes now, so we can remove all traces of this build.

Differential Revision: https://reviews.llvm.org/D111351
2021-10-08 10:57:40 -04:00
Louis Dionne 1262f8a64d [libc++] Remove the CI job for Apple/System/Noexceptions
When we recently started using DYLD_LIBRARY_PATH to run the test suite
on the Apple/System configuration of the library, the -fno-exceptions
variant started failing.

It started failing because under that configuration, libc++abi.dylib
doesn't provide support for exceptions. For example, it doesn't provide
some symbols such as ___gxx_personality_v0. Now, the problem is that
when the test suite is run with DYLD_LIBRARY_PATH, /usr/lib/libobjc.dylib
uses the just-built libc++abi.dylib, which doesn't support exceptions,
and we end up with an unresolved reference to ___gxx_personality_v0.

Previously, using -Wl,-rpath,path/to/lib, we would be loading both
/usr/lib/libc++abi.dylib and <just-built>/lib/libc++abi.dylib.
/usr/lib/libobjc.dylib would use the system libc++abi.dylib, which
contains support for exceptions, and the tests would be using the
just-built one, which doesn't.

Disentangling that led me to believe that we shouldn't try to test this
configuration where libc++/libc++abi are built as system libraries, but
where they don't support exceptions, since that just doesn't make any
sense. Doing so is like trying to build libc++/libc++abi and test it as
a system library after performing an ABI break -- of course nothing is
going to work.

For that reason, I am removing this configuration. Note that we could
still test the library on macOS without exceptions if we wanted, only
we wouldn't be building it as a system library. This patch doesn't add
that because we already have a -fno-exceptions CI job on Linux.

Differential Revision: https://reviews.llvm.org/D111349
2021-10-07 17:27:24 -04:00
Louis Dionne c07b80ca53 [libc++] Add a from-scratch testing config for GCC
Differential Revision: https://reviews.llvm.org/D111329
2021-10-07 17:26:25 -04:00
Louis Dionne f6a74908a7 [runtimes] Add tests for vendor-specific properties
Vendors take libc++ and ship it in various ways. Some vendors might
ship it differently from what upstream LLVM does, i.e. the install
location might be different, some ABI properties might differ, etc.

In the past few years, I've come across several instances where
having a place to test some of these properties would have been
incredibly useful. I also just got bitten by the lack of tests
of that kind, so I'm adding some now.

The tests added by this commit for Apple platforms have numerous
TODOs that capture discrepancies between the upstream LLVM CMake
and the slightly-modified build we perform internally to produce
Apple's system libc++. In the future, the goal would be to upstream
all those differences so that it's possible to build a faithful
Apple system libc++ with the upstream LLVM sources only.

But this isn't only useful for Apple - this lays out the path for
any vendor being able to add their own checks (either upstream or
downstream) to libc++.

This is a re-application of 9892d1644f, which was reverted in 138dc27186
because it broke the build. The issue was that we didn't apply the required
changes to libunwind and our CI didn't notice it because we were not
running the libunwind tests. This has been fixed now, and we're running
the libunwind tests in CI now too.

Differential Revision: https://reviews.llvm.org/D110736
2021-10-07 15:46:20 -04:00
Mark de Wever b8608b8723 [libc++] Use addressof in assignment operator.
Replace `&__rhs` with `_VSTD::addressof(__rhs)` to guard against ADL hijacking
of `operator&` in `operator=`. Thanks to @CaseyCarter for bringing it to our
attention.

Similar issues with hijacking `operator&` still exist, they will be
addressed separately.

Reviewed By: #libc, Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D110852
2021-10-07 18:10:47 +02:00
Mark de Wever b25f618857 [libcxx[ Run generate_private_header_tests.py
The script was recently updated to generate different output. This
breaks the CI due the patches which used the old version of the script.
2021-10-07 17:37:50 +02:00
Mark de Wever 7fb9f99f3b [libc++][format] Adds bool formatter.
Implements the formatter for Boolean types.
[format.formatter.spec]/2.3
For each charT, for each cv-unqualified arithmetic type ArithmeticT other
than char, wchar_t, char8_t, char16_t, or char32_t, a specialization
```
  template<> struct formatter<ArithmeticT, charT>;
```
This removes the stub implemented in D96664.

Implements parts of:
- P0645 Text Formatting
- P1652 Printf corner cases in std::format

Completes:
- P1868 width: clarifying units of width and precision in std::format

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D103670
2021-10-07 17:17:27 +02:00
Mark de Wever 49e736d845 [libc++][format] Adds char formatter.
Implements the formatter for all fundamental integer types.
[format.formatter.spec]/2.1
The specializations
```
  template<> struct formatter<char, char>;
  template<> struct formatter<char, wchar_t>;
  template<> struct formatter<wchar_t, wchar_t>;
```
This removes the stub implemented in D96664.

Implements parts of:
- P0645 Text Formatting

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D103466
2021-10-07 17:15:58 +02:00
Mark de Wever 3e9689d72c [libc++][format] Adds integer formatter.
Implements the formatter for all fundamental integer types
(except `char`, `wchar_t`, and `bool`).
[format.formatter.spec]/2.3
For each charT, for each cv-unqualified arithmetic type ArithmeticT other
than char, wchar_t, char8_t, char16_t, or char32_t, a specialization
```
  template<> struct formatter<ArithmeticT, charT>;
```
This removes the stub implemented in D96664.

As an extension it adds partial support for 128-bit integer types.

Implements parts of:
- P0645 Text Formatting
- P1652 Printf corner cases in std::format

Completes:
- LWG-3248 #b, #B, #o, #x, and #X presentation types misformat negative numbers

Reviewed By: #libc, ldionne, vitaut

Differential Revision: https://reviews.llvm.org/D103433
2021-10-07 17:07:51 +02:00
Mark de Wever d550930afc [libc++][format] Adds string formatter.
Implements the formatter for all string types.
[format.formatter.spec]/2.2
For each charT, the string type specializations
```
  template<> struct formatter<charT*, charT>;
  template<> struct formatter<const charT*, charT>;
  template<size_t N> struct formatter<const charT[N], charT>;
  template<class traits, class Allocator>
    struct formatter<basic_string<charT, traits, Allocator>, charT>;
  template<class traits>
    struct formatter<basic_string_view<charT, traits>, charT>;
```
This removes the stub implemented in D96664.

Implements parts of:
- P0645 Text Formatting
- P1868 width: clarifying units of width and precision in std::format

Reviewed By: #libc, ldionne, vitaut

Differential Revision: https://reviews.llvm.org/D103425
2021-10-07 17:03:04 +02:00
David Spickett 7ee133d3fc [libcxx][pretty printers] Correct tests run detection
Missing "global" meant that we set a local "has_run_tests"
so the global was False by the time everything has run.
2021-10-07 13:36:01 +01:00
David Spickett 88f08899da [libcxx][pretty printers] Report not being able to trace test program
If you don't have ptrace permissions this test will fail to run
silently, this adds a check for that and anything else that
might do similar things.

The output will now be:
```
FAILED test program did not run correctly, check gdb warnings

/usr/bin/gdb: warning: Couldn't determine a path for the index cache
directory.
No symbol table is loaded.  Use the "file" command.
warning: Error disabling address space randomization: Operation not
permitted
warning: Could not trace the inferior process.
warning: ptrace: Operation not permitted

error: command failed with exit status: 255
```

We already have a feature to check for a compatible python enabled
gdb, so I think it's reasonable to check for this at test runtime.

Note that this is different to the catch all at the end of the test
script. That would be a case where you can trace but something else
made it stop mid way that wasn't our test breakpoints.

Reviewed By: saugustine

Differential Revision: https://reviews.llvm.org/D110936
2021-10-07 11:02:35 +01:00
David Spickett 17608d345f [libcxx][pretty printers] Correct locale for u16/u32 string tests
When the locale is not some UTF-8 these tests fail.
(different results for python2 linked gdbs vs. python3
but same issue)

Setting the locale just for the test works around this.
By default Ubuntu comes with just C.UTF-8. I've chosen
to use en_US.UTF-8 instead given that my Mac doesn't have
the former and there's a slim chance this test might run there.

This also enables the u16string tests which are now passing.

Reviewed By: #libc, ldionne, saugustine

Differential Revision: https://reviews.llvm.org/D111138
2021-10-07 09:26:26 +01:00
David Spickett da59376546 [libcxx][CI] Install all locales used by the test suite
Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D111235
2021-10-07 09:24:17 +01:00
Arthur O'Dwyer 610ac8dbcc [libc++] [test] s/ContiguousView/MoveOnlyView/g. NFCI.
The unique (ha!) thing about this range type is that it's move-only.
Its contiguity is unsurprising (most of our test ranges are contiguous).
Discussed in D111231 but committed separately for clarity.
2021-10-06 16:43:03 -04:00
Arthur O'Dwyer 3666dd795d [libc++] [test] Change a lot of free begin/end pairs to members. NFCI.
If you have a `begin() const` member, you don't need a `begin()` member
unless you want it to do something different (e.g. have a different return
type). So in general, //view// types don't need `begin()` non-const members.

Also, static_assert some things about the types in "types.h", so that we
don't accidentally break those properties under refactoring.

Differential Revision: https://reviews.llvm.org/D111231
2021-10-06 16:43:03 -04:00
Louis Dionne 7c49052b17 [libc++] Use init_priority(100) when possible
Priorities below 101 are reserved for the implementation, so that's what
we should be using here. That is unfortunately only supported on more
recent versions of Clang. See https://reviews.llvm.org/D31413 for details.

Differential Revision: https://reviews.llvm.org/D95972
2021-10-06 15:53:56 -04:00
Louis Dionne 19a3e24803 [libc++] Simplify writing testing config files
Reduce code duplication by sharing most of the test suite setup across
the different from-scratch configs.

Differential Revision: https://reviews.llvm.org/D111196
2021-10-06 15:51:02 -04:00
Joe Loser 4be7f48960
[libc++] Implement P1391 for string_view
Implement P1391 (https://wg21.link/p1391) which allows
`std::string_view` to be constructible from any contiguous range of
characters.

Note that a different paper (http://wg21.link/P1989) handles the generic
range constructor for `std::string_view`.

Reviewed By: ldionne, Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D110718
2021-10-06 14:17:10 -04:00
Louis Dionne 60fe1f59d0 [runtimes][ci] Run the tests for libunwind in the CI
We should arguably have always been doing that. The state of libunwind
is quite sad, so this commit adds several XFAILs to make the CI pass.
We need to investigate why so many tests are not passing in some
configurations, but I'll defer that to folks who actually work on
libunwind for lack of bandwidth.

Differential Revision: https://reviews.llvm.org/D110872
2021-10-06 11:25:26 -04:00
Louis Dionne 84b0b52b03 [libc++] Refactor how basic_string and vector hoist exception-throwing functions
In basic_string and vector, we've been encapsulating all exception
throwing code paths in helper functions of a base class, which are defined
in the compiled library. For example, __vector_base_common defines two
methods, __throw_length_error() and __throw_out_of_range(), and the class
is externally instantiated in the library. This was done a long time ago,
but after investigating, I believe the goal of the current design was to:

1. Encapsulate the code to throw an exception (which is non-trivial) in
   an externally-defined function so that the important code paths that
   call it (e.g. vector::at) are free from that code. Basically, the
   intent is for the "hot" code path to contain a single conditional jump
   (based on checking the error condition) to an externally-defined function,
   which handles all the exception-throwing business.

2. Avoid defining this exception-throwing function once per instantiation
   of the class template. In other words, we want a single copy of
   __throw_length_error even if we have vector<int>, vector<char>, etc.

3. Encapsulate the passing of the container-specific string (i.e. "vector"
   and "basic_string") to the underlying exception-throwing function
   so that object files don't contain those duplicated string literals.
   For example, we'd like to have a single "vector" string literal for
   passing to `std::__throw_length_error` in the library, instead of
   having one per translation unit.

However, the way this is achieved right now has two problems:

- Using a base class and exporting it is really weird - I've been confused
  about this ever since I first saw it. It's just a really unusual way of
  achieving the above goals. Also, it's made even worse by the fact that
  the definitions of __throw_length_error and __throw_out_of_range appear
  in the headers despite always being intended to be defined in the compiled
  library (via the extern template instantiation).

- We end up exporting those functions as weak symbols, which isn't great
  for load times. Instead, it would be better to export those as strong
  symbols from the library.

This patch fixes those issues while retaining ABI compatibility (e.g. we
still export the exact same symbols as before). Note that we need to
keep the base classes as-is to avoid breaking the ABI of someone who
might inherit from std::basic_string or std::vector.

Differential Revision: https://reviews.llvm.org/D111173
2021-10-05 20:53:40 -04:00
Louis Dionne d51f57c23c [libc++] Pickle substitutions to pass them to dsl.sh.py
This is less brittle than hand-picking the substitutions that we
pass to the test, since a config could theorically use non-base
substitutions as well (such as defining %{flags} in terms of another
substitution like %{include}).

Also, print the decoded substitutions, which makes it much easier
to debug the test when it fails.

Differential Revision: https://reviews.llvm.org/D111179
2021-10-05 19:51:23 -04:00
Louis Dionne 54a8a0d09a [runtimes] Allow FOO_TEST_CONFIG to be a relative path
That makes it possible to store that value in a CMake cache if needed.

Differential Revision: https://reviews.llvm.org/D110843
2021-10-05 19:45:50 -04:00
Louis Dionne 7c9d9e4e64 [libc++] Run the no-unicode CI job on new testing configs
This was most likely an oversight, since we're running all other jobs on
the new configs.

Differential Revision: https://reviews.llvm.org/D111168
2021-10-05 16:55:31 -04:00
Joe Loser 8cf5319aff
[libc++][test] Use = delete over DELETE_FUNCTION. NFC.
Some tests repeat the definition of `DELETE_FUNCTION` macro locally.
However, it's not even requred to guard against in the C++03 case since
Clang supports `= delete;` in C++03 mode. A warning is issued but
`libc++` tests run with `-Wno-c++11-extensions`, so this isn't an issue.
Since we don't support other compilers in C++03 mode, `= delete;` is
always available for use. As such, inline all calls of `DELETE_FUNCTION`
to use `= delete;`.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D111148
2021-10-05 14:08:48 -04:00
Joe Loser 0ad9013fcd
[libc++][test] Remove unused macro in is_constructible.pass.cpp. NFC.
Test file defines `LIBCPP11_STATIC_ASSERT` but it never uses it now. It
always uses `static_assert` unconditionally. So, remove the unused
macro.
2021-10-05 10:15:24 -04:00
Martin Storsjö 204d563948 [libcxx] [test] Move a missed test to ctime.timespec.compile.pass.cpp
This was missed in ec574f5da4. TIME_UTC
is a define that goes along with timespec_get. The testcase that it is
moved to is only run for >= C++17, so the surrounding ifdef guard
can be dropped.

Differential Revision: https://reviews.llvm.org/D110988
2021-10-05 10:47:34 +03:00
Martin Storsjö a8d15a9266 [libcxx] Don't autodetect pthreads on MinGW
e9ee517930 added support for using
winpthreads on Windows, enabled if `__WINPTHREADS_VERSION` was
defined (i.e. if winpthreads headers have been included before
including libcxx `__config`). This was fragile (libcxx changed
behaviour depending on what headers had been included externally
before), and was changed in a1bc823a59
to use pthreads on Windows whenever the pthread.h header was
available.

This is also fragile; pthread.h might be unavailable while building
libcxx but installed later, and available when users include the
libcxx headers.

In practice, in every modern setup for building libcxx for Windows
I've seen, users end up manually configuring it with
`LIBCXX_HAS_WIN32_THREAD_API=ON`, as the users may have winpthreads
installed (for other libraries/projects to use) while wanting to
build libcxx with the default win32 threading.

Don't automatically pick up pthreads on Windows even if the header
is available. Instead require the user to configure the libcxx
build with `LIBCXX_HAS_PTHREAD_API=ON` if that's desired.

Differential Revision: https://reviews.llvm.org/D110975
2021-10-05 10:46:48 +03:00
Louis Dionne f800560ff1 [libc++] Rename the 'libc++' Lit feature to 'llvm-libc++'
This is to simplify an upcoming change where we distinguish between
flavors of libc++ by adding an apple-libc++ Lit feature.

Differential Revision: https://reviews.llvm.org/D110870
2021-10-04 18:32:50 -04:00
Louis Dionne 45395775c1 [libc++] Disable the Apple system -fno-exceptions CI that is currently building
I'm disabling it to avoid blocking everybody until I've fixed the issue.
2021-10-04 14:58:30 -04:00
Louis Dionne 83bc88174e [libc++][NFC] Fix include guard for some detail header 2021-10-04 13:36:08 -04:00