Commit Graph

11229 Commits

Author SHA1 Message Date
Nikolas Klauser
640274ff1f [libc++][NFC] Refactor __enable_ifs in <cstddef> to be defaulted
template arguments

This makes the library more consistent and reduces the size of mangled
names a bit as a bonus.
2023-10-29 11:49:50 +01:00
Vitaly Buka
22c3d9d9a4 [libc++] Disable test which timeouts on ARM with sanitizers
Introduced with cf0f6a1460 (#70020).

https://lab.llvm.org/buildbot/#/builders/237/builds/5145
https://lab.llvm.org/buildbot/#/builders/236/builds/7004
https://lab.llvm.org/buildbot/#/builders/239/builds/4269

Sometimes it passes with Asan but it's extemly slow

```
Slowest Tests:
1388.61s: llvm-libc++-shared.cfg.in :: std/experimental/simd/simd.reference/reference_assignment.pass.cpp
309.42s:  llvm-libc++-shared.cfg.in :: std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp
```
2023-10-27 14:28:28 -07:00
Louis Dionne
574c5cc9d8 [libc++] Fix incorrect length check in std::basic_filebuf
This patch fixes an ASAN-found issue in std::basic_filebuf where we'd
check the wrong size before proceeding to set our internal buffer to
the externally-provided buffer, leading to the library trying to read
from the incorrect buffer in underflow().

Thanks to Andrey Semin for the patch.

Differential Revision: https://reviews.llvm.org/D154514
2023-10-27 10:21:50 -04:00
Louis Dionne
cb950c9dc9
[libc++] Make sure we implement and test LWG2280 properly (#67670)
We did not mark std::begin/std::end as noexcept for C-style arrays, we
did not have conditional noexcept on cbegin/cend, and we did not mark
array cbegin/cend as constexpr in all Standard modes. Since this is a
LWG issue, we should implement it as a DR in all Standard modes as
usual.

This patch fixes these issues and adds test coverage. Fixes #67471.
2023-10-27 10:19:20 -04:00
Konstantin Varlamov
b3b611fe1a
[libc++] Fix flakiness in atomic_notify_all.pass.cpp (#70436)
Avoid relying on sleep for synchronization.
2023-10-27 09:49:54 -04:00
Rajveer Singh Bharadwaj
dd4891318c
[libc++] Fix _CopySegment helper in ranges::copy(join_view, out) when called in a static assertion context (#69593)
Resolves Issue #69083

The `_CopySegment` helper for `ranges::copy(join_view, out)` is not
`constexpr` causing rejection in `libc++` in a static assertion context
as in the issue snippet.
2023-10-27 11:07:12 +02:00
Vitaly Buka
fde1ecdec8 Revert "[libc++][tests] Fix a few remaining instances of outdated static assertion regexes in our test suite"
Fails like https://lab.llvm.org/buildbot/#/builders/238/builds/6278/steps/11/logs/stdio on many bots.

This reverts commit 166b3a8617.
2023-10-27 00:02:31 -07:00
Vitaly Buka
8d30e80166 Fix typo in c07903aac7 2023-10-26 23:44:58 -07:00
Vitaly Buka
c07903aac7 [libc++abi] Disable test with a leaks
Leak could be real, as the code terminates before freeing the memory.
2023-10-26 21:48:56 -07:00
ZhangYin
cf0f6a1460
[libc++] <experimental/simd> Add assignment operator of simd reference (#70020) 2023-10-26 23:09:55 +02:00
Louis Dionne
59750027b9
[libc++][NFC] Remove unused typedefs in filesystem::path helpers (#70331)
I came across those typedefs while working on another change, and I
noticed they were just never used.
2023-10-26 13:10:44 -04:00
Ilya Tocar
178a1fea57
[libc++] Optimize string operator[] for known large inputs (#69500)
If we know that index is larger than SSO size, we know that we can't be
in SSO case, and should access the pointer. This removes extra check
from operator[] for inputs known at compile time to be larger than SSO.
2023-10-26 13:09:20 -04:00
Louis Dionne
166b3a8617 [libc++][tests] Fix a few remaining instances of outdated static assertion regexes in our test suite 2023-10-26 11:31:36 -04:00
Igor Zhukov
c555a12377 [libc++] Make sure std::declval() produces an error when ODR-used
Fixes https://github.com/llvm/llvm-project/issues/61202

Differential Revision: https://reviews.llvm.org/D145376
2023-10-26 11:27:12 -04:00
Nikolas Klauser
a349092061 [libc++] Add __small_buffer
This is an implementation detail for `move_only_function` (and potentially other type-erasing classes).

Reviewed By: #libc, ldionne

Spies: Mordante, ldionne, EricWF, libcxx-commits

Differential Revision: https://reviews.llvm.org/D140259
2023-10-26 17:25:53 +02:00
Louis Dionne
bc792a2843
[libc++] Encode additional ODR-affecting properties in the ABI tag (#69669)
As explained in `__config`, we have an ABI tag that we use to ensure
that we don't run into ODR issues when mixing different versions of
libc++ in multiple TUs. However, the reasoning behind that extends not
only to different versions of libc++, but also to different
configurations of the same version of libc++. In fact, we've been aware
of this for a while but never really bothered to make the change because
ODR issues are often thought to be benign.

Well, it turns out that I just spent over an hour banging my head
against an issue that boils down to our lack of encoding of some ODR
properties in the ABI tag, so here's the patch we should have done a
long time ago.

For now, the ODR properties we encode in the ABI tag are:
- library version
- exceptions vs no-exceptions
- hardening mode

Those are all things that we support different values for on a per-TU
basis and they definitely affect ODR in a meaningful way. We can add
more properties later as we see fit.
2023-10-26 09:05:16 -04:00
Eric
78dcd015b6
Improve CI output. (#70236)
There is currently a major problem with the CI output:

The information you need to see never appears in the visible log.

This is because our logs are very verbose, and list (A) every test as
they run it, and (B) every unsupported tests. This can be thousands of
lines.

(A) was introduced by me when I disabled the PTY progress bar, which
doesn't play nice with log files. That change was an improvement, but I
have now disabled the PTY on the builders, so we can go back to passing
`-s`. When `-s` is passed but no PTY is available, it prints a long
friendly progress indicator.

(B) is solved here by disabling the printing of unsupported tests at the
end of the test suite. While it can be useful on occasion to audit the
list of unsupported tests, it's far from a common operation. Instead
people want to see the log of their failure. We should upload the xml
results, so if auditing is needed, it can be done using that.

Hopefully this change will make it so that the test failures appear in
the actual log output
2023-10-25 18:10:29 -04:00
Jakub Mazurkiewicz
e1e0598e20
[libc++] Update status of P2770R0, P2441R2 and P2711R1 (#70045)
This patch adds a mention that the following papers are in progress:

* P2770R0: #66033
* P2441R2 and P2711R1: #65536
2023-10-24 12:03:12 -07:00
Louis Dionne
15f179e5d1
[libc++] Remove the Buildkite job that builds documentation (#69992)
Since #69828, we have a Github Action that builds the documentation for
libc++, so we don't need to do it as part of our Buildkite pipeline
anymore.
2023-10-24 14:06:21 +02:00
Konstantin Varlamov
45d5a49c51
[libc++][NFC] Remove the list of nodiscard extensions from the docs. (#69546)
This list is a burden to maintain and provides very limited value. A
user wishing to know whether a particular function is declared with a
`nodiscard` extension would be better off grepping the headers.
2023-10-24 14:03:57 +02:00
Nikolas Klauser
5d7f346bd3 [libc++][PSTL] Implement std::rotate_copy
Reviewed By: #libc, ldionne

Spies: ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D155025
2023-10-24 14:02:37 +02:00
Ryan Prichard
dc9ed440b5
[libc++][Android] Enable Android testing in BuildKite CI (#69275)
Enable testing for two NDK configurations:
 - android-ndk-21-def-x86
 - android-ndk-33-goog-x86_64

Fixes: https://github.com/llvm/llvm-project/issues/69270
2023-10-23 14:24:33 -07:00
ZhangYin
dc53410693
[libc++] <experimental/simd> Add operator value_type() of simd reference (#68960) 2023-10-23 11:51:34 +02:00
Hans Wennborg
e2fc68c3db Typos: 'maxium', 'minium' 2023-10-23 10:42:28 +02:00
Nikolas Klauser
d2a46e6480 [libc++][PSTL] Implement std::move
Reviewed By: #libc, ldionne

Spies: ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D155330
2023-10-22 10:25:49 +02:00
Ryan Prichard
07ba499817
[libc++][Android] Disable Android ABI list checking (#69666)
Issue: https://github.com/llvm/llvm-project/issues/69270
2023-10-20 13:26:28 -04:00
Joel E. Denny
080fb3e5b7
[lit] Clean up internal shell parse errors with ScriptFatal (#68496)
Without this patch, the functions `executeScriptInternal` and thus
`runOnce` in `llvm/utils/lit/lit/TestRunner.py` return either a tuple like
`(out, err, exitCode, timeoutInfo)` or a `lit.Test.Result` object. They
return the latter only when there's a lit internal shell parse error in
a RUN line. In my opinion, a more straight-forward way to handle
exceptional cases like that is to use python exceptions.

For that purpose, this patch introduces `ScriptFatal`. Thus, this patch
changes `executeScriptInternal` to always either return the tuple or
raise the `ScriptFatal` exception. It updates `runOnce` and
`libcxx/utils/libcxx/test/format.py` to catch the exception rather than
check for the special return type.

This patch also changes `runOnce` to convert the exception to a
`Test.UNRESOLVED` result instead of `TEST.FAIL`. The former is the
proper result for such a malformed test, for which a rerun (given an
`ALLOW_RETRIES:`) serves no purpose. There are at least two benefits
from this change. First, `_runShTest` no longer has to specially and
cryptically handle this case to avoid unnecessary reruns. Second, an
`XFAIL:` directive no longer hides such a failure [as we saw
previously](https://reviews.llvm.org/D154987#4501125).

To facilitate the `_runShTest` change, this patch inserts the internal
shell parse error diagnostic into the format of the test's normal debug
output rather than suppressing the latter entirely. That change is also
important for [D154987](https://reviews.llvm.org/D154987), which
proposes to reuse `ScriptFatal` for python compile errors in PYTHON
lines or in `config.prologue`. In that case, the diagnostic might follow
debugging output from the test's previous RUN or PYTHON lines, so
suppressing the normal debug output would lose information.
2023-10-20 11:53:18 -04:00
Christian Trott
639a0986f3
[libc++] mdspan - implement layout_stride (#69650)
This implements layout_stride for C++23 and with that completes the
implementation of the C++23 mdspan header. The feature test macro is
added, and the status pages updated.

Co-authored-by: Damien L-G <dalg24@gmail.com>

Differential Revision: https://reviews.llvm.org/D157171
2023-10-20 08:13:52 -06:00
Louis Dionne
7961fa36ba
[libc++] Fix uninitialized algorithms when using unconstrained comparison operators (#69373)
If an iterator passed to std::uninitialized_copy & friends provided an
unconstrained comparison operator, we would trigger an ambiguous
overload resolution because we used to compare against
__unreachable_sentinel in our implementation.

This patch fixes that by only comparing the output iterator when it is
actually required, i.e. in the <ranges> versions of the algorithms.

Fixes #69334
2023-10-19 23:22:11 -07:00
Ryan Prichard
a7c4ff9a56
[libc++][Android] Don't list Android as supported yet (#69660)
We don't have a pre-commit CI bot running Android tests yet, so this is still WIP.
2023-10-19 18:09:39 -07:00
Ryan Prichard
bce3b50593
[libc++][Android] Mark tests XFAIL/UNSUPPORTED (#69271)
Mark tests as necessary to accommodate Android L (5.0 / API 21) and up.

Add three Android lit features:
 - android
 - android-device-api=(21,22,23,...)
 - LIBCXX-ANDROID-FIXME (for failures that need follow-up work)

Enable an AIX workaround in filesystem_test_helper.h for the broken
chmod on older Android devices.

Mark failing test with XFAIL or UNSUPPORTED:
 - Mark modules tests as UNSUPPORTED, matching other configurations.
 - Mark a gdb test as UNSUPPORTED.
 - XFAIL tests for old devices that lack an API (fmemopen).
- XFAIL various FS tests (because SELinux blocks FIFO and hard linking,
because fchmodat is broken on old devices).
- XFAIL various locale tests (because Bionic has limited locale
support). (Also XFAIL an re.traits test.)
- XFAIL some print.fun tests because the error exception has no system
error string.
- Mark std::{cin,wcin} tests UNSUPPORTED because they hang with
adb_run.py on old devices.
 - Mark a few tests UNSUPPORTED because they allocate too much memory.
 - notify_one.pass.cpp is flaky on Android.
- XFAIL libc++abi demangler test because of Android's special long
double on x86[-64].

N.B. The `__ANDROID_API__` macro specifies a minimum required API level
at build-time, whereas the android-device-api lit feature is the
detected API level of the device at run-time. The android-device-api
value will be >= `__ANDROID_API__`.

This commit was split out from https://reviews.llvm.org/D139147.

Fixes: https://github.com/llvm/llvm-project/issues/69270
2023-10-19 17:27:01 -07:00
Ryan Prichard
a30095a1e4
[libc++][Android] Add libcxx-builder-android Docker image (#69273)
Add a Dockerfile for a new Docker image, libcxx-builder-android, that
extends libcxx-builder with support for testing Android.

The image includes these things:

 * An Android Clang compiler and sysroot.

* The Android platform-tools (e.g. adb), so that an Android buildbot can
run programs on an Android device. At container startup, copy these
platform tools to an "android-platform-tools" Docker volume to share
them with an emulator container. This copying ensures that the emulator
and libcxx-builder containers avoid mismatched adb versions.

* Docker, so that an Android buildbot can manage a sibling Docker
container that runs the Android emulator.

Add an Android-specific run-buildbot-container script for local
development. Currently using this script requires building
libcxx-build-android and an emulator image locally.

Fixes: https://github.com/llvm/llvm-project/issues/69270
Differential Revision: https://reviews.llvm.org/D155271
2023-10-19 17:15:20 -04:00
Ryan Prichard
d173ce4a67
[libc++][Android] Support libc++ testing on Android (#69274)
I could probably break this commit into more pieces.

---

This patch adds libc++ support for Android L (Android 5.0+) and up,
tested using the Android team's current compiler, a recent version of
the AOSP sysroot, and the x86[-64] Android Emulator.

CMake and Lit Configuration:

Add runtimes/cmake/android/Arch-${ARCH}.cmake files that configure CMake
to cross-compile to Android without using CMake's built-in NDK support
(which only works with an actual packaged NDK).

Add libcxx/cmake/caches/AndroidNDK.cmake that builds and tests libc++
(and libc++abi) for Android. This file configures libc++ to match what
the NDK distributes, e.g.:
- libc++_shared.so (includes libc++abi objects, there is no
libc++abi.so). libunwind is linked statically but not exported.
 - libc++_static.a (does not include libc++abi) and libc++abi.a
 - `std::__ndk1` namespace
- All the libraries are built with `__ANDROID_API__=21`, even when they
are linked to something targeting a higher API level.

(However, when the Android LLVM team builds these components, they do
not use these CMake cache files. Instead they use Python scripts to
configure the builds. See
https://android.googlesource.com/toolchain/llvm_android/.)

Add llvm-libc++[abi].android-ndk.cfg.in files that test the Android
NDK's libc++_shared.so. These files can target old or new Android
devices. The Android LLVM team uses these test files to test libc++ for
both arm/arm64 and x86/x86_64 architectures.

The Android testing mode works by setting %{executor} to adb_run.py,
which uses `adb push` and `adb shell` to run tests remotely. adb_run.py
always runs tests as the "shell" user even on an old emulator where "adb
unroot" doesn't work. The script has workarounds for old Android
devices. The script uses a Unix domain socket on the host
(--job-limit-socket) to restrict concurrent adb invocations. Compiling
the tests is a major part of libc++ testing run-time, so it's desirable
to exploit all the host cores without overburdening the test devices,
which can have far fewer cores.

BuildKite CI:

Add a builder to run-buildbot, `android-ndk-*`, that uses Android Clang
and an Android sysroot to build libc++, then starts an Android emulator
container to run tests.

Run the emulator and an adb server in a separate Docker container
(libcxx-ci-android-emulator), and create a separate Docker image for
each emulator OS system image. Set ADB_SERVER_SOCKET to connect to the
container's adb server. Running the only adb server inside the container
makes cleanup more reliable between test runs, e.g. the adb client
doesn't create a `~/.android` directory and the adb server can be
restarted along with the emulator using docker stop/run. (N.B. The
emulator insists on connecting to an adb server and will start one
itself if it can't connect to one.)

The suffix to the android-ndk-* job is a label that concisely specifies
an Android SDK emulator image. e.g.:
 - "system-images;android-21;default;x86" ==> 21-def-x86
 - "system-images;android-33;google_apis;x86_64" ==> 33-goog-x86_64

Fixes: https://github.com/llvm/llvm-project/issues/69270
Differential Revision: https://reviews.llvm.org/D139147
2023-10-19 16:58:30 -04:00
Duo Wang
3daa771047
[libcxx][test] Fix empty.gen selftest on windows (#69403)
Using `true` as a no-op unfortunately does not work on windows, which
fails libcxx lit tests on windows. Lit provides the `:` internal shell
builtin which is equivalent to `true`.
2023-10-19 12:30:05 -07:00
Piotr Fusik
d6a92611eb [libc++] Improve the tests for std::basic_stringbuf's constructors and assignment operators
Differential Revision: https://reviews.llvm.org/D154499

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-10-18 20:25:42 -07:00
Daniel Kutenin
ea9af5e7fd
[libc++] Add assertions for potential OOB reads in std::nth_element (#67023)
Same as https://reviews.llvm.org/D147089 but for std::nth_element
2023-10-18 20:22:17 -07:00
Louis Dionne
a574242f19
[libc++][docs] Update contributing docs to reflect the move to GitHub (#69386)
Fixes #69367
2023-10-18 20:00:50 -07:00
Louis Dionne
208a6d97f5
[libc++] Fix inconsistency between is_lock_free and is_always_lock_free (#68109)
std::atomic is implemented with the following (confusing!) hierarchy of
types:

     std::atomic<T> : std::__atomic_base<T> { ... };
     std::__atomic_base<T> {
          std::__cxx_atomic_impl<T> __impl;
     };
     std::__cxx_atomic_impl<T> {
          _Atomic(T) __val;
     };

Inside std::__atomic_base, we implement the is_lock_free() and
is_always_lock_free() functions. However, we used to implement them
inconsistently:
- is_always_lock_free() is based on whether __cxx_atomic_impl<T> is
always lock free (using the builtin), which means that we include any
potential padding added by _Atomic(T) into the determination.
- is_lock_free() was based on whether T is lock free (using the
builtin), which meant that we did not take into account any potential
padding added by _Atomic(T).

It is important to note that the padding added by _Atomic(T) can turn a
type that wouldn't be lock free into a lock free type, for example by
making its size become a power of two.

The inconsistency of how the two functions were implemented could lead
to cases where is_always_lock_free() would return true, but
is_lock_free() would then return false. This is the case for example of
the following type, which is always lock free on arm64 but was
incorrectly reported as !is_lock_free() before this patch:

     struct Foo { float x[3]; };

This patch switches the determination of is_lock_free() to be based on
__cxx_atomic_impl<T> instead to match how we determine
is_always_lock_free().

rdar://115324353
2023-10-18 19:58:24 -07:00
Louis Dionne
1196e6dda9
[libc++] Move the check-generated-files job to Github Actions (#68920)
This allows running these quick checks faster than in our Buildkite
pipeline, which has much more latency. This will also avoid blocking the
rest of the testing pipeline in case the generated-files checks are
failing.
2023-10-18 19:56:16 -07:00
Louis Dionne
e494a96a69
[libc++][NFC] Refactor the core logic of operator new into helper functions (#69407)
This will make it easier to implement new(nothrow) without calling the
throwing version of new when exceptions are disabled. See
https://llvm.org/D150610 for the full discussion.
2023-10-18 11:33:05 -07:00
Louis Dionne
f362be597a [libc++][NFC] Reformat new.cpp and stdlib_new_delete.cpp
This makes it a lot easier to make wide ranging changes like I am
about to do in https://llvm.org/D150610.
2023-10-18 11:23:32 -07:00
Martin Storsjö
122064a630
[libcxx] [test] Add a test parameter for disabling memory intensive tests (#68214)
Specifically, the test std/input.output/string.streams/stringstream/stringstream.members/gcount.pass.cpp
allocates a std::string with INT_MAX-1 elements, and then writes this to
a std::stringstream. On Linux, running this test consumes around 5.0 GB
of memory; on Windows, it ends up using up to 6.8 GB of memory.

This limits whether such tests can run on e.g. GitHub Actions runners,
where the free runners are limited to 8 GB of memory.

This is somewhat similar to, but still notably different, from the
existing test parameter long_tests.
2023-10-17 12:49:52 -07:00
Amirreza Ashouri
838f2890fd
[libc++] Eliminate extra allocations from std::move(oss).str() (#67294)
Add test coverage for the new behaviors, especially to verify that the
returned string uses the correct allocator.
Fixes https://github.com/llvm/llvm-project/issues/64644

Migrated from https://reviews.llvm.org/D157776 — @philnik777  @pfusik 
@ldionne @mordante 
 please take another look!
2023-10-17 11:38:12 +02:00
Hui
511236e074
[libc++][test] Add stop_token benchmark (#69117)
This is transforming the `stop_token` benchmark that Lewis Baker had
created into Google
Bench
https://reviews.llvm.org/D154702
2023-10-16 21:49:37 +01:00
Nikolas Klauser
fcc13c04bb [libc++] Simplify the tuple constructor overload set
This uses conditional explicit to avoid having two overloads for implicit/explicit conversions.

Reviewed By: ldionne, #libc

Spies: jrtc27, dblaikie, #clang-vendors, #libc_vendors, aaron.ballman, libcxx-commits

Differential Revision: https://reviews.llvm.org/D148432
2023-10-16 19:49:13 +02:00
Louis Dionne
b51eaebd2b
[libc++] Remove workaround for clang-tidy 16 in the test suite setup code (#69035)
We have moved to clang-tidy 17 now, so the workaround shouldn't be
necessary.
2023-10-16 09:18:40 -07:00
Nikolas Klauser
e9c101a753 [libc++] Add missing <__availability> include 2023-10-16 17:08:12 +02:00
Louis Dionne
70fedaf89b [libc++][NFC] Fix slightly incorrect comment in PSTL documentation 2023-10-13 17:27:44 -07:00
Anton Rydahl
f2b79ed9c6
[libcxx] Refactoring SIMD function names in PSTL CPU backend (#69029)
This PR addresses a smaller detail discussed in the code review for
https://github.com/llvm/llvm-project/pull/66968. Currently, some
functions in the `libc++` PSTL CPU backend have been appended with a
digit to indicate the number of input iterator arguments. However, there
is no need to change the name for each version as overloading can be
used instead. This PR will make the naming more consistent in the the
CPU and the proposed OpenMP backend.
2023-10-13 17:08:15 -07:00
Louis Dionne
1bc4871695 [libc++][NFC] Fix typo in filename 2023-10-13 11:58:20 -07:00
Louis Dionne
36bb134ac7
[libc++] Use -nostdlib++ on GCC unconditionally (#68832)
We support GCC 13, which supports the flag. This allows simplifying the
CMake logic around the use of -nostdlib++. Note that there are other
places where we don't assume -nostdlib++ yet in the build, but this
patch is intentionally trying to be small because this part of our CMake
is pretty tricky.
2023-10-13 11:53:57 -07:00
Louis Dionne
475e154331
[libc++] Introduce make_test_jthread for jthread tests (#68837)
This patch introduces the support::make_test_jthread utility which is
basically the same as support::make_test_thread but for std::jthread. It
allows vendors to maintain a downstream way to create threads for use
within the test suite, which is especially useful for embedded
platforms.
2023-10-13 10:54:54 -07:00
Eric
20f39bf482
Lower std::string's alignment requirement from 16 to 8. (#68807)
This allows smaller allocations to occur, closer to the actual
std::string's required size. This is particularly effective in
decreasing the allocation size upon initial construction (where
__recommend is called to determine the size).

Although the memory savings per-string are never more than 8 bytes per
string initially, this quickly adds up. And has lead to not insigficant
memory savings at Google.

Unfortunately, this change is ABI breaking because it changes the value
returned by max_size. So it has to be guarded.
2023-10-13 11:56:24 -04:00
Louis Dionne
ba79fb2e1f [libc++] Re-apply "Remove UB in list, forward_list and __hash_table"
This patch removes undefined behavior in list and forward_list and __hash_table
caused by improperly beginning and ending the lifetime of the various node
classes. It allows removing the _LIBCPP_STANDALONE_DEBUG macro from
these node types since we now properly begin and end their lifetime,
meaning that we won't trip up constructor homing.

See https://reviews.llvm.org/D98750 for more information on what prompted
this patch.

This commit re-applies 0687e4d9f3, which had been reverted in b935882bdc
because it broke the LLDB build. LLDB folks tell me I can go ahead and
re-commit this now.

Differential Revision: https://reviews.llvm.org/D101206

Co-authored-by: Amy Kwan <amy.kwan1@ibm.com>
2023-10-13 08:03:22 -07:00
Louis Dionne
2cea1babef
[libc++] Remove libc++'s own <setjmp.h> header (#68806)
It doesn't seem to do anything useful beyond what the C library header
is doing, so there's no purpose in having one.
2023-10-12 16:59:04 -07:00
Louis Dionne
b3a39a9bdb
[libc++] Check formatting with clang-format 17 (#68928)
This updates the clang-format we use in libc++ to 17. This is necessary
to start running the generated-files checks in GitHub Actions (in
#68920). In fact this is a pre-existing issue regardless of #68920 --
right now our ignore_format.txt job disagrees with the LLVM-wide
clang-format job.
2023-10-12 14:30:33 -07:00
Christian Trott
b0c769a80b
[libc++][mdspan] Fix extents CTAD (#68737)
extents CTAD was requiring default constructibility of the extent
arguments due to the way we implemented a pack expansion. This
requirement is not in the standard.

Reported in issue #68671
https://github.com/llvm/llvm-project/issues/68671 by @hewillk.

Fixes #68671
2023-10-12 13:09:36 -06:00
Louis Dionne
b56488c879
[libc++] Improve the output of the generated-output CI job (#68903)
The step that checked for ignore_format.txt being consistent with the
tree wouldn't print any explicit diagnostic when failing, which led to
confusion. After this patch, an explicit diagnostic will be printed by
the job along with the required diff to ignore_format.txt.
2023-10-12 10:53:33 -07:00
ZhangYin
593521b079
[libcxx] <experimental/simd> Add generate constructor of class simd (#66737)
Differential Revision: https://reviews.llvm.org/D159442
2023-10-12 07:39:31 -05:00
Martin Storsjö
ebf1feaeda
[libcxx] [docs] Update the MinGW build example (#68790)
The previous example wasn't a configuration that we actually test, but
was a simplistic configuration with libstdc++ as ABI library.

The previous example configuration has bitrotted and broken in a couple
different ways since it was added:

- In b0fd9497af, libcxx added uses of weak
  symbols that can be overridden by the user. GNU ld fails to export such
  weak symbols on MinGW, resulting in errors like:
    C:/msys64/mingw64/bin/ld: cannot export _ZNSt3__126__libcpp_assertion_handlerEPKciS1_S1_: symbol wrong type (2 vs 3) 
  By switching to using LLD, -DLLVM_ENABLE_LLD=ON, alternatively
  -DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld, linking still succeeds.

- In a80e65e00a, building with
  -DLIBCXX_CXX_ABI=libstdc++ in this configuration started failing. Switch
  to showing how to build with libcxxabi instead, which is the tested
  configuration and also is the typical configuration in how it most
  usually would be used on Windows.

These updates allow removing the mentions of the old caveats with the
build configuration.
2023-10-11 06:35:08 -07:00
Martin Storsjö
06322d43d5
[libcxx] [docs] Remove mention of a MSVC/Debug mode caveat (#68791)
Since e346fd8a60 and
cd1b8be8de, the tests should run fine in
Debug mode, with failed asserts not popping up blocking dialog boxes.
2023-10-11 06:32:45 -07:00
Louis Dionne
76abab9dc1 [libc++] Run clang-format on newly-added test to fix CI 2023-10-11 06:32:10 -07:00
Louis Dionne
d95a6c949f [libc++][NFC] Fix typo in synopsis comment 2023-10-10 21:51:21 -07:00
James Y Knight
b964419ec2
[libcxx] Allow string to use SSO in constant evaluation. (#66576)
Previously, libcxx forced all strings created during constant evaluation
to point to allocated memory. That was done due to implementation
difficultites, but it turns out not to be necessary. This patch permits
the use of SSO strings during constant evaluation, and also simplifies
the implementation.

This does have a downside in terms of enabling users to accidentally
write non-portable code, however, which I've documented in
UsingLibcxx.rst.

In particular, whether `constinit std::string x = "...";` will
successfully compile now depends on whether the string is smaller than
the SSO capacity -- in libc++, up to 22 bytes on 64-bit platforms, and
up to 10 bytes on 32-bit platforms. By comparison, libstdc++ and MSVC
have an SSO capacity of 15 bytes, except that in libstdc++,
constant-initialized strings cannot be used as function-locals because
the object contains a pointer to itself.

Closes #68434
2023-10-10 11:31:47 -07:00
Konstantin Varlamov
c6151f5350
[libc++][hardening] Undeprecate safe mode (#68391)
To allow for a smoother transition, keep the safe mode working as is in
the LLVM 18 release (the first release that aims to make hardening
available), then deprecate it in LLVM 19.
2023-10-10 11:10:18 -07:00
Louis Dionne
f901254341
[libc++] Remove libc++'s own <limits.h> (#65472)
We do not define anything beyond the C Library's limits.h, so it
shouldn't be needed. This removes the need for a GCC-specific
workaround, see [1].

[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107795

Differential Revision: https://reviews.llvm.org/D138384
2023-10-10 11:06:43 -07:00
kasuga-fj
5fa5ffeb6c
[Clang] Fix missing diagnostic for non-standard layout type in offsetof (#65246)
Fixes #64619

Clang warns diagnostic for non-standard layout types in `offsetof` only
if they are in evaluated context. With this patch, you'll also get
diagnostic if you use `offsetof` on non-standard layout types in any
other contexts
2023-10-10 15:31:21 +09:00
Martin Storsjö
5e3f43e16c
[libcxx] [test] Quote the python executable in the executor (#68208)
This reapplies the change from
c218c80c73, which was lost in the
refactoring in 78d649a417.

On Windows, the Python interpreter is by default installed in a path
like "C:\Program Files\Python38\python.exe", which requires quoting when
included in a concatenated command string (as opposed to a command list,
where each argument is a separate element).

This doesn't show up in the CI environments as they use Python installed
in a different directory, like C:\Python.

In addition to the python executable, also quote the path to run.py, if
needed.
2023-10-09 23:19:06 +03:00
Hui
bcf172ec57
[libc++] LWG 3821 uses_allocator_construction_args should have overload for pair-like (#66939)
This change addresses LWG 3821 and LWG 3677.

- make `std::pair`'s constructor no longer takes `subrange`
- `uses_allocator_construction_args` constraint changes w.r.t to
`pair-like` types
- `uses_allocator_construction_args` constraints checks
`is-pair-like<remove_cv_t<T>>`
2023-10-09 13:50:27 +01:00
Nikolas Klauser
aade74675c [libc++][PSTL] Overhaul exceptions handling
This makes exception handling a lot simpler, since we don't have to convert any exceptions this way. Is also properly handles all the user-thrown exceptions.

Reviewed By: ldionne, #libc

Spies: arichardson, mstorsjo, libcxx-commits

Differential Revision: https://reviews.llvm.org/D154238
2023-10-06 23:01:30 +02:00
Nikolas Klauser
a9138cdb36 [libc++] Optimize ranges::count for __bit_iterators
```
---------------------------------------------------------------
Benchmark                                    old            new
---------------------------------------------------------------
bm_vector_bool_count/1                   1.92 ns        1.92 ns
bm_vector_bool_count/2                   1.92 ns        1.92 ns
bm_vector_bool_count/3                   1.92 ns        1.92 ns
bm_vector_bool_count/4                   1.92 ns        1.92 ns
bm_vector_bool_count/5                   1.92 ns        1.92 ns
bm_vector_bool_count/6                   1.92 ns        1.92 ns
bm_vector_bool_count/7                   1.92 ns        1.92 ns
bm_vector_bool_count/8                   1.92 ns        1.92 ns
bm_vector_bool_count/16                  1.92 ns        1.92 ns
bm_vector_bool_count/64                  2.24 ns        2.25 ns
bm_vector_bool_count/512                 3.19 ns        3.20 ns
bm_vector_bool_count/4096                14.1 ns        12.3 ns
bm_vector_bool_count/32768               84.0 ns        83.6 ns
bm_vector_bool_count/262144               664 ns         661 ns
bm_vector_bool_count/1048576             2623 ns        2628 ns
bm_vector_bool_ranges_count/1            1.07 ns        1.92 ns
bm_vector_bool_ranges_count/2            1.65 ns        1.92 ns
bm_vector_bool_ranges_count/3            2.27 ns        1.92 ns
bm_vector_bool_ranges_count/4            2.68 ns        1.92 ns
bm_vector_bool_ranges_count/5            3.33 ns        1.92 ns
bm_vector_bool_ranges_count/6            3.99 ns        1.92 ns
bm_vector_bool_ranges_count/7            4.67 ns        1.92 ns
bm_vector_bool_ranges_count/8            5.19 ns        1.92 ns
bm_vector_bool_ranges_count/16           11.1 ns        1.92 ns
bm_vector_bool_ranges_count/64           52.2 ns        2.24 ns
bm_vector_bool_ranges_count/512           452 ns        3.20 ns
bm_vector_bool_ranges_count/4096         3577 ns        12.1 ns
bm_vector_bool_ranges_count/32768       28725 ns        83.7 ns
bm_vector_bool_ranges_count/262144     229676 ns         662 ns
bm_vector_bool_ranges_count/1048576    905574 ns        2625 ns
```

Reviewed By: #libc, ldionne

Spies: arichardson, ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D156956
2023-10-06 22:58:41 +02:00
Krasimir Georgiev
b935882bdc Revert "[libc++] Remove UB in list, forward_list and __hash_table"
This reverts commit 0687e4d9f3.
Causes LLDB failures: https://reviews.llvm.org/D101206#4653253
2023-10-06 10:09:36 +00:00
philnik777
ff843c00ce
[libc++] Bump the clang version the clang-tidy checks are based on (#68318) 2023-10-06 11:43:33 +02:00
Nikolas Klauser
0d7947b08c [libc++] Implement P2614R2 (Deprecate numeric_limits::has_denorm)
Reviewed By: #libc, ldionne

Spies: ldionne, Mordante, libcxx-commits

Differential Revision: https://reviews.llvm.org/D155411
2023-10-06 11:30:55 +02:00
Nikolas Klauser
c66d0b019a [libc++] Recategorize additional instantiations in the dylib as availability macros
Adding additional instantiations to the dylib isn't actually an ABI break as long as programs targeting an older dylib don't start to depend on them. Making additional instantiations a matter of availability allows us to add them without an ABI break.

Reviewed By: #libc, ldionne, Mordante

Spies: arichardson, ldionne, Mordante, libcxx-commits

Differential Revision: https://reviews.llvm.org/D154796
2023-10-06 11:21:05 +02:00
Anatolii Malibroda
dc129d6f71
[libc++] Add std::fpclassify overloads for floating-point. (#67913)
Standard says that implementation of math functions that have
floating-point-type parameter should provide an "overload for each
cv-unqualified floating-point type".
2023-10-05 21:18:02 +02:00
Christopher Di Bella
48c805bafd
[libcxx] replaces SFINAE with requires-expressions in bind_front and bind_back (#68249)
The diagnostics for `enable_if_t` are extremely opaque:

```
error: no matching function for call to 'bind_front'
note: candidate template ignored: requirement 'integral_constant<bool, false>::value' was not satisfied
```

Using requires-expressions gives us a little more context:

```
error: no matching function for call to 'bind_front'
note: candidate template ignored: constraints not satisfied
note: because 'is_constructible_v<decay_t<T &>, T &>' evaluated to false
```

Pull request: #68249
2023-10-05 10:32:08 -07:00
Louis Dionne
0687e4d9f3 [libc++] Remove UB in list, forward_list and __hash_table
This patch removes undefined behavior in list and forward_list and __hash_table
caused by improperly beginning and ending the lifetime of the various node
classes. It allows removing the _LIBCPP_STANDALONE_DEBUG macro from
these node types since we now properly begin and end their lifetime,
meaning that we won't trip up constructor homing.

See https://reviews.llvm.org/D98750 for more information on what prompted
this patch.

Differential Revision: https://reviews.llvm.org/D101206

Co-authored-by: Amy Kwan <amy.kwan1@ibm.com>
2023-10-05 13:02:00 -04:00
Ilya Biryukov
f722db02d3
[libc++] Use correct size for deallocation of arrays in shared_ptr (#68233)
Fixes #68051.

Current implementation passes the number of `_AlignedStorage` objects
when it calls to `allocate` and the number of **bytes** on `deallocate`.
This only applies to allocations that allocate control block and the
storage together, i.e. `make_shared` and `allocate_shared`.

Found by ASan under Clang combined with `-fsized-deallocation`.
2023-10-05 15:27:58 +02:00
Marek Kurdej
d2cb198f25 [libc++] Make future_error constructor standard-compliant
This patch removes the non compliant constructor of std::future_error
and adds the standards compliant constructor in C++17 instead.

Note that we can't support the constructor as an extension in all
standard modes because it uses delegating constructors, which require
C++11. We could in theory support the constructor as an extension in
C++11 and C++14 only, however I believe it is acceptable not to do that
since I expect the breakage from this patch will be minimal.

If it turns out that more code than we expect is broken by this, we can
reconsider that decision.

This was found during D99515.

Differential Revision: https://reviews.llvm.org/D99567
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-10-05 09:11:49 -04:00
Louis Dionne
b09551f074
[libc++] Fix implementation of iota_view::size (#67819)
We were incorrectly deducing the return type of size() because we were
not using ternary operators in the implementation (as the spec says).
Instead of deducing the common type of the expressions in the spec, we
would deduce potentially different return types and fail to compile.

Fixes #67551
2023-10-04 18:34:43 -04:00
Louis Dionne
04b45450ac
[libc++] Explicitly pass execution policies to _LIBCPP_PSTL_CUSTOMIZATION_POINT (#68238)
The _LIBCPP_PSTL_CUSTOMIZATION_POINT macro was assuming that the policy
was called _RawPolicy and referencing it by name. It happened to always
work but this was definitely accidental and an oversight in the original
implementation. This patch fixes that by passing the policy to the macro
explicitly. Noticed while reviewing #66968.
2023-10-04 18:12:39 -04:00
Alexander Richardson
e599422954
[runtimes] Fix parsing of LIB{CXX,CXXABI,UNWIND}_TEST_PARAMS (#67691)
Since 78d649a417 the recommended way to
pass an executor is to use the _TEST_PARAMS variable, which means we now
pass more complicated value (including ones that may contain multiple
`=`) as part of this variable. However, the `REGEX REPLACE` being used
has greedy matches so everything up to the last = becomes part of the
variable name which results in invalid syntax in the generated lit
config file.

This was noticed due to builder failures for those using the
CrossWinToARMLinux.cmake cache file.

---------

Co-authored-by: Vladimir Vereschaka <vvereschaka@accesssoftek.com>
2023-10-04 18:11:37 -04:00
Louis Dionne
d32edcb86d [libc++][NFC] Fix broken formatting in comment 2023-10-04 16:38:30 -04:00
Louis Dionne
7a73a2c241 [libc++][NFC] Document missing __pstl_merge function in PSTL basis operations 2023-10-04 13:39:34 -04:00
Louis Dionne
2848125c6c
[libc++] Remove dead code in legacy_debug_handler.cpp (#68155)
We removed all traces of the legacy debug mode a while back, but we
forgot to remove the actual `.cpp` file that implemented the legacy
debug handler. The file is not referenced from anywhere so this is
effectively a NFC.
2023-10-04 11:38:35 -04:00
Amirreza Ashouri
b6f6fe98a8
[libc++] Remove unused defaulted template arg from __rewrap_range. (#67733)
Template argument `_Unwrapped` is always deduced from the type of
`_Unwrapped __iter`.
2023-10-04 11:23:36 +02:00
Caslyn Tonelli
a6cdbba4d6
[libcxx][test] Amend XFAIL directive in no_unique_address tests (#67849)
This PR amends the `XFAIL` directive to clang < 18 in
no_unique_address.compile.pass.cpp tests.

Since PR 67199 implements the [[msvc::no_unique_address]] attribute,
these tests pass in a windows-x64 build against ToT clang-cl:

```
********************
Unexpectedly Passed Tests (3):
llvm-libc++-static-clangcl.cfg.in :: libcxx/ranges/range.adaptors/range.lazy.split/no_unique_address.compile.pass.cpp
llvm-libc++-static-clangcl.cfg.in :: libcxx/ranges/range.adaptors/range.split/no_unique_address.compile.pass.cpp
llvm-libc++-static-clangcl.cfg.in :: libcxx/ranges/range.factories/range.istream.view/no_unique_address.compile.pass.cpp
```

---------

Co-authored-by: Caslyn Tonelli <caslyn@google.com>
2023-10-03 17:16:10 -07:00
Mark de Wever
bee2ae8677 [NFC][libc++][test] ' ,c++17' -> ', c++17'. 2023-10-03 20:34:27 +02:00
Will Hawkins
08e4ccbff8
[libc++][ranges][NFC] Mark ranges::slide_view in progress (#68056)
Mark `ranges::slide_view` implementation as in progress.
2023-10-03 14:05:25 -04:00
Louis Dionne
3a44223711 [libc++] Fix test failing on macOS with modules enabled 2023-10-03 13:54:04 -04:00
Amirreza Ashouri
b861457c90
[libc++] Fix a segfault in weak_ptr(const weak_ptr<Y>&) (#67956)
Fixes https://github.com/llvm/llvm-project/issues/40459
2023-10-02 17:52:34 -04:00
Martijn Vels
6fe4e033f0 [libc++] Optimize vector push_back to avoid continuous load and store of end pointer
Credits: this change is based on analysis and a proof of concept by
gerbens@google.com.

Before, the compiler loses track of end as 'this' and other references
possibly escape beyond the compiler's scope. This can be see in the
generated assembly:

     16.28 │200c80:   mov     %r15d,(%rax)
     60.87 │200c83:   add     $0x4,%rax
           │200c87:   mov     %rax,-0x38(%rbp)
      0.03 │200c8b: → jmpq    200d4e
      ...
      ...
      1.69 │200d4e:   cmp     %r15d,%r12d
           │200d51: → je      200c40
     16.34 │200d57:   inc     %r15d
      0.05 │200d5a:   mov     -0x38(%rbp),%rax
      3.27 │200d5e:   mov     -0x30(%rbp),%r13
      1.47 │200d62:   cmp     %r13,%rax
           │200d65: → jne     200c80

We fix this by always explicitly storing the loaded local and pointer
back at the end of push back. This generates some slight source 'noise',
but creates nice and compact fast path code, i.e.:

     32.64 │200760:   mov    %r14d,(%r12)
      9.97 │200764:   add    $0x4,%r12
      6.97 │200768:   mov    %r12,-0x38(%rbp)
     32.17 │20076c:   add    $0x1,%r14d
      2.36 │200770:   cmp    %r14d,%ebx
           │200773: → je     200730
      8.98 │200775:   mov    -0x30(%rbp),%r13
      6.75 │200779:   cmp    %r13,%r12
           │20077c: → jne    200760

Now there is a single store for the push_back value (as before), and a
single store for the end without a reload (dependency).

For fully local vectors, (i.e., not referenced elsewhere), the capacity
load and store inside the loop could also be removed, but this requires
more substantial refactoring inside vector.

Differential Revision: https://reviews.llvm.org/D80588
2023-10-02 09:12:37 -04:00
ZhangYin
cf31d0eca8
[libcxx] <experimental/simd> Add _LIBCPP_HIDE_FROM_ABI to internal br… (#66977)
…oadcast functions
2023-09-29 16:32:54 +02:00
Konstantin Varlamov
dd788af74a
Reapply "[libc++][ranges] Add benchmarks for the from_range constructors of vector and deque." (#67753)
This reverts commit 10edd5d943 and guards
against older versions of GCC to work around the problem.
2023-09-29 10:27:20 -04:00
Hui
4fa812bb52 [libc++] Implement std::condition_variable_any::wait[_for/until] overloads that take stop_token
- This is section 32.6.4 of P0660R10
- https://eel.is/c++draft/thread.condvarany.intwait

Differential Revision: https://reviews.llvm.org/D153441
2023-09-29 13:50:16 +01:00
Louis Dionne
6b03d8aa94 [libc++][NFC] Remove spurious check for is-constant-evaluated
This NFC change was reverted as part of 880fa7faa9, but the change is
really good regardless of the associated Clang patch.
2023-09-28 14:21:35 -04:00
Louis Dionne
9bb9ec380a
[libc++][NFC] Simplify checks for static assertions in .verify.cpp tests (#67559)
We don't neeed to handle both spellings anymore since we don't support
Clang 15 anymore.
2023-09-28 09:07:08 -04:00
Louis Dionne
000940e296
[libc++] Refactor the tests for [iterator.range] (#67496)
The tests were a bit of a mess -- the testing coverage wasn't bad but it
was extremely difficult to see what was being tested and where. I split
up the tests to make them easier to audit for completeness and did such
an audit, adding a few missing tests (e.g. the conditional noexcept-ness
of std::cbegin and std::cend). I also audited the synopsis and adjusted
it where it needed to be adjusted.

This patch is in preparation of fixing #67471.
2023-09-28 09:04:07 -04:00
Louis Dionne
e331bbb346
[libc++] Add regression test for #67449 (#67590)
Even though the underlying issue was fixed in #65177 when we made
std::pointer_traits SFINAE-friendly, it is worth adding a regression
test since it's so easy to do.
2023-09-28 09:03:27 -04:00
Sam McCall
880fa7faa9 Revert "[clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated"
This reverts commit 491b2810fb.

This change broke valid code and generated incorrect diagnostics, see
https://reviews.llvm.org/D155064
2023-09-27 18:58:01 +02:00
Daniel Thornburgh
07d08f4eb4
[libc++] Don't add reference to system_category when exceptions disabled (#67504)
This fixes a size regression in Fuchsia when building a static libc++
multilib with exceptions disabled. Referring to `system_category` in
`__throw_system_error` brings in a relatively large amount of additional
exception classes into the link without substantially improving the
error message.
2023-09-27 09:09:43 -04:00
Louis Dionne
6e1dcc9335 [libc++] Refactor string unit tests to ease addition of new allocators
While doing this, I also found a few tests that were either clearly
incorrect (e.g. testing the wrong function) or that lacked basic test
coverage like testing std::string itself (e.g. the test was only checking
std::basic_string with a custom allocator). In these cases, I did a few
conservative drive-by changes.

Differential Revision: https://reviews.llvm.org/D140550
Co-authored-by: Brendan Emery <brendan.emery@esrlabs.com>
2023-09-27 09:01:58 -04:00
Martin Storsjö
27546a65d4 [libcxx] [test] Use -fms-runtime-lib= for picking the CRT to use
This is a more correct way of linking against a specific runtime
library with the GCC-like clang frontend.

This avoids having to pass -D_DEBUG (and passes flags like -D_DLL,
which we should be passing if linking against the dynamic CRT).

When -fms-runtime-lib= is specified, each compiled object file gets
embedded directives instructing the linker about what CRT it should
link against. The -nostdlib we pass to the compiler driver only
inhibits the libs that the compiler driver passes to the linker
command.

Thus, this also avoids having to specify -lmsvcrt, -lmsvcrtd,
-llibcmt or -llibcmtd, and -loldnames.

Based on a patch by Andrew Ng.

The -fms-runtime-lib= option was added in Clang 16, but libcxx
now has dropped support for Clang 15.

Differential Revision: https://reviews.llvm.org/D155562
2023-09-27 13:52:13 +03:00
Takuya Shimizu
491b2810fb [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated
This patch makes clang diagnose extensive cases of consteval if and is_constant_evaluated usage that are tautologically true or false.
This introduces a new IsRuntimeEvaluated boolean flag to Sema::ExpressionEvaluationContextRecord that means the immediate appearance of if consteval or is_constant_evaluated are tautologically false(e.g. inside if !consteval {} block or non-constexpr-qualified function definition body)
This patch also pushes new expression evaluation context when parsing the condition of if constexpr and initializer of constexpr variables so that Sema can be aware that the use of consteval if and is_consteval are tautologically true in if constexpr condition and constexpr variable initializers.
BEFORE this patch, the warning for is_constant_evaluated was emitted from constant evaluator. This patch moves the warning logic to Sema in order to diagnose tautological use of is_constant_evaluated in the same way as consteval if.

This patch separates initializer evaluation context from InitializerScopeRAII.
This fixes a bug that was happening when user takes address of function address in initializers of non-local variables.

Fixes https://github.com/llvm/llvm-project/issues/43760
Fixes https://github.com/llvm/llvm-project/issues/51567

Reviewed By: cor3ntin, ldionne
Differential Revision: https://reviews.llvm.org/D155064
2023-09-27 09:26:06 +09:00
Alexander Richardson
78d649a417
[libc++][lit] Allow overriding the executor for tests (#66545)
This is useful when trying to run multiple tests with different
arguments to the executor script. This is needed in my case since I
do not know the correct ssh connection arguments when building libc++.
The testing script I have spawns multiple QEMU instances that listen on
a given port on localhost and runs lit with the --num-shards/--run-shard
argument. In order to connect each shard to the right QEMU instances I
need to customize the arguments passed to ssh.py (--extra-ssh-args and
--extra-scp-args) but can't do this at configure time since the target
port is only known when running the tests but not when calling CMake.
This change allows me to pass `executor=ssh.py <args>` to lit once I
know
the right hostname/port for running the tests.

This also deprecates the `LIB{CXX,CXXABI,UNWIND}_EXECUTOR` CMake
variable
as the same can be achieved by adding `executor=...` to the
`LIB{CXX,CXXABI,UNWIND}_TEST_PARAMS` variable.
2023-09-26 15:19:31 +01:00
Louis Dionne
0106ae3cce [libc++] Use _Lazy in tuple constructors
This reduces the number of instantiations and also avoid blowing up
past the fold-expression limit of Clang.

This is NOT a general statement that we should strive to stay within
Clang's (sometimes way too small) limits, however in this case the
change will reduce the number of template instantiations while at the
same time doing that, which is good.

Differential Revision: https://reviews.llvm.org/D132509
2023-09-26 09:24:05 -04:00
Louis Dionne
580d26ae46
[libc++] Remove the CI job testing Clang 15 (#66406)
Since LLVM 17 has been branched and is on the verge of being released,
we can drop the CI job that tests against Clang 15. I think the number
of cherry-picks to `release/17.x` will be a lot smaller now, so keeping
a Clang 15 job around for that purpose seems unnecessary.

As a fly-by, this patch also removes some Clang 15 workarounds and test
suite annotations as we usually do. It also removes some slightly older
gcc test suite annotations that were missed.
2023-09-25 17:55:59 -04:00
Louis Dionne
4ca00a5686
[libc++] Remove the libc++ specific clang-format job (#67344)
Now that we have a LLVM-wide GitHub action, it doesn't make sense to
have a custom job for libc++ in our BuildKite CI pipeline. This only creates
confusion as to which CI job should be acted upon.
2023-09-25 17:24:01 -04:00
Louis Dionne
ba94646c76 [libc++][NFC] Qualify mention of va_list with std:: in documentation 2023-09-25 13:40:24 -04:00
Louis Dionne
273ece4640 [libc++] Add missing files to ignore_format.txt
The new formatting job enabled with GitHub actions checks for mis-formatted
files everywhere, not only in the select subdirectories we checked previously.
As a result, we'd get spurious clang-format failure reports whenever a
test was modified. This patch fixes that.
2023-09-25 12:09:35 -04:00
Louis Dionne
029c9c3176
[libc++] Refactor tests for std::pointer_traits (#66645)
After landing the implementation of LWG3545, I realized that the tests
for std::pointer_traits had become a bit disorganized. This patch is a
NFC that refactors the tests:
- Move compile-only tests to `.compile.pass.cpp` tests
- Re-create the clear distinction between tests for the std::pointer_traits base tempate and for the T* specialization.
- De-duplicate test coverage -- we had a bunch of things that were tested in duplication.
2023-09-25 11:15:33 -04:00
Aaron Ballman
10edd5d943 Revert "[libc++][ranges] Add benchmarks for the from_range constructors of vector and deque."
This reverts commit 390ac82317.

It broke the sphinx publish bots for our documentation:
https://lab.llvm.org/buildbot/#/builders/242/builds/1130

because that machine has GCC 9.4.0 which does not know about C++23
2023-09-25 10:40:51 -04:00
Louis Dionne
21f8bc25ad
[libc++] Make sure we forward stdin through executors (#67064)
This allows running tests like the ones for std::cin even on SSH
executors. This was originally reported as
https://github.com/llvm/llvm-project/pull/66842#issuecomment-1728701639.
2023-09-25 09:50:07 -04:00
Louis Dionne
5f2da9c80d
[runtimes] Bump the supported AppleClang version to AppleClang 15 (#67065)
AppleClang 15 was released on September 18th and is now stable. Per our
policy, we're bumping the supported AppleClang compiler to the latest
release. This allows cleaning up the test suite, but most importantly
unblocking various other patches that are blocked on bumping the
compiler requirements.
2023-09-25 09:46:01 -04:00
Zhangyin
81a3828dbd [libcxx] <experimental/simd> excluded long double for 32-bits x86 temporarily
Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D159514
2023-09-25 10:27:56 +08:00
James Y Knight
b0e19cfb62
[libcxx] Don't deallocate non-pointer data in string assignment. (#67200)
Previously, assignment to a std::basic_string type with a _custom_
allocator could under certain conditions attempt to interpret part of
the target string's "short" string-content as if it was a "long" data
pointer, and attempt to deallocate a garbage value.

This is a serious bug, but code in which it might happen is rare. It
required:

1. the basic_string must be using a custom allocator type which sets the
propagate_on_container_copy_assignment trait to true (thus, it does not
affect the default allocator, nor most custom allocators).
2. the allocator for the target string must compare not equal to the
allocator for the source string (many allocators always compare equal).
3. the source of the copy must currently contain a "long" string, and
the assignment-target must currently contain a "short" string.

Finally, the issue would've typically been innocuous when the bytes
misinterpreted as a pointer were all zero, as deallocating a nullptr is
typically a no-op. This is why existing test cases did not exhibit an
issue: they were all zero-length strings, which do not have data in the
bytes interpreted as a pointer.
2023-09-24 09:12:57 -04:00
Louis Dionne
d217aeb0b7
[runtimes] Simplify testing configurations on GCC by using -nostdlib++ (#67021)
Since GCC now supports -nostdlib++, we can remove some complexity in the
test configurations and do the same as Clang. However, we can't fully
remove the GCC test configuration for libc++ because we apparently need
to explicitly link against libm for some tests to work.
2023-09-21 17:21:24 -04:00
Louis Dionne
0065d75099 [runtimes][NFC] Remove old Lit annotations for gcc-12 and clang-14
We don't support these compilers anymore so these Lit annotations were
never used.
2023-09-21 17:13:31 -04:00
Louis Dionne
2ab31b6bab [libc++] When run in verbose mode, ssh.py should print to stderr, not stdout
Otherwise this can mess up the test results which inspect stdout.
2023-09-21 16:37:46 -04:00
Louis Dionne
1ce70139ff [libc++] Simplify ssh.py by not passing args everywhere 2023-09-21 16:37:46 -04:00
Louis Dionne
d2b71c7a1a [libc++] Fix how we run codesign in the test suite when --codesign_identity is provided 2023-09-21 13:34:58 -04:00
Louis Dionne
77d8ce5bb8 [libc++] Add a --verbose option to ssh.py to help debug failures 2023-09-21 13:34:58 -04:00
Louis Dionne
7fcbb64fca [runtimes] Workaround a subtle linker issue on macOS in the CI 2023-09-21 11:29:45 -04:00
Jake Egan
1abff08e9e
[AIX] cxx_std_23 is currently not a known feature to ibm-clang (#66952)
Temporary workaround for the following CMake error:
```
CMake Error in /llvm/libcxx/benchmarks/CMakeLists.txt:
The compiler feature "cxx_std_23" is not known to CXX compiler
"IBMClang"
```
2023-09-21 10:34:07 -04:00
Louis Dionne
24161bcc44 [libc++] Move a few XFAILs to UNSUPPORTED for consistency
The wide stream tests should be marked as `UNSUPPORTED: no-wide-characters`,
not XFAIL.
2023-09-21 07:42:23 -04:00
Louis Dionne
354c99bb5f [libc++] Temporarily disable std::cin tests on Windows -> Linux cross compiler
To get the bot back to green as we figure out how to handle piping data
into a test running behind a SSH executor.
2023-09-21 07:39:58 -04:00
Igor Zhukov
910b76a002 [libc++] Implement LWG-3655: The INVOKE operation and union types
https://cplusplus.github.io/LWG/issue3655

Differential Revision: https://reviews.llvm.org/D144645
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-09-21 05:23:41 -04:00
Louis Dionne
8bbcc6d548
[libc++] Add test coverage for unordered containers comparison (#66692)
This patch is a melting pot of changes picked up from
https://llvm.org/D61878. It adds a few tests checking corner cases of
unordered containers comparison and adds benchmarks for a few
unordered_set operations.
2023-09-21 05:11:49 -04:00
Louis Dionne
e46de4e54f
[runtimes] Fix link order of system librarires on Apple platforms (#66940)
On Apple platforms, we always support the -nostdlib++ flag. Hence, it is
not necessary to manually link against system libraries. In fact, doing
so causes us to link against libSystem explicitly, which messes up with
the order of libraries we should use. Indeed:

   Before patch, using the system unwinder (LIBCXXABI_USE_LLVM_UNWINDER = OFF)
   ===========================================================================
   $ otool -L lib/{libc++.1.dylib,libc++abi.1.dylib,libunwind.1.dylib}
   lib/libc++.1.dylib:
         @rpath/libc++.1.dylib
         /usr/lib/libSystem.B.dylib
         @rpath/libc++abi.1.dylib
   lib/libc++abi.1.dylib:
         @rpath/libc++abi.1.dylib
         /usr/lib/libSystem.B.dylib
   lib/libunwind.1.dylib:
         @rpath/libunwind.1.dylib
         /usr/lib/libSystem.B.dylib

   After patch, using the system unwinder (LIBCXXABI_USE_LLVM_UNWINDER = OFF)
   ===========================================================================
   $ otool -L lib/{libc++.1.dylib,libc++abi.1.dylib,libunwind.1.dylib}
   lib/libc++.1.dylib:
         @rpath/libc++.1.dylib
         @rpath/libc++abi.1.dylib
         /usr/lib/libSystem.B.dylib
   lib/libc++abi.1.dylib:
         @rpath/libc++abi.1.dylib
         /usr/lib/libSystem.B.dylib
   lib/libunwind.1.dylib:
         @rpath/libunwind.1.dylib
         /usr/lib/libSystem.B.dylib

   Before patch, with the LLVM unwinder (LIBCXXABI_USE_LLVM_UNWINDER = ON)
   =======================================================================
   $ otool -L lib/{libc++.1.dylib,libc++abi.1.dylib,libunwind.1.dylib}
   lib/libc++.1.dylib:
         @rpath/libc++.1.dylib
         /usr/lib/libSystem.B.dylib
         @rpath/libc++abi.1.dylib
         @rpath/libunwind.1.dylib
   lib/libc++abi.1.dylib:
         @rpath/libc++abi.1.dylib
         /usr/lib/libSystem.B.dylib
         @rpath/libunwind.1.dylib
   lib/libunwind.1.dylib:
         @rpath/libunwind.1.dylib
         /usr/lib/libSystem.B.dylib

   After patch, with the LLVM unwinder (LIBCXXABI_USE_LLVM_UNWINDER = ON)
   ======================================================================
   $ otool -L lib/{libc++.1.dylib,libc++abi.1.dylib,libunwind.1.dylib}
   lib/libc++.1.dylib:
         @rpath/libc++.1.dylib
         @rpath/libc++abi.1.dylib
         @rpath/libunwind.1.dylib
         /usr/lib/libSystem.B.dylib
   lib/libc++abi.1.dylib:
         @rpath/libc++abi.1.dylib
         @rpath/libunwind.1.dylib
         /usr/lib/libSystem.B.dylib
   lib/libunwind.1.dylib:
         @rpath/libunwind.1.dylib
         /usr/lib/libSystem.B.dylib

As we can see, libSystem appears before the just-built libraries before
the patch, which causes the libunwind.dylib bundled in libSystem.dylib
to be used instead of the just-built libunwind.dylib.

We didn't notice the issue until recently when I tried to update the
macOS CI builders to macOS 13.5, where it is necessary to use the right
libunwind library (the exact reason still needs to be investigated).
2023-09-21 05:10:05 -04:00
Louis Dionne
e3b166229f [libc++] Sort available features before printing them
This makes it easier to compare the features available in two adjacent
runs of lit.
2023-09-20 09:53:07 -04:00
Louis Dionne
257eb74524
[libc++] Simplify how the global stream tests are written (#66842)
Instead of relying on Bash, use the builtin Lit commands whenever
possible. The motivation is to stop running %t.exe behind Bash, which
breaks on macOS 13.5 with SIP enabled because DYLD_LIBRARY_PATH isn't
forwarded to the underlying process when running through a protected
process.

For more details, see [1].

[1]: https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html
2023-09-20 09:33:16 -04:00
Nikolas Klauser
2b7f11a652 [libc++] Warn if an unsupported compiler is used
This makes it obvious that libc++ is used in an unsupported configuration,
and the compiler probably has to be updated. It often happens that people
try to use libc++ and don't realize that their compiler is too old.

Differential Revision: https://reviews.llvm.org/D158214
2023-09-19 23:45:49 -04:00
Louis Dionne
e7a7a16901
[libc++] Fix __threading_support when used with C11 threading (#66780)
Since we are defining these typedefs inside namespace std, we need to
refer to ::once_flag (the C Standard Library version). Otherwise
'once_flag' refers to 'std::once_flag', and that's not something we can
pass to the C Standard Library '::call_once()' function later on.
2023-09-19 18:15:26 -04:00
Daniel McIntosh
be8c2df2b1 [libc++][NFC] Clean up std::__call_once
__call_once is large and cluttered with #ifdef preprocessor guards. This
cleans it up a bit by using an exception guard instead of try-catch.

Differential Revision: https://reviews.llvm.org/D112319
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-09-19 16:17:20 -04:00
Joel E. Denny
f223022a4c [lit] Improve test output from lit's internal shell
This patch and D154984 were discussed in
<https://discourse.llvm.org/t/rfc-improving-lits-debug-output/72839>.

Motivation
----------

D154984 removes the "Script:" section that lit prints along with a
test's output, and it makes -v and -a imply -vv.  For example, after
D154984, the "Script:" section below is never shown, but -v is enough
to produce the execution trace following it:

```
 Script:
 --
 : 'RUN: at line 1'; echo hello | FileCheck bogus.txt && echo success
 --
 Exit Code: 2

 Command Output (stdout):
 --
 $ ":" "RUN: at line 1"
 $ "echo" "hello"
 # command output:
 hello

 $ "FileCheck" "bogus.txt"
 # command stderr:
 Could not open check file 'bogus.txt': No such file or directory

 error: command failed with exit status: 2

 --
```

In the D154984 review, some reviewers point out that they have been
using the "Script:" section for copying and pasting a test's shell
commands to a terminal window.  The shell commands as printed in the
execution trace can be harder to copy and paste for the following
reasons:

- They drop redirections and break apart RUN lines at `&&`, `|`, etc.
- They add `$` at the start of every command, which makes it hard to
  copy and paste multiple commands in bulk.
- Command stdout, stderr, etc. are interleaved with the commands and
  are not clearly delineated.
- They don't always use proper shell quoting.  Instead, they blindly
  enclose all command-line arguments in double quotes.

Changes
-------

D154984 plus this patch converts the above example into:

```
 Exit Code: 2

 Command Output (stdout):
 --
 # RUN: at line 1
 echo hello | FileCheck bogus-file.txt && echo success
 # executed command: echo hello
 # .---command stdout------------
 # | hello
 # `-----------------------------
 # executed command: FileCheck bogus-file.txt
 # .---command stderr------------
 # | Could not open check file 'bogus-file.txt': No such file or directory
 # `-----------------------------
 # error: command failed with exit status: 2

 --
```

Thus, this patch addresses the above issues as follows:

- The entire execution trace can be copied and pasted in bulk to a
  terminal for correct execution of the RUN lines, which are printed
  intact as they appeared in the original RUN lines except lit
  substitutions are expanded.  Everything else in the execution trace
  appears in shell comments so it has no effect in a terminal.
- Each of the RUN line's commands is repeated (in shell comments) as
  it executes to show (1) that the command actually executed (e.g.,
  `echo success` above didn't) and (2) what stdout, stderr, non-zero
  exit status, and output files are associated with the command, if
  any.  Shell quoting in the command is now correct and minimal but is
  not necessarily the original shell quoting from the RUN line.
- The start and end of the contents of stdout, stderr, or an output
  file is now delineated clearly in the trace.

To help produce some of the above output, this patch extends lit's
internal shell with a built-in `@echo` command.  It's like `echo`
except lit suppresses the normal execution trace for `@echo` and just
prints its stdout directly.  For now, `@echo` isn't documented for use
in lit tests.

Without this patch, libcxx's custom lit test format tries to parse the
stdout from `lit.TestRunner.executeScriptInternal` (which runs lit's
internal shell) to extract the stdout and stderr produced by shell
commands, and that parse no longer works after the above changes.
This patch makes a small adjustment to
`lit.TestRunner.executeScriptInternal` so libcxx can just request
stdout and stderr without an execution trace.

(As a minor drive-by fix that came up in testing: lit's internal `not`
command now always produces a numeric exit status and never `True`.)

Caveat
------

This patch only makes the above changes for lit's internal shell.  In
most cases, we do not know how to force external shells (e.g., bash,
sh, window's `cmd`) to produce execution traces in the manner we want.

To configure a test suite to use lit's internal shell (which is
usually better for test portability than external shells anyway), add
this to the test suite's `lit.cfg` or other configuration file:

```
config.test_format = lit.formats.ShTest(execute_external=False)
```

Reviewed By: MaskRay, awarzynski

Differential Revision: https://reviews.llvm.org/D156954
2023-09-19 12:38:38 -04:00
Zijun Zhao
0218ea4aaa [libc++] Implement ranges::ends_with
Reviewed By: #libc, var-const

Differential Revision: https://reviews.llvm.org/D150831
2023-09-18 11:56:10 -07:00
Hui
054f9c55c6
[libc++] Fix std::pair's pair-like constructor's incorrect assumption (#66585)
The helper function `__pair_like_explicit_wknd` is only SFINAE-ed with
`tuple_size<remove_cvref_t<_PairLike>>::value == 2`, but its function
body assumes `std::get` being valid.

Fixes #65620
2023-09-18 14:01:19 -04:00
Alexander Richardson
14882d6b74
[libc++][lit] Atomically update the persistent cache (#66538)
When running multiple shards in parallel, one shard might write to the
cache while another one is reading this cache. Instead of updating the
file in place, write to a temporary file and swap the cache file using
os.replace(). This is an atomic operation and means shards will either
see the old state or the new one.
2023-09-18 12:08:24 -04:00
zhijian
c24a422aa3 [libc++][CI][AIX] modify the equivalence classes of regex_match for locale "cs_CZ.ISO8859-2"
Reviewers: David Tenty, Mark de Wever
Differential Revision: https://reviews.llvm.org/D126407
2023-09-18 11:03:06 -04:00
Amirreza Ashouri
aa8601dc6d
[libc++] [string_view] Remove operators made redundant by C++20 (#66206)
Thanks to Giuseppe D'Angelo for pointing this out on the cpplang Slack!

The example implementation in https://eel.is/c++draft/string.view.comparison#example-1
was necessary when it was written, in C++17, but in C++20 we don't need that
complexity anymore, because of the reversed candidates that are
synthesized by the compiler.
2023-09-18 10:30:44 -04:00
Louis Dionne
d4d8f214a3
[libc++] Simplify how we select modules flavors in the test suite (#66385)
This gets rid of the separate parameter enable_modules_lsv in favor of
adding a named option to the enable_modules parameter. The patch also
removes the getModuleFlag helper, which was just a really complicated
way of hardcoding "none".
2023-09-18 09:37:18 -04:00
Daniel Cheng
078651b6de
[libc++] Implement LWG3545: std::pointer_traits should be SFINAE-friendly. (#65177)
See https://wg21.link/LWG3545 for background and details.

Differential Revision: https://reviews.llvm.org/D158922
2023-09-18 08:46:59 -04:00
Hui
4a1fe09b18 [libc++] Fix potentially flaky test joinable.pass.cpp
This is a follow up of
https://reviews.llvm.org/D151559

Where one test point is potentially falky due to a race condition.
2023-09-16 23:07:46 +01:00
Hui
695138ca84 [libc++] implement std::jthread 2023-09-16 19:54:19 +01:00
Louis Dionne
b64bf895e5
[libc++] Improve the verbosity of configuration errors when a compiler flag is not supported (#66379)
If an assertion fails during the configuration of the test suite because
the compiler doesn't support a flag (or the compiler configuration is
borked entirely), we will now print additional context to help debug the
issue instead of just saying "The compiler doesn't support the flag" and
bailing.
2023-09-15 10:15:50 -04:00
Louis Dionne
320d4c90fa
[libc++] Update Apple CI jobs to run the C++23 configuration (#66367)
We were running the test suite in C++20 mode, but we should really be
tracking the latest supported version. We can't do C++26 because the
latest stable AppleClang doesn't support it yet.
2023-09-15 10:15:15 -04:00
Louis Dionne
fdf91c768e
[libc++][NFC] Introduce named states in std::call_once (#66289)
This idea is extracted from https://reviews.llvm.org/D112319. It makes
the code easier to read but doesn't otherwise change any functionality.
2023-09-15 10:14:13 -04:00
Louis Dionne
69875d59bc
[libc++] Refactor node creation and destruction in list and forward_list (#65614)
This removes a lot of code duplication, makes the code simpler and
prepares the terrain for https://reviews.llvm.org/D101206, which will
fix some UB in the node-based containers.

This also allows removing the dependency of list and forward_list on
unique_ptr by using __allocation_guard instead.
2023-09-15 10:10:26 -04:00
Louis Dionne
4d08eccd63
[libc++] Implement P2538R1 "ADL-proof std::projected" (#65411)
Notice that because Holder<Incomplete> is _possible_ to complete, but
_unsafe_ to complete, that means that Holder<Incomplete>* is basically
not an iterator and it's not even safe to ask if
input_iterator<Holder<Incomplete>*> because that _will_ necessarily
complete the type. So it's totally expected that we still cannot safely
ask e.g.


static_assert(std::indirect_unary_predicate<bool(&)(Holder<Incomplete>&),
Holder<Incomplete>*>);

or even

static_assert(!std::indirect_unary_predicate<int, Holder<Incomplete>*>);

This was originally uploaded as https://reviews.llvm.org/D119029 and I
picked it up here as part of the Github PR transition.

Co-authored-by: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
2023-09-15 10:09:38 -04:00
eric
571e4f233b Mark LWG 2426 as complete.
Atomic is implemented by Clang, and Clang already implements the
behavior in the DR. This was initially noticed by Zoe Carver.
2023-09-14 16:42:57 -04:00
Louis Dionne
85f27d126d
[libc++] Make sure LWG2070 is implemented as a DR (#65998)
When we implemented C++20's P0674R1, we didn't enable the part of
P0674R1 that was resolving LWG2070 as a DR. This patch fixes that and
makes sure that we consistently go through the allocator when
constructing and destroying the underlying object in
std::allocate_shared.

Fixes #54365.
2023-09-14 15:12:06 -04:00
Dmitry Ilvokhin
3df9c2984b [libc++] Fix minor warnings in libcxx benchmarks
This fixes some unused variable and "comparison of integers of different
signs" warnings in the benchmarks.

Differential Revision: https://reviews.llvm.org/D156613
2023-09-13 17:05:56 -04:00
Louis Dionne
008bd84625
[libc++] Remove unused CMake option LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS (#66249)
Thanks @Gadal for noticing.

Fixes #63703
2023-09-13 16:05:39 -04:00
Louis Dionne
cce062d226
[libc++] Reintroduce the removed std::char_traits specialization (#66153)
This partially reverts commit e30a148b09, which removed the base
template for std::char_traits. That base template had been marked as
deprecated since LLVM 16 and we were planning to remove it in LLVM 18.
However, as explained in the post-commit comments in
https://reviews.llvm.org/D157058, the deprecation mechanism didn't work
as expected. Basically, the deprecation warnings were never shown to
users since libc++ headers are system headers and Clang doesn't show
warnings in system headers.

As a result, this removal came with basically no lead time as far as
users are concerned, which is a poor experience. For this reason, I am
re-introducing the deprecated char_traits specialization until we have a
proper way of phasing it out in a way that is not a surprise for users.
2023-09-13 12:30:05 -04:00
Zhangyin
adae4e9b5c [libcxx] <experimental/simd> Fix CI errors on 32-bits x86
Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D159509
2023-09-13 17:12:53 +08:00
Konstantin Varlamov
9d9a41e280 [libc++][hardening] Make the safe mode pipeline run with modules enabled
Differential Revision: https://reviews.llvm.org/D159065
2023-09-12 23:08:59 -07:00
Louis Dionne
644134799e
[libc++] Simplify the implementation of locale::id (#65781)
Since we use C++20 to build the dylib, we can use a lambda to do the
first-time initialization instead of emulating std::bind. This should
not change the behavior of the code at all, it merely simplifies it.

This removes a symbol from the dylib, however that symbol was only ever
used inside the dylib so it shouldn't break the ABI for anyone. I
confirmed that by searching for that symbol on the ABI boundary of a
large number of programs and couldn't find any references to that
function.
2023-09-12 19:20:27 -04:00
Armando Martín
d78ca7324c [libc++] Fix the rotate direction used in countl_zero()
This "bug" was probably not noticed because it doesn't affect any integer
type we currently support. It requires integers with more than 2x the
size of `unsigned long long`. However, with such types, the algorithm
used to break down the large integer into groups of size `unsigned long long`
didn't work because we rotated in the wrong direction.

For example, the 256 bit number (1 << 255) would yield the wrong answer
when used with the algorithm before this patch.

In particular, note that the current rotation happens to work for 128 bit
integers because it just swaps the halves in this case.

Differential Revision: https://reviews.llvm.org/D134625
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-09-12 18:19:56 -04:00
Louis Dionne
d671126ad0 [libc++][NFC] Remove stray #if 1 that was probably a debugging leftover 2023-09-12 17:19:28 -04:00
Konstantin Varlamov
b85e1862c1 [libc++][hardening] Add back the safe mode.
The safe mode is in-between the hardened and the debug modes, extending
the checks contained in the hardened mode with certain checks that are
relatively cheap and prevent common sources of errors but aren't
security-critical. Thus, the safe mode trades off some performance for
a wider set of checks, but unlike the debug mode, it can still be used
in production.

Differential Revision: https://reviews.llvm.org/D158823
2023-09-12 12:01:51 -07:00
Konstantin Boyarinov
2e106d5520 [libc++][test][NFC] Rewrite map count test and add test case for "final" compare
Was part of D118114. Unify test cases for `std::map::count` method and
add test case for the comparator that marked `final`

Differential Revision: https://reviews.llvm.org/D118232
2023-09-12 13:52:58 -04:00
Louis Dionne
3e266905f9 [libc++] Add missing std::ranges::join_view to the list of experimental features 2023-09-12 11:39:17 -04:00
Louis Dionne
06bb6c8b5c
[libc++] Document experimental features in the library (#65994)
Fixes #65125
2023-09-12 11:02:17 -04:00
Igor Zhukov
70248920fc [libc++][test] Add '-Wdeprecated-copy', '-Wdeprecated-copy-dtor' warnings to the test suite
This is a follow up to https://reviews.llvm.org/D144694.
Fixes https://github.com/llvm/llvm-project/issues/60977.

Differential Revision: https://reviews.llvm.org/D144775
2023-09-12 08:53:38 -04:00
Zhangyin
ed29f275bf [libcxx] <experimental/simd> Add broadcast constructor of class simd/simd_mask
Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D156225
2023-09-12 11:41:49 +08:00
Zhangyin
e7a45c6d76 [libcxx] <experimental/simd> Added internal storage type, constructors, subscript operators of class simd/simd_mask and related tests
[libcxx] <experimental/simd> Added internal storage type for class simd/simd_mask
[libcxx] <experimental/simd> Added all constructors of class simd/simd_mask and related tests
[libcxx] <experimental/simd> Added basic simd reference implementation, subscript operators of class simd/simd_mask and related tests

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D144364
2023-09-12 11:41:46 +08:00
Zhangyin
a284d0cc9c [libcxx] <experimental/simd> Added aliagned flag types, traits is_simd_flag_type[_v], memory_alignment[_v] and related tests
Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D153319
2023-09-12 11:41:44 +08:00
Zhangyin
ce5652c78a [libcxx] <experimental/simd> Added simd width functions, simd_size traits and related tests
Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D144363
2023-09-12 11:41:42 +08:00
Zhangyin
0e30dd44ad [libcxx] <experimental/simd> Add ABI tags, class template simd/simd_mask implementations. Add related simd traits and tests.
[libcxx] <experimental/simd> Add ABI tags, class template simd/simd_mask implementations.
[libcxx] <experimental/simd> Add traits is_abi_tag[_v], is_simd[_v] and is_simd_mask[_v].
[libcxx] <experimental/simd> Add related tests.

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D144362
2023-09-12 11:41:40 +08:00
Zhangyin
3e14076c76 [libcxx] <experimental/simd> Removed original implementations and tests
Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D144698
2023-09-12 11:41:38 +08:00
Louis Dionne
1d7cec6adc [libc++] Fix broken test in C++03 mode 2023-09-11 21:13:35 -04:00
Konstantin Varlamov
881718857f [libc++][ranges] Fix a split_view test accidentally using lazy_split 2023-09-11 16:17:34 -07:00
Louis Dionne
f3c2a3de84
[libc++] Mark static variables of locale::id as constinit (#65783)
The dylib contains multiple global variables of type locale::id. Those
can be marked as constinit to make it clear that static initialization
is performed.
2023-09-11 14:22:12 -04:00
Louis Dionne
3e24a77a86 [libc++] Use the default initializer for char_type in std::num_get::do_get
This is to fix an error that occurs when the char type is a class type.
Thanks to Yichen Yan for the patch.

Differential Revision: https://reviews.llvm.org/D100005
2023-09-11 14:16:47 -04:00
Louis Dionne
ee2a7bcebf [libc++] Add regression tests for issue #46841 2023-09-11 14:13:30 -04:00
Alex Brachet
62bec3de12
[libcxx] Fix include directory order (#65859)
It's important that the arch directory be included first so that
its header files which interpose on the default include dir
be included instead of the default ones. The clang driver [1] does
this when not building with -nostdinc, the libcxx build should
do the same.

We found this after https://reviews.llvm.org/D154282 when cross
compiling from non Linux to Linux. If the host machine was not
Linux, _LIBCPP_HAS_NO_TIME_ZONE_DATABASE would be defined in
the default include dir __config_site, while it was undefined
in the arch specific one causing build failures.
2023-09-11 12:36:06 -04:00
Hristo Hristov
623bb5c2c2 [libc++][ranges][NFC] Status page: Adds enumerate_view patch 2023-09-11 14:43:19 +03:00
Mark de Wever
2a0f2fa9d1 [libc++] Use inline instead of static in headers.
This has been tested as part of D156609.
2023-09-10 18:54:06 +02:00
Mark de Wever
2374ae4362 [libc++][nfc] Fixes emacs magic marker. 2023-09-09 14:43:12 +02:00
Konstantin Varlamov
5795e7ba3e [libc++][hardening][NFC] Fix the 17 release notes to remove mentions of hardening
This is to bring `main` in sync with `release/17.x` after https://reviews.llvm.org/D159171.

Differential Revision: https://reviews.llvm.org/D159454
2023-09-08 11:41:13 -07:00
Jake Egan
8a79af676d [libc++][AIX] Remove hardcode fail from format test
The test is hardcoded to fail after passing `test_ill_formed_utf16()`. It passes on 32-bit AIX if we remove this.

Reviewed By: Mordante, #libc, ldionne

Differential Revision: https://reviews.llvm.org/D150273
2023-09-08 13:40:07 -04:00
Colin Finck
5f29ed1654 [libc++] Fix warnings when compiling libc++ for Windows with clang-cl /W4
Differential Revision: https://reviews.llvm.org/D96408
2023-09-08 11:51:20 -04:00
Sirui Mu
679c0b48d7 [libc++abi] Refactor around __dynamic_cast
This commit contains refactorings around __dynamic_cast without changing
its behavior. Some important changes include:

- Refactor __dynamic_cast into various small helper functions;
- Move dynamic_cast_stress.pass.cpp to libcxx/benchmarks and refactor
  it into a benchmark. The benchmark performance numbers are updated
  as well.

Differential Revision: https://reviews.llvm.org/D138006
2023-09-08 11:47:24 -04:00
Alexander Richardson
bf1bcb68fc [libc++] Use intptr_t instead of ptrdiff_t for messages_base::catalog
On GLibc, FreeBSD and macOS systems nl_catd is a pointer type, and
round-tripping this in a variable of ptrdiff_t is not portable.
In fact such a round-trip yields a non-dereferenceable pointer on
CHERI-enabled architectures such as Arm Morello. There pointers (and
therefore intptr_t) are twice the size of ptrdiff_t, which means casting
to ptrdiff_t strips the high (metadata) bits (as well as a hidden pointer
validity bit).

Since catalog is now guaranteed to be the same size or larger than nl_catd,
we can store all return values safely and the shifting workaround from
commit 0c68ed006d should not be needed
anymore (this is also not portable to CHERI systems on since shifting a
valid pointer right will create a massively out-of-bounds pointer that
may not be representable).

This can be fixed by using intptr_t which should be the same type as
ptrdiff_t on all currently supported architectures.

See also: https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2028

Differential Revision: https://reviews.llvm.org/D134420

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-09-08 09:15:57 -04:00
Louis Dionne
7d7dcc1f25
[libc++][NFC] Remove dead code in <list> (#65651)
I came across this function (which is never used) while doing other
changes. It should be safe to remove since it's not used anywhere.
2023-09-08 08:52:02 -04:00
Daniel McIntosh
61cecf641f [libc++][NFC] tidy up strstreambuf::seekoff and strstreambuf::seekpos
Should be the same logic, but hopefully easier to read this way. Gets
rid of some superfluous state variables, and uses early returns.

Differential Revision: https://reviews.llvm.org/D112956
2023-09-08 08:50:20 -04:00
Louis Dionne
521c6117f6 [libc++][NFC] Run clang-format on strstream.cpp
I'm about to land https://reviews.llvm.org/D112956 which touches many
lines in that file anyway, so we might as well clang-format it first.
2023-09-08 08:50:19 -04:00
Xing Xue
7f302f220e Revert "[libc++][NFC] Remove __has_keyword"
This reverts commit cd34e89cfa.

See https://reviews.llvm.org/D158215#inline-1544266 for details.
2023-09-07 14:48:45 -04:00
Mark de Wever
88359213ee [libc++][chrono] TZDB CI fixes.
Fixes a conflict with adding the no experimental module build.

Disables some tests that need further investigation, this should fix the
CI runners.

These issues were reported on Discord and in D154282.
2023-09-07 20:31:18 +02:00
Brad Smith
401e457106 [libc++] Wipe some more macros that do not belong in C++ forwarding headers
Submitting upstream from OpenBSD tree.

Differential Revision: https://reviews.llvm.org/D94569
2023-09-07 13:32:26 -04:00
Will Hawkins
f00e0f2bdc
[libc++][doc] Add warning about limitation of --fresh in boostrapping build (#65265)
Add a warning to the `Building Libcxx` documentation about the
limitations of the utility of `--fresh` at the top level.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2023-09-07 13:22:07 -04:00
Joel E. Denny
bb6d5fc205 Revert "[lit] Improve test output from lit's internal shell"
This reverts commit c981c53305.

The reason for the revert is discussed at:
https://discourse.llvm.org/t/rfc-improving-lits-debug-output/72839/52
2023-09-07 12:35:55 -04:00
Will Hawkins
77fc5499d0 [libc++] Add support for bootstrapping build in libcxx-lit
Add a [-b|--bootstrap] flag to change cxx-test-depends to
runtimes-test-depends when testing a build of libcxx from bootstrapping.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>

Differential Revision: https://reviews.llvm.org/D157045
2023-09-07 12:05:43 -04:00
Dimitry Andric
6255157d24 [libc++] Re-enable std::pair trivial copy constructor for FreeBSD >= 14
After many years of using the really old std::pair ABI which did not yet
have a trivial copy constructor, FreeBSD 14 and later will finally get
rid of it. Only use the old ABI for FreeBSD 13 and earlier.

Note: on the FreeBSD side, we will bump our libc++.so version for this,
and keep an old compatibility library in a separate package.

Differential Revision: https://reviews.llvm.org/D126462
2023-09-07 11:57:56 -04:00
Alex Bradbury
c9b7ef4005 [libc++][test] Cover RISC-V in string.capacity test
Prior to this patch, libcxx/test/libcxx/strings/basic.string/string.capacity/max_size.pass.cpp
would fail for RISC-V. The __riscv macro is defined for both RV32 and RV64.

Differential Revision: https://reviews.llvm.org/D143158
2023-09-07 11:45:36 -04:00
h-vetinari
afc96481c4
[libc++] Clean up some minor inconsistencies in the status pages (#65259) 2023-09-07 11:05:19 -04:00
Arthur O'Dwyer
3df1a64eba [libc++] Add a test for std::ssize's SFINAE
Inspired by https://reviews.llvm.org/D120684#inline-1157644 and
subsequent LWG discussion. See http://wg21.link/LWG3207 for
additional context.

Differential Revision: https://reviews.llvm.org/D121154

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-09-06 19:40:50 -04:00
Zoe Carver
bd095b5c4d [libc++] Add tests for P0809 (Comparing Unordered Containers)
Differential Revision: https://reviews.llvm.org/D61771

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-09-06 19:37:17 -04:00
Mark de Wever
0735a6e3fa [NFC][libc++] Adds spaces in the CMake output.
The line continuations didn't have the proper spaces.
2023-09-06 20:54:43 +02:00