Commit Graph

10796 Commits

Author SHA1 Message Date
Mark de Wever
60647e6a29 [libc++][print] Disables tests with msan.
These tests break with msan on the sanitizer-aarch64-linux-bootstrap-msan
builder. Note the x86_64 builder is not affected. To unbreak the CI
temporary disable the tests completely with msan.

The breakage was introduced by D150044.
2023-07-19 20:59:44 +02:00
Piotr Fusik
8ecb959164 [libc++] Work around dynamic linking of stringbuf::str() on Windows
https://github.com/llvm/llvm-project/issues/40363 caused the C++20
`str() const &` and `str() &&` to be dllimport'ed despite _LIBCPP_HIDE_FROM_ABI.
This is a temporary solution until #40363 is fixed.

Reviewed By: #libc, hans, ldionne, Mordante

Differential Revision: https://reviews.llvm.org/D155185
2023-07-19 17:13:34 +02:00
Martin Storsjö
7506cb3c92 [libcxx] Link to fewer MSVC CRT libraries
The library msvcrt.lib pulls in ucrt.lib and vcruntime.lib anyway,
there's no need to manually link against the individual dependencies.

This matches how the tests link against libraries - they only link
against msvcrt and msvcprt, not directly against ucrt and vcruntime.

Differential Revision: https://reviews.llvm.org/D155555
2023-07-19 11:31:53 +03:00
Andrew Ng
f9e54a5c0f [libcxx] [test] Remove a stray double space from a test config. NFC.
Differential Revision: https://reviews.llvm.org/D155553
2023-07-19 11:31:52 +03:00
Mark de Wever
1cad87c07a [libc++][test] Fixes transitives includes. 2023-07-18 22:21:10 +02:00
Mark de Wever
7941e5df76 [libc++][print] Fixes tests.
The exception message improvements for `<format>` were not applied to
print. The issue has been reported by Ian Anderson.
2023-07-18 21:49:26 +02:00
Mark de Wever
b9f3d241f4 [libc++][format] Fixes times before epoch.
The number of days should be rounded down, for both positive and
negative times since epoch. The original code truncated, which is
correct for positive values, but wrong for negative values.

Depends on D138826

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154865
2023-07-18 21:17:11 +02:00
Mark de Wever
402eb2ef09 [libc++][format] Improves diagnostics.
Improves both the compile-time and run-time errors.
At compile-time it does a bit more work to get more specific errors.
This could be done at run-time too, but that has a performance penalty.
Since it's expected most use-cases use format* instead of vformat* the
compile-time errors are more common.

For example when using

  std::format_to("{:-c}", 42);

Before compile output would contain

  std::__throw_format_error("The format-spec should consume the input or end with a '}'");

Now it contains

  std::__throw_format_error("The format specifier does not allow the sign option");

Given a better indication the sign option is not allowed. Note the
output is still not user-friendly; C++ doesn't have good facilities to
generate nice messages from the library.

In general all messages have been reviewed and improved, using a more
consistent style and using less terms used in the standard. For example

  format-spec -> format specifier
  arg-id -> argument index

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D152624
2023-07-18 21:11:12 +02:00
Mark de Wever
a0ffeccc70 [libc++][format] Improves run-time diagnostics.
After parsing a std-format-spec it's validated, depending on the type used some
format options are not allowed. This improves the error messages in the
exceptions thrown upon failure.

Depends on D155364

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D155366
2023-07-18 21:01:52 +02:00
Mark de Wever
cf931d4fa5 [libc++][format] Improves compile-time diagnostics.
Then a std-format-spec option is invalid for a type the compile-time
validation will detect its usage and issue a diagnostic. Before it
validated after parsing the entire std-format-spec, which meant the
diagnostic was less precise. It would be possible to do this validation
run-time but that has a performance overhead. When using the format
family of functions, this would be unneeded overhead; the validation was
done at run-time. For the vformat family it would give better
diagnostics.

To avoid paying what you don't use, it has been decided to aim for the
better performance. It's more likely users will use the format family of
functions.

Depends on D155264

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D155364
2023-07-18 20:46:06 +02:00
Mark de Wever
eb70334114 [NFC][libc++][format] Generalizes bracket parsing.
Both the tuple formatter and range formatter parse a bracket. Instead of
implementing this twice do it in the generic parser. This is preparation
to improve the diagnostics in the format library.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D155264
2023-07-18 20:32:58 +02:00
Mark de Wever
3f65f71833 [libc++][print] Adds FILE functions.
Drive-by fix to make sure the __retarget_buffer works correctly whan
using a hint of 1. This was discovered in one of the new tests.

Drive-by fixes __retarget_buffer when initialized with size 1.

Implements parts of
- P2093R14 Formatted output
- P2539R4  Should the output of std::print to a terminal be
           synchronized with the underlying stream?

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D150044
2023-07-18 20:07:11 +02:00
Louis Dionne
b88db47bd2 [libc++] Encode the version in the ReleaseNotes file
This way, we don't need to remove the contents of the ReleaseNotes file
after the branch. This should make it much easier and natural to cherry-pick
changes onto the release branch. Typically, we need two patches for those.
First, we need the code changes against `main`, and then we need a patch
that updates the release notes on the just-created branch.

By versioning the release notes, it becomes easy to author a change
against `main` that targets a just-branched LLVM release by simply
adding it to the release notes for the right version. This has been
a pain point in previous releases.

Differential Revision: https://reviews.llvm.org/D155024
2023-07-18 14:06:21 -04:00
pateldeev
347f45ed2b [libc++][LWG 2996] Implement c++20 shared_ptr rvalue overloads.
Implement c++20 `shared_ptr` rvalue overloads for aliasing constructor and pointer casts. See https://cplusplus.github.io/LWG/issue2996

Commit from
"patedeev" <dkp10000@gmail.com>

Reviewed By: philnik, #libc, ldionne, pateldeev

Differential Revision: https://reviews.llvm.org/D135548
2023-07-18 20:04:21 +02:00
varconst
ef70fe4d26 [libc++][ranges] Implement the changes to node-based containers from P1206 (ranges::to):
- add the `from_range_t` constructors and the related deduction guides;
- add the `insert_range`/`assign_range`/etc. member functions.

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

Differential Revision: https://reviews.llvm.org/D149830
2023-07-18 11:01:10 -07:00
Mark de Wever
ab0d757bcf [libc++][chrono] Fixes month inc and dec operations.
The operator++, operator++(int), operator--, and operator--(int) need to
change the month to a valid value. The wording is specified in terms of
  operator+(const month& x, const months& y) noexcept;
which has the correct behavior. The aforementioned operators instead
used ++/-- on the internal value direction, resulting in incorrect
behaviour.

As a drive-by improve the unit tests:
- use the typical constexpr test method
- test whether the month is valid after the operations
- format the tests

Fixes: https://llvm.org/PR63912

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D155504
2023-07-18 17:32:11 +02:00
Louis Dionne
64558826ed [libc++] Remove broken self test for the libc++ Lit format
The empty.sh.cpp test never tested what it was intended to test, because
it did contain an unexpected RUN: command. This was discovered in
https://reviews.llvm.org/D154987 while trying to land an unrelated change.
Since there is no reliable way to test what I was trying to test from
the libc++ test suite, just remove the test.
2023-07-17 18:35:10 -04:00
Louis Dionne
c9c3cddb5e [libc++] Use _LIBCPP_VERBOSE_ABORT in a few remaining __throw_FOO functions
This provides better error messages when the program terminates due to
an exception being thrown in -fno-exceptions mode. Those seem to have
been missed in https://reviews.llvm.org/D141222.

Differential Revision: https://reviews.llvm.org/D154995
2023-07-17 18:00:03 -04:00
Nikolas Klauser
9ebc24d90c [libc++][NFC] Remove unused macro definition 2023-07-17 13:24:30 -07:00
Louis Dionne
71f95ecff2 [libc++] Move _LIBCPP_NO_THREAD_SAFETY_ANALYSIS to __config
This makes __threading_support contain nothing but the base threading
API provided by the system.

Differential Revision: https://reviews.llvm.org/D155458
2023-07-17 16:06:46 -04:00
Mark de Wever
44d17cd739 [libc++][doc] Updates the release notes.
This is a preparation for the upcoming LLVM 17 release.

Reviewed By: ldionne, jloser, H-G-Hristov, #libc

Differential Revision: https://reviews.llvm.org/D154874
2023-07-17 18:41:10 +02:00
Mark de Wever
7583c73bc4 [libc++][format] Fixes an off by one error.
The post-condition on the functions is that the buffer is not full.
This post-conditon is used as pre-condition of the push_back function.
When a copy, fill, of transform function exactly fit in the buffer this
post-condition was validated.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D155397
2023-07-17 18:01:19 +02:00
Louis Dionne
edab068de4 [libc++][NFC] Remove unnecessary declarations in __thread/id.h 2023-07-17 09:37:32 -04:00
Louis Dionne
724fcace0a [libc++][NFC] clang-format __thread/id.h since it just got moved 2023-07-17 09:36:36 -04:00
Louis Dionne
8ac71b026e [libc++] Remove internal "build-with-external-thread-library" configuration
Our threading support layer is currently a huge mess. There are too many
configurations with too many confusing names, and none of them are tested
in the usual CI. Here's a list of names related to these configurations:

  LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY
  _LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL

  LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY
  _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL

  LIBCXX_HAS_EXTERNAL_THREAD_API
  _LIBCPP_HAS_THREAD_API_EXTERNAL

This patch cleans this up by removing the ability to build libc++ with
an "external" threading library for testing purposes, removing 4 out of
6 "names" above. That setting was meant to be used by libc++ developers,
but we don't use it in-tree and it's not part of our CI.

I know the ability to use an external threading API is used by some folks
out-of-tree, and this patch doesn't change that. This only changes the
way they will have to test their external threading support. After this
patch, the intent would be for them to set `-DLIBCXX_HAS_EXTERNAL_THREAD_API=ON`
when building the library, and to provide their usual `<__external_threading>`
header when they are testing the library. This can be done easily now
that we support custom lit configuration files in test suites.

The motivation for this patch is that our threading support layer is
basically unmaintainable -- anything beyond adding a new "backend" in
the slot designed for it requires incredible attention. The complexity
added by this setting just doesn't pull its weigh considering the
available alternatives.

Concretely, this will also allow future patches to clean up
`<__threading_support>` significantly.

Differential Revision: https://reviews.llvm.org/D154466
2023-07-17 09:32:36 -04:00
Piotr Fusik
c7c0095b29 [libc++] Implement stringstream members of P0408R7 (Efficient Access to basic_stringbuf's Buffer)
Reviewed By: Mordante, #libc

Differential Revision: https://reviews.llvm.org/D155359
2023-07-16 18:32:56 +02:00
Piotr Fusik
6ed4041891 [libc++] Implement ostringstream members of P0408R7 (Efficient Access to basic_stringbuf's Buffer)
Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D155276
2023-07-16 15:25:35 +02:00
Mark de Wever
2c07ca853b [NFC][libc++] Fixes some comments. 2023-07-16 11:34:41 +02:00
Ian Anderson
33fe4dc91e [libc++][Modules] Restore the <string> include to <__format/format_functions.h>
<__format/format_functions.h> was using <string>, we need to bring the include back that was removed in D154122.

Reviewed By: Mordante, #libc

Differential Revision: https://reviews.llvm.org/D155116
2023-07-15 08:29:25 -07:00
Mark de Wever
dd5c4da552 [libc++] Adds a missing include.
It turns out D153336 needs a new include. This should fix the broken
LLVM CI runners.
2023-07-15 16:29:36 +02:00
Piotr Fusik
34bd7e229d [libc++][tests] Fix a test testing wrong class
Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D155360
2023-07-15 16:14:55 +02:00
Mark de Wever
56ae3568ea [NFC][libc++][bitset] Refactors constructors.
Based on the review comments in D153201 this combines the string and
c-string constructors. The common constructor is using a string_view:
- it allows propagating the _Traits, which are required to be used for
  comparison.
- it avoids allocating
- libc++ supports it in C++03

Reviewed By: philnik, #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154860
2023-07-15 15:21:31 +02:00
Edoardo Sanguineti
1122cbf403 [libc++] add basic runtime assertions to <barrier>
Adding assertions will aid users that have bugs in their code to receive better error messages.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154626
2023-07-15 12:50:28 +02:00
Mark de Wever
a4814bdc53 [libc++][chrono] Fixes formatter duration.
@EricWF spotted this issue in the post-commit review comments of
D134742. However the suggestion to just use chrono calculations can
result in similar issues when using small fractional seconds.

Reviewed By: EricWF, #libc

Differential Revision: https://reviews.llvm.org/D138826
2023-07-15 12:02:03 +02:00
Mark de Wever
1c1edd1b5d [libc++] Fixes thread::id's operator<<.
The output of

  template<class charT, class traits>
    basic_ostream<charT, traits>&
      operator<<(basic_ostream<charT, traits>& out, thread::id id);

is affected by the state of out. The wording states

[thread.thread.id]/2
  The text representation for the character type charT of an object of
  type thread::id is an unspecified sequence of charT such that, for two
  objects of type thread::id x and y, if x == y is true, the thread::id
  objects have the same text representation, and if x != y is true, the
  thread::id objects have distinct text representations.

[thread.thread.id]/9
  template<class charT, class traits>
    basic_ostream<charT, traits>&
      operator<< (basic_ostream<charT, traits>& out, thread::id id);

  Effects: Inserts the text representation for charT of id into out.

This wording changed in C++23 due to adding a formatter specialization for
thread::id. However the requirement was the same in older versions of C++.

This issue is that thread::id is an integral or pointer and affected by the
formatting manipulators for them. Thus the text representation can differ if
x == y which violates the requirements.

The fix has to hard-code some formatting style for the text
representation. It uses the Standard specified default values

Table 124: basic_ios::init() effects [tab:basic.ios.cons] flags()
  flags() skipws | dec

Fixes PR: https://llvm.org/PR62073

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D153336
2023-07-15 11:52:19 +02:00
Nikolas Klauser
4675a3261e [libc++][NFC] Remove redundant defined(_LIBCPP_BUILDING_LIBRARY) 2023-07-15 01:38:34 -07:00
Advenam Tacet
6a9c41fdd4 [libc++] Set correct size at the end of growing std::string
This commit deprecates `std::basic_string::__grow_by`, which is part of ABIv1. The function is replaced by `std::basic_string:__grow_by_without_replace`, which is not part of ABI.

- The original function `__grow_by` is deprecated because it does not set the string size,  therefore it may not update the size when the size is changed, and it may also not set the size at all when the string was short initially. This leads to unpredictable size value. It is not removed or changed to avoid breaking the ABI.
- The commit adds `_LIBCPP_HIDE_FROM_ABI`  guarded by `_LIBCPP_ABI_VERSION >= 2` to `__grow_by`. This allows the function to be used in the dylib in ABIv1 without raising the `[abi:v170000]` error and removes it from future ABIs. `_LIBCPP_HIDE_FROM_ABI_AFTER_V1` cannot be used.
- Additionally, `__grow_by` has been removed from `_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST` in `libcxx/include/__string/extern_template_lists.h`.

This bugfix is necessary to implement string ASan annotations, because it mitigates the problems encountered in D132769.

Reviewed By: ldionne, #libc, philnik

Differential Revision: https://reviews.llvm.org/D148693
2023-07-15 04:00:30 +02:00
varconst
f0dfe682bc [libc++][hardening] Deprecate _LIBCPP_ENABLE_ASSERTIONS.
`_LIBCPP_ENABLE_ASSERTIONS` was used to enable the "safe" mode in
libc++. Libc++ now provides the hardened mode and the debug mode that
replace the safe mode.

For backward compatibility, enabling `_LIBCPP_ENABLE_ASSERTIONS` now
enables the hardened mode. Note that the hardened mode provides
a narrower set of checks than the previous "safe" mode (only
security-critical checks that are performant enough to be used in
production).

Differential Revision: https://reviews.llvm.org/D154997
2023-07-14 16:58:47 -07:00
Christian Trott
20c6b9d451 [libc++][mdspan] Implement default_accessor
This commit implements default_accessor in support of C++23 mdspan
(https://wg21.link/p0009). default_accessor is the trivial accessor
using plain pointers and reference to element types.

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

Differential Revision: https://reviews.llvm.org/D153935
2023-07-14 11:52:40 -06:00
Nikolas Klauser
76f20099a5 [libc++][NFC] Update emojis in the buildkite pipeline 2023-07-14 08:20:18 -07:00
Martin Storsjö
3277aaae6f [libcxx] [test] Skip timezone formatting tests on Windows
While these tests do pass in the CI environment, they fail elsewhere.
On GitHub Action runners, they produce '+0000' instead of '-0000' for
the UTC offset, and on local machines, it outputs the UTC offset of
the local timezone.

Differential Revision: https://reviews.llvm.org/D155182
2023-07-14 09:53:19 +03:00
Piotr Fusik
61d2a9b3ea [libc++] Implement istringstream members of P0408R7 (Efficient Access to basic_stringbuf's Buffer)
Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D154454
2023-07-14 08:32:27 +02:00
Po-yao Chang
bd03e0ca75 [libc++][NFC] Suppress -Wdeprecated-literal-operator
Remove spaces between operator"" and identifier to suppress
-Wdeprecated-literal-operator, and between operator and ""
like how they are written in [string.view.literals] and [basic.string.literals].

Differential Revision: https://reviews.llvm.org/D155200
2023-07-14 06:52:39 +08:00
Louis Dionne
dab5f56eaf [libc++] Fix filesystem tests on platforms that don't have IO
This patch moves a few tests that were still using std::fprintf to
using TEST_REQUIRE instead, which provides a single point to tweak
for platforms that don't implement fprintf. As a fly-by fix, it also
avoids including `time_utils.h` in filesystem_clock.cpp when it is
not required, since that header makes some pretty large assumptions
about the platform it is on.

Differential Revision: https://reviews.llvm.org/D155019
2023-07-13 13:58:37 -04:00
Louis Dionne
76e3928fc7 [libc++] Remove BuildKite bridging files that are not needed anymore
Differential Revision: https://reviews.llvm.org/D155120
2023-07-13 10:46:40 -04:00
Nico Weber
7a9b8a8374 [gn build] Port 2b2e7f6e57 2023-07-13 08:37:12 -04:00
Louis Dionne
7e6f2b749b [libc++] Fix clock selection in chrono.cpp and filesystem_clock.cpp
This patch partly reverts the change that was made in 5f1ba3a502
regarding the clock selection on Apple platforms. It turns out that
gettimeofday() is marked as obsolete by POSIX and clock_gettime() is
recommended instead. Since both are equivalent for our purposes,
prefer using clock_gettime() even on Apple platforms.

Differential Revision: https://reviews.llvm.org/D155022
2023-07-12 18:07:21 -04:00
Nikolas Klauser
2b2e7f6e57 [libc++][PSTL] Add a GCD backend
Reviewed By: ldionne, #libc

Spies: arichardson, mgrang, krytarowski, libcxx-commits, h-vetinari

Differential Revision: https://reviews.llvm.org/D151717
2023-07-12 13:27:33 -07:00
Edoardo Sanguineti
dd2cfabddb [libc++] add test for latch ctor
Currently, there are no tests to confirm without a doubt the constructor of latch is really constexpr and explicit.
I think this would be an addition that it would not harm to have. In another revision, I was asked to add tests for an almost identical case which made me consider adding this test for the latch class too.

Reviewed By: #libc, philnik

Spies: philnik, libcxx-commits, kristof.beyls

Differential Revision: https://reviews.llvm.org/D154957
2023-07-12 12:33:19 -07:00
Edoardo Sanguineti
c77af00eb9 [libc++] mark barrier constructor as explicit in <barrier>
If I read the standard correctly, the public constructor of "barrier" should be marked as "constexpr explicit".
I see some of the internal classes used by the barrier header are correctly marked but I think, if I'm not mistaken, the standard would like the public class to have the correct definition as well.

Because the implementation that llvm uses by default is not constexpr friendly at this time, this revision will focus on only marking it as explicit.

Reviewed By: #libc, philnik, Mordante

Spies: philnik, Mordante, libcxx-commits

Differential Revision: https://reviews.llvm.org/D154590
2023-07-12 12:31:16 -07:00
Louis Dionne
4766b96399 [libc++] Stop running backdeployment CI on macOS 10.9
The oldest deployment target supported by Xcode 14 is macOS 10.13.
Trying to back-deploy to older targets runs into other issues in Clang,
so stop testing libc++ against unsupported deployment targets.

This patch doesn't attempt to clean up support for older deployment
targets from the code base -- this will be done in a follow-up patch.

Differential Revision: https://reviews.llvm.org/D155085
2023-07-12 14:04:05 -04:00
Louis Dionne
298f207e06 [ci] Make libc++ and Clang CI scripts independent
This simply moves existing CI-related scripts for Clang outside of libc++
to make the two projects independent with respect to CI.

The reason for making this change is that libc++'s CI pipeline history
was full of Clang runs, making it a lot harder to figure out information
about libc++'s own jobs. I created a pipeline for Clang and this patch
will run pre-commit CI for Clang inside that pipeline instead.

Differential Revision: https://reviews.llvm.org/D155078
2023-07-12 14:01:38 -04:00
varconst
1ba514c2cb [libc++][hardening][NFC] Remove the LIBCXX_DEBUG_BUILD CMake variable.
It's no longer necessary to define `_DEBUG` because we use our own
internal assertion mechanism in libc++.

Differential Revision: https://reviews.llvm.org/D155038
2023-07-12 10:16:00 -07:00
varconst
d1367ca46e [libc++][hardening][NFC] Add macros to enable hardened mode.
This patch only adds new configuration knobs -- the actual assertions
will be added in follow-up patches.

Differential Revision: https://reviews.llvm.org/D153902
2023-07-12 10:12:58 -07:00
varconst
d0b51657c2 [libc++] Fix an exception safety issue in forward_list and add tests.
When inserting nodes into a forward list, each new node is allocated but
not constructed. The constructor was being called explicitly on the node
`value_` but the `next_` pointer remained uninitialized rather than
being set to null. This bug is only triggered in the cleanup code if an
exception is thrown -- upon successful creation of new nodes, the last
incorrect "next" value is overwritten to a correct pointer.

This issue was found due to new tests added in
https://reviews.llvm.org/D149830.

Differential Revision: https://reviews.llvm.org/D152327
2023-07-12 10:11:26 -07:00
Nikolas Klauser
a70ce8cb0e [libc++][PSTL] Fix double-move in std::transform_reduce
Reviewed By: #libc, ldionne

Spies: h-vetinari, libcxx-commits

Differential Revision: https://reviews.llvm.org/D154913
2023-07-12 08:56:10 -07:00
Nikolas Klauser
2a3322bab0 [clang] Create a buildkite-pipeline.yml file for clang
This moves the formatting job to a shell script, which should also fix
the clang pre-commit CI.

Differential Revision: https://reviews.llvm.org/D153920
2023-07-12 08:33:22 -04:00
Mark de Wever
28584755e4 [libc++][chrono] Fixes formatting duration subseconds.
Fixes https://llvm.org/PR62082

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154851
2023-07-11 20:39:56 +02:00
Mark de Wever
20341c3ad6 [libc++][format] Adds a UTF transcoder.
This is a preparation for

  P2093R14 Formatted output

When the output of print is to the terminal it needs to use the native
API. This means transcoding UTF-8 to UTF-16 on Windows. The encoder's
interface is modeled after

 P2728 Unicode in the Library, Part 1: UTF Transcoding

But only the required part for P2093R14 is implemented.

On Windows wchar_t is 16 bits, in order to test on platforms where
wchar_t is 32 bits the transcoder has support for char16_t. It also adds
and UTF-8 to UTF-32 encoder which is useful for other tests.

Note it is possible to use <codecvt> for transcoding, but that header is
deprecated. So rather write new code that is not deprecated; the hard
part, decoding, has already been done. The <codecvt> header also
requires locale support while the new code works without including
<locale>.

Note the current transcoder implementation can be optimized since it
basically does UTF-8 -> UTF-32 -> UTF-16. The first goal is to have a
working implementation. Since it's not part of the ABI it's possible to
do the optimization later.

Depends on D149672

Reviewed By: ldionne, tahonermann, #libc

Differential Revision: https://reviews.llvm.org/D150031
2023-07-11 20:28:19 +02:00
Louis Dionne
053d9e5832 [libc++] Move __thread_id out of <__threading_support>
This makes <__threading_support> closer to handling only the bridge
between the system's implementation of threading and the rest of libc++.

Differential Revision: https://reviews.llvm.org/D154464
2023-07-11 08:58:27 -04:00
Hui
477f6bc407 [libc++] Make stop_token experimental
There are discussions about different ways of implementing `stop_token` to make it more performant
mark `stop_token` as experimental to allow us to change the design before it is shipped

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>

Differential Revision: https://reviews.llvm.org/D154700
2023-07-11 08:52:31 -04:00
Mark de Wever
3ab20c6809 [libc++][format] Granularize formatter_output.
This should reduce the size of the transitive includes for the vector header.
Note the header still quite large so the difference may be small.

Depends on D154122

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D154286
2023-07-10 19:30:26 +02:00
Louis Dionne
6f36ead577 [libc++] Fix std::move algorithm with trivial move-only types
As reported in https://reviews.llvm.org/D151953#4472195, the std::move
algorithm (and various other functions that relied on it) stopped working
after starting to use `__constexpr_memmove` in its implementation. This
patch fixes the underlying issue in `__constexpr_memmove` and adds tests
for various related algorithms and functions that were not exercising
trivial move-only types.

Differential Revision: https://reviews.llvm.org/D154613
2023-07-10 11:50:09 -04:00
Louis Dionne
baf560e395 [libc++] Add missing include to fix no-localization CI 2023-07-10 09:58:55 -04:00
Louis Dionne
a84914c675 [libc++] Remove unnecessary _LIBCPP_VERSION tests
These tests are now generated by libcxx/test/libcxx/libcpp_version.gen.py.

Differential Revision: https://reviews.llvm.org/D154656
2023-07-10 09:46:22 -04:00
David Spickett
43cfc788fa [libcxx] Check MSVC flag directly instead of setting LIBCXX_TARGETING_MSVC
MSVC is set for actual msvc and clang-cl. LIBXX_TARGETTING_CLANG_CL is
still used over in runtimes to configure warning flags.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154698
2023-07-10 09:25:26 +00:00
Jake Egan
643b7bcdb4 [libc++] Fix simple cases of locale name construction
When using the following constructors:

```
locale(const locale& other, const char* std_name, category cat);
locale(const locale& other, const string& std_name, category cat);
locale(const locale& other, const locale& one, category cats);
```
The new locale name is always "*". Locale names formed from parts of two named locales (that is, C++ locales having names) are supposed to have names in turn (see C++20 subclause 28.3.1.1 [locale.general] paragraph 8). This patch fixes the name construction for cases when either of locales are unnamed, when the category is locale::none, and when the two locale names are the same.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D119441
2023-07-08 22:02:56 -04:00
Christoph Schlosser
cf6b3315f2 libcxx: Bring back unsigned return from wcstoull_l
Got removed here:
21d9282ae2b6e1e7dfbabfd87f6208c3bdff8ea4#diff-e41832b8aa26da45585a57c5111531f2e1d07e91a67c4f8bf1cd6d566ae45a2bR40

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D148056
2023-07-08 13:54:30 +02:00
Mark de Wever
438073b213 [libc++][doc] Removes clang name in version number.
Noticed I had these left in just committed code.
2023-07-08 13:36:32 +02:00
Mark de Wever
c62e88eeef [libc++][modules] Avoids duplicated exports.
The first issue was found by @ldionne, upon further investigation there
were more duplicates. This removes the duplicates and updates the
clang-tidy test to detect duplicates.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D154723
2023-07-08 13:19:43 +02:00
Mark de Wever
d3d079678c [NFC][libc++] Addresses LWG3905.
Note libc++ implemented this in its initial version. It always used the type
from the C library and never validated whether it was an integer type.

Implements
- LWG3905 Type of std::fexcept_t

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D153285
2023-07-08 12:56:46 +02:00
Mark de Wever
00e740f1e9 [NFC][libc++] Addresses LWG3903.
Note libc++ actually implemented this wording from the start (D49338).
The Clang version is the same as the version that implements
  P0122R7 <span>

Implements
- LWG3903 span destructor is redundantly noexcept

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D153284
2023-07-08 12:54:49 +02:00
Mark de Wever
285e1e2a00 [libc++][format] Removes unneeded includes.
I did a manual review after the post-review comments in D149543

Reviewed By: #libc, philnik, ldionne

Differential Revision: https://reviews.llvm.org/D154122
2023-07-08 12:39:33 +02:00
Mark de Wever
f8d96d8e06 [NFC][libc++] Addresses LWG3885.
Implements
- LWG3885 'op' should be in [zombie.names]

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D153283
2023-07-08 12:27:24 +02:00
yrong
1e02158666 [libc++] Implement LWG3843 (std::expected<T,E>::value() & assumes E is copy constructible)
Implement LWG3843 (std::expected<T,E>::value() & assumes E is copy constructible)
https://wg21.link/LWG3843

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154110
2023-07-08 11:57:00 +08:00
Ian Anderson
6c47654efd Revert "[libc++] Remove the type_traits includes from limits and new"
type_traits doesn't need to include __type_traits/noexcept_move_assign_container.h, so there is no include cycle from <limits> or <new>. Restore their includes of type_traits to preserve compatibility.

This reverts commit 2af6d79c7e.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D154747
2023-07-07 17:53:09 -07:00
Nikolas Klauser
ece2294b9a [libc++][PSTL] Add a missing policy argument in the std::merge test
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D154546
2023-07-07 15:41:41 -07:00
Louis Dionne
b5a9f9f6dc [libc++] Make sure we use __ulock on Apple platforms
We forgot to include the header, which means that _LIBCPP_USE_ULOCK was
always undefined and we'd always use the fallback. Note that this doesn't
seem to fix https://github.com/llvm/llvm-project/issues/63737.

Differential Revision: https://reviews.llvm.org/D154718
2023-07-07 17:15:22 -04:00
Louis Dionne
1c834112f2 [libc++] Add some tests for std::bit_cast using pointers
Differential Revision: https://reviews.llvm.org/D154728
2023-07-07 17:14:52 -04:00
Ian Anderson
67b37af4cd [libc++][Modules] Add missing __fwd includes
A few __fwd includes are missing from public modules that will become noticeable when the private submodules are split into their own top level modules (D144322). Add the missing includes.

Reviewed By: ldionne, philnik, #libc

Differential Revision: https://reviews.llvm.org/D153216
2023-07-07 14:09:27 -07:00
Louis Dionne
9101479420 [libc++][NFC] Add 'const' to some operator()
This is NFC because the function object is stateless anyway. This is
done solely for consistency with surrounding code and this was probably
an oversight in https://reviews.llvm.org/D132505.

Differential Revision: https://reviews.llvm.org/D154612
2023-07-06 16:46:34 -04:00
Nicole Rabjohn
92e4d6791f Fixing conflicting macro definitions between curses.h and the standard library.
POSIX allows certain macros to exist with generic names (i.e. refresh(), move(), and erase()) to exist in `curses.h` which conflict with functions found in std::filesystem, among others. This patch undefs the macros in question and adds them to LIBCPP_PUSH_MACROS and LIBCPP_POP_MACROS.

Reviewed By: #libc, philnik, ldionne

Differential Revision: https://reviews.llvm.org/D147356
2023-07-06 17:21:08 +00:00
varconst
e61764c32f [libc++][hardening][NFC] Rename the has-debug-mode feature to has-legacy-debug-mode.
This will allow reusing the `has-debug-mode` feature for the new debug
mode without accidentally reenabling old debug mode tests. The
`has-legacy-debug-mode` feature is deliberately never set -- the old
tests are left checked in to have a point of reference for the level of
checking that was supported by the legacy debug mode, making it easier
to verify we've reached feature parity in the future.
2023-07-06 10:19:27 -07:00
David Spickett
36df92dcd9 [libcxx] Only add -GR- option to MSVC or clang-cl builds
Previously we added both `-GR-` and `-fno-rtti` if RTTI was disabled.
When building with clang 16.x, that caused this error in part of the build:
```
clang-16: error: argument unused during compilation: '-G R-' [-Werror,-Wunused-command-line-argument]
```
I think the strange message is because clang is seeing `R-` as the argument
to `-G`, which is a valid clang option.

`-GR-` is an alternate syntax for the `/GR-` option for MSVC
(the dash means disable RTTI):
https://learn.microsoft.com/en-us/cpp/build/reference/gr-enable-run-time-type-information?view=msvc-170

This error is sort of fixed by cd18efb61d
but not intentionally. Also, we'd have to wait for 17.x to benefit from that.

The proper fix here is to only add `-GR-` if we are building with MSVC
or the MSVC-like clang-cl, and add `-fno-rtti` if not.

Reviewed By: #libc, simon_tatham, michaelplatings, ldionne

Differential Revision: https://reviews.llvm.org/D154582
2023-07-06 14:47:02 +00:00
Louis Dionne
5b666cf11e [libc++] Fix thread annotations on shared_mutex and shared_timed_mutex
Based on the comment in https://reviews.llvm.org/D54290#4418958, these
attributes need to be on the top-level functions in order to work
properly. Also, add tests.

Fixes http://llvm.org/PR57035.

Differential Revision: https://reviews.llvm.org/D154354
2023-07-06 08:37:10 -04:00
varconst
baf6f91851 [libc++][ranges] Implement the changes to basic_string from P1206 (ranges::to):
- add the `from_range_t` constructors and the related deduction guides;
- add the `insert_range`/`assign_range`/etc. member functions.

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

Differential Revision: https://reviews.llvm.org/D149832
2023-07-05 14:50:59 -07:00
Louis Dionne
99dcc9ff0e [libc++][NFC] Remove leftover entry for <experimental/span> in header_information.py 2023-07-05 17:48:04 -04:00
Nikolas Klauser
75f6af82c3 [libc++] Mark LWG2994 as complete and remove Clang from the version
Reviewed By: #libc, ldionne

Spies: ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D154381
2023-07-05 14:43:04 -07:00
Edoardo Sanguineti
5e807c38bf [libc++] add basic runtime assertions to <latch>
Adding assertions will aid users that have bugs in their code to
receive better error messages.

Differential Revision: https://reviews.llvm.org/D154425
2023-07-05 17:34:23 -04:00
James Y Knight
73c12a8ffc [libcxx] Migrate posix_compat.h layer to not use CRT filesystem functions.
Right now, the filesystem APIs _mostly_ use Win32 API calls, but a
small number of functions use CRT APIs instead. The semantics are
effectively the same, except for which sorts of error codes are
returned. We want to be consistent about returning only native Win32
error codes, as a prerequisite for https://reviews.llvm.org/D151493.

This change switches getcwd, chdir, and mkdir. It does _not_ switch
open/close, because there are difficulties around the use of C-runtime
file descriptor numbers. Instead, those two APIs are removed from
posix_compat.h, and the win32-specific code inlined into the
operations.cpp FileDescriptor class (with a TODO comment).

Reviewed By: #libc, mstorsjo, Mordante

Differential Revision: https://reviews.llvm.org/D153037
2023-07-05 13:27:46 -04:00
Ian Anderson
9992b386bf [libc++][Modules] Remove explicit exports from modules that export *
This may be a clang bug, but explicit exports interfere with `export *`, especially in local submodule visibility mode. For example, exporting `depr.stdint_h` from `cstdint` causes std::int32_t to become an "unresolved using declaration" in LSV if `cstdint` and `stdint.h` are promoted to top level modules. This was previously worked around by exporting `Darwin.C.stdint` in `depr.stdint_h`, but that only works on Apple platforms, and it stops working when `cstdint` and `stdint.h` are promoted to top level modules.

Remove all of the explicit `export` statements in modules that have `export *`.

Reviewed By: ldionne, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D153212
2023-07-05 09:52:02 -07:00
Ian Anderson
6f05da6cf8 [libc++][Modules] Add missing submodules
Several headers that are included by the modular headers are missing from the module map, add those in.
The either/or implementation headers `<__algorithm/pstl_backends/cpu_backends/serial.h>`/`<__algorithm/pstl_backends/cpu_backends/thread.h>` need to be textual, as does `<__undef_macros>`.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D153213
2023-07-05 09:51:11 -07:00
Mark de Wever
a9e5773f52 [libc++][format] Implements formatting pointer.
The feature is applied as DR instead of a normal paper. MSVC STL and
libstdc++ will do the same.

Implements
- P2510R3 Formatting pointers

Depends on D153192

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D153195
2023-07-05 18:23:31 +02:00
Mark de Wever
1403080a1f [NFC][chrono][test] Fixes some tests on Windows.
This updates the tests to match the actual output on Windows.
Note some tests still need more investigation.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D153498
2023-07-05 18:09:24 +02:00
Louis Dionne
5f1ba3a502 [libc++] Synchronize clock selection between chrono.cpp and filesystem_clock.cpp
Note that _FilesystemClock will now be implemented by calling gettimeofday()
on Apple platforms instead of clock_gettime(). However, since both are
equivalent, this should not change the behavior on Apple platforms.
There should be no behavior change on other platforms.

In addition to being a consistency clean up, this fixes some issues seen
by folks as reported in https://reviews.llvm.org/D154390#4471924.

Differential Revision: https://reviews.llvm.org/D154457
2023-07-05 08:38:20 -04:00
Louis Dionne
fc5e76da22 [libc++] Reformat status tables
We use 17.0 instead of Clang 17 in our status tables pretty consistently,
but not universally. This ensures that we do it universally, for all
versions.

Differential Revision: https://reviews.llvm.org/D154461
2023-07-05 08:37:19 -04:00
Dmitry Ilvokhin
78addb2c32 Use hash value checks optimizations consistently
There are couple of optimizations of `__hash_table::find` which are applicable
to other places like `__hash_table::__node_insert_unique_prepare` and
`__hash_table::__emplace_unique_key_args`.

```
for (__nd = __nd->__next_; __nd != nullptr &&
    (__nd->__hash() == __hash
    // ^^^^^^^^^^^^^^^^^^^^^^
    //         (1)
      || std::__constrain_hash(__nd->__hash(), __bc) == __chash);
                                               __nd = __nd->__next_)
{
    if ((__nd->__hash() == __hash)
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^
    //           (2)
        && key_eq()(__nd->__upcast()->__value_, __k))
        return iterator(__nd, this);
}
```

(1): We can avoid expensive modulo operations from `std::__constrain_hash` if
hashes matched. This one is from commit 6a411472e3.
(2): We can avoid `key_eq` calls if hashes didn't match. Commit:
318d35a7bc.

Both of them are applicable for insert and emplace methods.

Results of unordered_set_operations benchmark:

```
Comparing /tmp/main to /tmp/hashtable-hash-value-optimization
Benchmark                                                                 Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------------------------
BM_Hash/uint32_random_std_hash/1024                                    -0.0127         -0.0127          1511          1492          1508          1489
BM_Hash/uint32_random_custom_hash/1024                                 +0.0012         +0.0013          1370          1371          1367          1369
BM_Hash/uint32_top_std_hash/1024                                       -0.0027         -0.0028          1502          1497          1498          1494
BM_Hash/uint32_top_custom_hash/1024                                    +0.0033         +0.0032          1368          1373          1365          1370
BM_InsertValue/unordered_set_uint32/1024                               +0.0267         +0.0266         36421         37392         36350         37318
BM_InsertValue/unordered_set_uint32_sorted/1024                        +0.0230         +0.0229         28247         28897         28193         28837
BM_InsertValue/unordered_set_top_bits_uint32/1024                      +0.0492         +0.0491         31012         32539         30952         32472
BM_InsertValueRehash/unordered_set_top_bits_uint32/1024                +0.0523         +0.0520         62905         66197         62780         66043
BM_InsertValue/unordered_set_string/1024                               -0.0252         -0.0253        300762        293189        299805        292221
BM_InsertValueRehash/unordered_set_string/1024                         -0.0932         -0.0920        332924        301882        331276        300810
BM_InsertValue/unordered_set_prefixed_string/1024                      -0.0578         -0.0577        314239        296072        313222        295137
BM_InsertValueRehash/unordered_set_prefixed_string/1024                -0.0986         -0.0985        336091        302950        334982        301995
BM_Find/unordered_set_random_uint64/1024                               -0.1416         -0.1417         16075         13798         16041         13769
BM_FindRehash/unordered_set_random_uint64/1024                         -0.0105         -0.0105          5900          5838          5889          5827
BM_Find/unordered_set_sorted_uint64/1024                               +0.0014         +0.0014          2813          2817          2807          2811
BM_FindRehash/unordered_set_sorted_uint64/1024                         -0.0247         -0.0249          5863          5718          5851          5706
BM_Find/unordered_set_sorted_uint128/1024                              +0.0113         +0.0112         15570         15746         15539         15713
BM_FindRehash/unordered_set_sorted_uint128/1024                        +0.0438         +0.0441          6917          7220          6902          7206
BM_Find/unordered_set_sorted_uint32/1024                               -0.0020         -0.0020          3098          3091          3092          3085
BM_FindRehash/unordered_set_sorted_uint32/1024                         +0.0570         +0.0569          5377          5684          5368          5673
BM_Find/unordered_set_sorted_large_uint64/1024                         +0.0081         +0.0081          3594          3623          3587          3616
BM_FindRehash/unordered_set_sorted_large_uint64/1024                   -0.0542         -0.0540          6154          5820          6140          5808
BM_Find/unordered_set_top_bits_uint64/1024                             -0.0061         -0.0061         10440         10377         10417         10353
BM_FindRehash/unordered_set_top_bits_uint64/1024                       +0.0131         +0.0128          5852          5928          5840          5914
BM_Find/unordered_set_string/1024                                      -0.0352         -0.0349        189037        182384        188389        181809
BM_FindRehash/unordered_set_string/1024                                -0.0309         -0.0311        180718        175142        180141        174532
BM_Find/unordered_set_prefixed_string/1024                             -0.0559         -0.0557        190853        180177        190251        179659
BM_FindRehash/unordered_set_prefixed_string/1024                       -0.0563         -0.0561        182396        172136        181797        171602
BM_Rehash/unordered_set_string_arg/1024                                -0.0244         -0.0241         27052         26393         26989         26339
BM_Rehash/unordered_set_int_arg/1024                                   -0.0410         -0.0410         19582         18779         19539         18738
BM_InsertDuplicate/unordered_set_int/1024                              +0.0023         +0.0025         12168         12196         12142         12173
BM_InsertDuplicate/unordered_set_string/1024                           -0.0505         -0.0504        189238        179683        188648        179133
BM_InsertDuplicate/unordered_set_prefixed_string/1024                  -0.0989         -0.0987        198893        179222        198263        178702
BM_EmplaceDuplicate/unordered_set_int/1024                             -0.0175         -0.0173         12674         12452         12646         12427
BM_EmplaceDuplicate/unordered_set_string/1024                          -0.0559         -0.0557        190104        179481        189492        178934
BM_EmplaceDuplicate/unordered_set_prefixed_string/1024                 -0.1111         -0.1110        201233        178870        200608        178341
BM_InsertDuplicate/unordered_set_int_insert_arg/1024                   -0.0747         -0.0745         12993         12022         12964         11997
BM_InsertDuplicate/unordered_set_string_insert_arg/1024                -0.0584         -0.0583        191489        180311        190864        179731
BM_EmplaceDuplicate/unordered_set_int_insert_arg/1024                  -0.0807         -0.0804         35946         33047         35866         32982
BM_EmplaceDuplicate/unordered_set_string_arg/1024                      -0.0312         -0.0310        321623        311601        320559        310637
OVERALL_GEOMEAN                                                        -0.0276         -0.0275             0             0             0             0
```

Time differences looks more like noise to me. But if we want to have this
optimizations in `find`, we probably want them in `insert` and `emplace` as
well.

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D140779
2023-07-04 21:01:08 +02:00
Edoardo Sanguineti
0529025648 [libc++] Use this in lamba capture in <latch>
"&" seemed to be used in a situation where perhaps it's not the best option.
Other libc++ modules make use of [this] when calling functions from the same class.
[this] would be the appropriate lambda capture specifier to use in this situation.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154358
2023-07-04 20:43:56 +02:00
Piotr Fusik
a4bc96d38a [NFC][libc++] Fix whitespace in sstream
Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D154455
2023-07-04 20:42:08 +02:00
Louis Dionne
ba3619b927 [libc++] Avoid including things that require a filesystem in filesytem_clock.cpp
The filesystem clock implementation should be available regardless of
whether a proper filesystem is available on the platform, so it makes
sense to try and avoid including things that are inherently filesystem-y
in the implementation of filesystem clock.

Differential Revision: https://reviews.llvm.org/D154390
2023-07-04 14:29:00 -04:00
Louis Dionne
b7bc8033f1 [libc++][NFC] Sort list of attribute macros in the .clang-format file 2023-07-04 11:25:46 -04:00
Louis Dionne
2d7eb9c9ea [libc++][NFC] clang-format <shared_mutex>
I am about to touch several lines in that file for a patch anyway, so
I might as well clang-format it upfront to avoid mixing styles after
my patch.
2023-07-04 11:20:21 -04:00
Hans Wennborg
1e35e93e30 [libc++] Disable tree invariant check in asserts mode
This is a follow-up to D153672 which removed the old debug mode and
moved many of those checks to the regular asserts mode.

The tree invariant check is too expensive for the regular asserts mode,
making element removal O(n) instead of O(log n), so disable it until
there is a new debug assert category it can be put in.

Differential revision: https://reviews.llvm.org/D154417
2023-07-04 15:36:15 +02:00
Nikolas Klauser
e18e17aa47 [libc++][NFC] Remove a redundant check for building the library 2023-07-03 18:35:37 -07:00
Ian Anderson
ebd2ed2aa8 [libc++][Modules] std.functional.__functional.invoke and std.type_traits.underlying_type can't export std.type_traits
`__functional/invoke.h` currently only includes `__type_traits/invoke.h` and not all of `type_traits`. Keep it using the specific header, and update its export. Similarly, `__type_traits/underlying_type.h` currently only includes `__type_traits/is_enum.h`, so update its export as well. This requires adding lots of export statements to the module map to keep the transitive includes working. Adding direct includes to the headers fixes `check-cxx`, but leaves many `run-buildbot generic-modules` tests failing, some even with linker errors.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D153832
2023-07-03 13:59:59 -07:00
Louis Dionne
8dcb8ea75c [libc++] Remove support for .fail.cpp tests
We want to move away from those tests and towards explicit .verify.cpp
tests, since those have a simpler model.

Differential Revision: https://reviews.llvm.org/D153982
2023-07-03 15:38:37 -04:00
Louis Dionne
b82dcb624e [libc++] Move all the remaining .fail.cpp tests to .verify.cpp
I made sure they all had some expected-error output in them. Many of
these tests would be better implemented as a positive test using SFINAE,
but this is beyond the scope of this patch.

Differential Revision: https://reviews.llvm.org/D153980
2023-07-03 09:41:03 -04:00
Louis Dionne
60a6a0d17a [libc++] Add missing includes
Those were found while trying to enable configurations like no-threads
and no-localization with Clang modules enabled.

Differential Revision: https://reviews.llvm.org/D153977
2023-07-03 09:40:09 -04:00
Amirreza Ashouri
f4ec54b51b Fix typo "__is_parititioned_impl" to "__is_partitioned_impl"
A typo has been fixed

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D154296
2023-07-02 16:56:32 +02:00
Piotr Fusik
81ad5a5cb8 [libc++] Implement stringbuf members of P0408R7 (Efficient Access to basic_stringbuf's Buffer)
Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D153709
2023-07-01 13:43:08 +02:00
Mark de Wever
5bf142749e [libc++][doc] Updates spaceship status.
Work on the missing chrono parts has started, but their operators will
be added in different patches. So split the remaining chrono part to one
entry per line and mark them in progress.
2023-07-01 12:37:02 +02:00
Mark de Wever
0fa67d44e0 [libc++] Enables constexpr string tests.
These tests were disabled during constant evaluation in D90569. At that
time constexpr string was not implemented. It now is.

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D154227
2023-07-01 12:26:48 +02:00
Amirreza Ashouri
bf17b08b45 correct misspelled _LIBCPP___TYPE_TRAITS_IS_EQUAILITY_COMPARABLE_H to _LIBCPP___TYPE_TRAITS_IS_EQUALITY_COMPARABLE_H
I just corrected a mistakenly misspelled macro

Reviewed By: philnik, #libc

Spies: libcxx-commits, #llvm, philnik

Differential Revision: https://reviews.llvm.org/D154252
2023-06-30 13:51:48 -07:00
Nikolas Klauser
c4e98722ca [libc++] Fix std::copy and std::move for ranges with potentially overlapping tail padding
This fixes thr bug reported in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108846.

Reviewed By: ldionne, #libc

Spies: mstorsjo, libcxx-commits

Differential Revision: https://reviews.llvm.org/D151953
2023-06-30 13:48:16 -07:00
Louis Dionne
f13e1a65ca [libc++] Revert __uninitialized_buffer changes
This patch reverts the following commits:

    015cd317ea (add missing HIDE_FROM_ABI)
    420a204d52 (add _LIBCPP_NO_CFI)
    31eeba3f7c (add __uninitialized_buffer)

It also reverts a small part of b935ab8e74
which is required to make the stable_partition.pass.cpp test pass on GCC.

Some issues were pointed out in https://reviews.llvm.org/D152208 and
in https://reviews.llvm.org/D154017, so I am reverting this patch
until we have time to weigh the various solutions and get consensus
on the design of the API.

Differential Revision: https://reviews.llvm.org/D154161
2023-06-30 09:17:24 -04:00
Ian Anderson
40cdb220f5 [libc++][Modules] Make module exports consistent with header includes
Some modules export modules that they don't import (i.e. that their header doesn't directly include). That sometimes works when the exported submodule is in the same module, but when the `std` mega module is broken up (D144322), some of the exports stop working. Make the exports and includes consistent, either by adding includes for the exports, or by removing exports for missing includes.

The `concepts.equality_comparable` export in `std.iterator.__iterator.concepts` isn't doing anything because 1) it's resolved as `std.iterator.__iterator.concepts.equality_comparable` and 2) there's a `__concepts` submodule in between `std.concepts` and `equality_comparable`. Fix it to be `std.concepts.__concepts.equality_comparable`.

<span> is listed in both `std.span` and `std.experimental.span`. Delete the latter module.
There is no `__errc` module or header, so remove that export from `std.system_error`.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D153211
2023-06-29 15:37:03 -07:00
varconst
b5270ba20d [libc++] Remove the legacy debug mode.
See https://discourse.llvm.org/t/rfc-removing-the-legacy-debug-mode-from-libc/71026

Reviewed By: #libc, Mordante, ldionne

Differential Revision: https://reviews.llvm.org/D153672
2023-06-29 14:49:51 -07:00
Louis Dionne
e7c63c0e90 [libc++] Stop using __builtin_assume in _LIBCPP_ASSERT
__builtin_assume can sometimes worsen code generation. For now, the
guideline seems to be to avoid adding assumptions without a clear
optimization intent. Since _LIBCPP_ASSERT is very general, we can't
have a clear optimization intent at this level, which makes
__builtin_assume the wrong tool for the job -- at least until
__builtin_assume is changed.

See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609
for a discussion of this.

Differential Revision: https://reviews.llvm.org/D153968
2023-06-29 16:59:29 -04:00
Christian Trott
b4ff893877 [libc++][mdspan] Implement layout_left
This commit implements layout_left in support of C++23 mdspan
(https://wg21.link/p0009). layout_left is a layout mapping policy
whose index mapping corresponds to the memory layout of Fortran arrays.
Thus the left most index has stride-1 access, and the right most index
is associated with the largest stride.

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

Differential Revision: https://reviews.llvm.org/D153783
2023-06-29 14:01:08 -06:00
Mark de Wever
9595a18de1 [NFC][libc++] Use a better type_trait to show the intention. 2023-06-29 19:56:28 +02:00
Christian Trott
cfa096d9c9 [libc++][mdspan] Implement layout_right
This commit implements layout_right in support of C++23 mdspan
(https://wg21.link/p0009). layout_right is a layout mapping policy
whose index mapping corresponds to the memory layout of multidimensional
C-arrays, and is thus also referred to as the C-layout.

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

Differential Revision: https://reviews.llvm.org/D151267
2023-06-29 10:12:17 -04:00
varconst
cd0ad4216c [libc++][hardening][NFC] Introduce _LIBCPP_ASSERT_UNCATEGORIZED.
Replace most uses of `_LIBCPP_ASSERT` with
`_LIBCPP_ASSERT_UNCATEGORIZED`.

This is done as a prerequisite to introducing hardened mode to libc++.
The idea is to make enabling assertions an opt-in with (somewhat)
fine-grained controls over which categories of assertions are enabled.
The vast majority of assertions are currently uncategorized; the new
macro will allow turning on `_LIBCPP_ASSERT` (the underlying mechanism
for all kinds of assertions) without enabling all the uncategorized
assertions (in the future; this patch preserves the current behavior).

Differential Revision: https://reviews.llvm.org/D153816
2023-06-28 15:10:31 -07:00
Nikolas Klauser
015cd317ea [libc++] Add missing _LIBCPP_HIDE_FROM_ABI in uninitialized_buffer.h 2023-06-28 11:22:26 -07:00
varconst
be02f912d6 [libc++][hardening] Add an ABI macro _LIBCPP_ABI_BOUNDED_ITERATORS.
Use the new macro instead of `_LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING`.

Differential Revision: https://reviews.llvm.org/D153895
2023-06-27 16:41:29 -07:00
Nikolas Klauser
420a204d52 [libc++] Add _LIBCPP_NO_CFI to __make_uninitialized_buffer
CFI doen't allow casting uninitialized memory to a type, resulting in a
crash in `__make_uninitialized_buffer`.
2023-06-27 15:48:57 -07:00
Vitaly Buka
c4bd5977f4 [libcxx] Add new line after assert message
Abort signal handler may print aswell. Without new line it goes into the
same.

Reviewed By: #libc, philnik, Mordante

Differential Revision: https://reviews.llvm.org/D142184
2023-06-27 13:32:41 -07:00
Louis Dionne
5b55eb1e88 [lit] Add a method to lit.TestFormat to get the list of tests associated to a path
Lit TestFormat classes already needed to implement the getTestsInDirectory
method. However, some test formats may want to expand a single test path
to multiple Lit tests, for example in the case of a test that actually
generates other Lit tests.

To accommodate that, this commit adds the getTestsForPath method to
TestFormat. This method can be used to turn a single path in a Lit
test suite into a list of tests associated to that path.

Differential Revision: https://reviews.llvm.org/D151664
2023-06-27 16:27:08 -04:00
Ian Anderson
d5ce68afdf [libc++] __iterator/readable_traits.h isn't standalone
`__iterator/readable_traits.h` can't be used by itself, intantiating `iter_value_t` requires `__iterator/iterator_traits.h`. `readable_traits.h` can't include `iterator_traits.h` though because `iterator_traits.h` requires `readable_traits.h`.

Move `iter_value_t` to `__iterator/iterator_traits.h` so that both headers can work standalone.

Reviewed By: Mordante, #libc

Differential Revision: https://reviews.llvm.org/D153828
2023-06-27 10:52:08 -07:00
Mark de Wever
7da669d9e5 [libc++][doc] Fixes header formatting.
This was broken in D145628; it caused the new header not to be displayed
as a header at all and show part of the markup as text.
2023-06-27 18:42:51 +02:00
Louis Dionne
6d6e32895b [libc++][NFC] Add missing includes to perfect_forward.h
Differential Revision: https://reviews.llvm.org/D153807
2023-06-27 09:46:36 -04:00
Louis Dionne
c352fa7407 [libc++] Expand the contents of LIBCXX_ENABLE_FILESYSTEM
Since LIBCXX_ENABLE_FILESYSTEM now truly represents whether the
platform supports a filesystem (as opposed to whether the <filesystem>
library is provided), we can provide a few additional classes from
the <filesystem> library even when the platform does not have support
for a filesystem. For example, this allows performing path manipulations
using std::filesystem::path even on platforms where there is no actual
filesystem.

rdar://107061236

Differential Revision: https://reviews.llvm.org/D152382
2023-06-27 09:18:40 -04:00
Advenam Tacet
10ec9276d4 [2a/3][ASan][libcxx] std::deque annotations
This revision is a part of a series of patches extending AddressSanitizer C++ container overflow detection capabilities by adding annotations, similar to those existing in `std::vector`, to `std::string` and `std::deque` collections. These changes allow ASan to detect cases when the instrumented program accesses memory which is internally allocated by the collection but is still not in-use (accesses before or after the stored elements for `std::deque`, or between the size and capacity bounds for `std::string`).

The motivation for the research and those changes was a bug, found by Trail of Bits, in a real code where an out-of-bounds read could happen as two strings were compared via a std::equals function that took `iter1_begin`, `iter1_end`, `iter2_begin` iterators (with a custom comparison function). When object `iter1` was longer than `iter2`, read out-of-bounds on `iter2` could happen. Container sanitization would detect it.

This revision introduces annotations for `std::deque`. Each chunk of the container can now be annotated using the `__sanitizer_annotate_double_ended_contiguous_container` function, which was added in the rG1c5ad6d2c01294a0decde43a88e9c27d7437d157. Any attempt to access poisoned memory will trigger an ASan error. Although false negatives are rare, they are possible due to limitations in the ASan API, where a few (usually up to 7) bytes before the container may remain unpoisoned. There are no false positives in the same way as with `std::vector` annotations.

This patch only supports objects (deques) that use the standard allocator. However, it can be easily extended to support all allocators, as suggested in the D146815 revision.

Furthermore, the patch includes the addition of the `is_double_ended_contiguous_container_asan_correct` function to `libcxx/test/support/asan_testing.h`. This function can be used to verify whether a `std::deque` object has been correctly annotated.

Finally, the patch extends the unit tests to verify ASan annotations (added LIBCPP_ASSERTs).
If a program is compiled without ASan, all helper functions will be no-ops. In binaries with ASan, there is a negligible performance impact since the code from the change is only executed when the deque container changes in size and it’s proportional to the change. It is important to note that regardless of whether or not these changes are in use, every access to the container's memory is instrumented.

If you have any questions, please email:
- advenam.tacet@trailofbits.com
- disconnect3d@trailofbits.com

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D132092
2023-06-27 06:55:09 +02:00
Nikolas Klauser
f6d557ee34 [clang][NFC] Remove trailing whitespaces and enforce it in lib, include and docs
A lot of editors remove trailing whitespaces. This patch removes any trailing whitespaces and makes sure that no new ones are added.

Reviewed By: erichkeane, paulkirth, #libc, philnik

Spies: wangpc, aheejin, MaskRay, pcwang-thead, cfe-commits, libcxx-commits, dschuff, nemanjai, arichardson, kbarton, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, Jim, s.egerton, sameer.abuasal, apazos, luismarques, martong, frasercrmck, steakhal, luke

Differential Revision: https://reviews.llvm.org/D151963
2023-06-26 09:34:36 -07:00
Mark de Wever
9a2561a7be [libc++] Silences an invalid compiler diagnostic.
When the value is not initialized it's never used. However silencing the
warning is trivial, as suggested by BlamKiwi.

Fixes https://llvm.org/PR63421
2023-06-26 18:15:58 +02:00
Mark de Wever
af7c22b735 [libc++][doc] Fixes a typo.
Thanks to ChuanqiXu for spotting it.
2023-06-26 17:09:22 +02:00
Louis Dionne
21853b9645 [libc++][filesystem] Avoid using anonymous namespaces in support headers
This avoids using anonymous namespaces in headers and ensures that
the various helper functions get deduplicated across the TUs
implementing <filesystem>. Otherwise, we'd get a definition of
these helper functions in each TU where they are used, which is
entirely unnecessary.

Differential Revision: https://reviews.llvm.org/D152378
2023-06-26 09:35:26 -04:00
yronglin
9f6439f1c5 [libc++][ranges] Implement P2494R2 (Relaxing range adaptors to allow for move only types)
Implement P2494R2 `Relaxing range adaptors to allow for move only types`

https://open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2494r2.html#wording-ftm

According to the words in P2494R2, I haven't add new test for `drop_while_view`, `take_while_view` and `filter_view`, because these views has the requirement that the predicate is an `indirect_unary_predicate`, which requires that the predicate is `copy_constructible`, so they still can't accept move only types as predicate.

```
[P2483R0] also suggests future work to relax the requirements on the predicate types stored by standard views. This paper does not perform this relaxation, as the copy constructibility requirement is enshrined in the indirect callable concepts ([indirectcallable.indirectinvocable]). Thus, while this paper modifies the views that currently use copyable-box for user provided predicates, it only does so to apply the rename of the exposition-only type to movable-box; it does not change any of the constraints on those views. It does, however, relax the requirements on invocables accepted by the transform family of views, because those are not constrained using the indirect callable concepts.
```

Reviewed By: #libc, var-const

Differential Revision: https://reviews.llvm.org/D151629
2023-06-25 08:15:52 +08:00
Ian Anderson
2af6d79c7e [libc++] Remove the type_traits includes from limits and new
type_traits is currently unable to include __type_traits/noexcept_move_assign_container.h, because it would cause several include cycles.

type_traits -> __type_traits/noexcept_move_assign_container.h -> __memory/allocator_traits.h -> __memory/construct_at.h -> new -> exception -> type_traits

type_traits -> __type_traits/noexcept_move_assign_container.h -> __memory/allocator_traits.h -> __memory/construct_at.h -> new -> type_traits

type_traits -> __type_traits/noexcept_move_assign_container.h -> __memory/allocator_traits.h -> limits -> type_traits

This is a problem for clang modules after the std mega module is broken up (D144322), because it becomes a module cycle which is a hard error.

Unconditionally remove the type_traits includes from limits and new in all versions, and also remove the exception include from new. (These are already removed in C++23.)

Reviewed By: ldionne, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D153214
2023-06-24 10:54:53 -07:00
Piotr Fusik
c0a5b147fa [libc++] Add noexcept clauses to swap per P0408R7 (Efficient Access to basic_stringbuf's Buffer)
Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D153427
2023-06-24 18:29:21 +02:00
Hristo Hristov
5f8e431597 [libc++][ranges] Addresses: LWG3719 - Directory iterators should be usable with default sentinel
Addresses:  LWG3719 - Directory iterators should be usable with default sentinel
https://wg21.link/LWG3719

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D153299
2023-06-24 17:54:47 +03:00
varconst
d9688b4635 [libc++][NFC] Fix incorrect return type of operator<=> in span test code. 2023-06-23 18:10:03 -07:00
Louis Dionne
b356928058 [libc++] Fix the check-format job
Previously, it wouldn't take into account files in ignore_format.txt
(at least not on OSX) because the `find` command would return file names
like `libcxx/src//new_handler.cpp`, which never matched the file names
in `ignore_format.txt`.

Differential Revision: https://reviews.llvm.org/D153416
2023-06-21 17:59:32 -04:00
Louis Dionne
bcca95da5e [libc++] Refactor the selection of string's ABI in __config
This doesn't change the selection, but it expands the conditions to
add comments and make it clearer what's happening. It also removes a
-Wundef instance when we checked __ARM_ARCH_7K__ >= 2 without checking
that it is defined in the first place.

Differential Revision: https://reviews.llvm.org/D153413
2023-06-21 17:53:57 -04:00
Petr Hosek
037952f6d4 [libcxx] Include <sys/time.h> in posix_compat.h
posix_compat.h uses struct timeval which is defined in <sys/time.h>
but it doesn't include it. On most POSIX platforms like Linux or macOS,
that headers is transitively included by other headers like <sys/stat.h>,
but there are other platforms where this is not the case.

Differential Revision: https://reviews.llvm.org/D153384
2023-06-21 16:10:01 +00:00
Louis Dionne
afc5cca0d4 [libc++] Get rid of _LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS
Whether we include operator new and delete into libc++ has always
been a build time setting, and piggy-backing on a macro like
_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS is inconsistent with how
we handle similar cases for e.g. LIBCXX_ENABLE_RANDOM_DEVICE. Instead,
simply avoid including new.cpp in the sources of the library when we
do not wish to include these operators in the build.

This also makes us much closer to being able to share the definitions
between libc++ and libc++abi, since we could technically build those
definitions into a standalone static library and decide whether we link
it into libc++abi.dylib or libc++.dylib.

Differential Revision: https://reviews.llvm.org/D153272
2023-06-21 09:01:24 -04:00
Louis Dionne
9ff36c24a0 [libc++] Guard terminate_successful with TEST_HAS_NO_EXCEPTIONS
This one is a bit twisted. Some platforms don't have support for
exiting in a clean manner, so they don't provide std::exit(). As
a result, defining `terminate_successful()` on those platforms won't
work, and the PSTL tests that rely on `terminate_successful()` also
won't work.

However, we don't have a notion of "no clean termination" in libc++,
so we can't properly guard this. Since embedded platforms that don't
support clean termination usually also don't enable exceptions, we
don't need to be able to run those `terminate_successful` PSTL tests,
and guarding the definition of `terminate_successful` with
TEST_HAS_NO_EXCEPTIONS works pretty well.

This is kind of a hack for the lack of having a concept of "no clean
termination" in the library and in the test suite.

Differential Revision: https://reviews.llvm.org/D153302
2023-06-21 08:34:51 -04:00
Mark de Wever
48abcf11ad [libc++][format] Adds formattable-with concept.
This change has a few additional effects:
- Abstract classes are now formattable.
- Volatile objects are no longer formattable.

Implements
- LWG3631 basic_format_arg(T&&) should use remove_cvref_t<T> throughout
- LWG3925 Concept formattable's definition is incorrect

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D152092
2023-06-21 08:05:33 +02:00
Louis Dionne
333384c5bc [libc++][NFC] clang-format filesystem_error.h
It's giving me trouble in an upcoming patch so I figured I'd do it as
a NFC before landing that other patch.
2023-06-20 16:27:26 -04:00
Louis Dionne
5a6e6adb91 [libc++] Make sure our .clang-format is used for all languages
In particular, this ensures that it is used for Objective-C and
Objective-C++, since we have a few files that get detected as that.

Differential Revision: https://reviews.llvm.org/D153289
2023-06-20 15:00:53 -04:00
Mark de Wever
59f266d2e2 [chrono][test] Fixes some tests on Windows.
The tests switched from assert to TEST_EQUAL to make it easier to debug
assertion failures. This is used to fix most tests on Windows.

Some CI tests give no output, which needs to be investigated separately.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D152062
2023-06-20 19:35:38 +02:00