11496 Commits

Author SHA1 Message Date
Louis Dionne
d8278b6823
[libc++] Only include <setjmp.h> from the C library if it exists (#81887)
In 2cea1babefbb, we removed the <setjmp.h> header provided by libc++. However, we did not conditionally include the underlying <setjmp.h>
header only if the C library provides one, which we otherwise do consistently (see e.g. 647ddc08f43c).

rdar://122978778
2024-02-16 14:45:00 -07:00
LRFLEW
fc027e10ba
linear_congruential_engine: Fixes for __lce_alg_picker (#81080)
This fixes two major mistakes in the implementation of
`linear_congruential_engine` that allowed it to produce incorrect
output. Specifically, these mistakes are in `__lce_alg_picker`, which is
used to determine whether Schrage's algorithm is valid and needed.

The first mistake is in the definition of `_OverflowOK`. The code
comment and the description of [D65041](https://reviews.llvm.org/D65041)
both indicate that it's supposed to be true iff `m` is a power of two.
However, the definition used does not work out to that, and instead is
true whenever `m` is even. This could result in
`linear_congruential_engine` using an invalid implementation, as it
would incorrectly assume that any integer overflow can't change the
result. I changed the implementation to one that accurately checks if
`m` is a power of two. Technically, this implementation has an edge case
where it considers `0` to be a power of two, but in this case this is
actually accurate behavior, as `m = 0` indicates a modulus of 2^w where
w is the size of `result_type` in bits, which *is* a power of two.

The second mistake is in the static assert. The original static assert
erroneously included an unnecessary `a != 0 || m != 0`. Combined with
the `|| !_MightOverflow`, this actually resulted in the static assert
being impossible to fail. Applying De Morgan's law and expanding
`_MightOverflow` gives that the only way this static assert can be
triggered is if `a == 0 && m == 0 && a != 0 && m != 0 && ...`, which
clearly cannot be true. I simply removed the explicit checks against `a`
and `m`, as the intended checks are already included in `_MightOverflow`
and `_SchrageOK`, and their inclusion doesn't provide any obvious
semantic benefit.

This should fix all the current instances where
`linear_congruential_engine` uses an invalid implementation. This
technically isn't a complete implementation, though, since the static
assert will cause some instantiations of `linear_congruential_engine`
not disallowed by the standard from compiling. However, this should
still be an improvement, as all compiling instantiations of
`linear_congruential_engine` should use a valid implementation. Fixing
the cases where the static assert triggers will require adding
additional implementations, some of which will be fairly non-trivial, so
I'd rather leave those for another PR so they don't hold up these more
important fixes.

Fixes #33554
2024-02-15 19:46:22 +01:00
Po-yao Chang
08fe7df600
[libc++][format] Don't treat a closing '}' as part of format-spec (#81305)
This allows:
```
std::println("{}>42", std:🧵:id{});
std::println("{}>42", std::span<int>{});
std::println("{}>42", std::pair{42, "Hello"sv});
std::println("{:}>42", std:🧵:id{});
std::println("{:}>42", std::span<int>{});
std::println("{:}>42", std::pair{42, "Hello"sv});
```
to compile and run.
2024-02-16 02:41:07 +08:00
ZijunZhaoCCK
a6b846ae1e
[libc++][ranges] Implement ranges::contains_subrange (#66963) 2024-02-13 15:42:37 -08:00
Mark de Wever
fc0e9c8315
[libc++][modules] Re-add build dir CMakeLists.txt. (#81370)
This CMakeLists.txt is used to build modules without build system
support. This was removed in d06ae33ec32122bb526fb35025c1f0cf979f1090.
This is used in the documentation how to use modules.

Made some minor changes to make it work with the std.compat module using
the std module.

Note the CMakeLists.txt in the build dir should be removed once build
system support is generally available.
2024-02-13 20:04:34 +01:00
Abhina Sree
a70077ed8c
[SystemZ][z/OS][libcxx] mark aligned allocation tests XFAIL on z/OS (#80735)
zOS doesn't support aligned allocation, so mark these testcases as
unsupported.

Continuation of https://reviews.llvm.org/D102798
2024-02-13 08:03:14 -05:00
Hristo Hristov
d2ccf33933
[libc++][sstream] Explicitly delete special member functions (#80254)
The standard declares the copy constructors and copy assign operators as
deleted.

References:
- https://eel.is/c++draft/string.streams
2024-02-13 09:59:31 +02:00
Nikolas Klauser
f9d6d6fbcc
[libc++] Move the contents of __fwd/get.h into the forward declaration headers they actually belong to (#81368)
This brings us closer to one forward declaring header per public header.
2024-02-12 08:32:28 +01:00
Danny Mösch
00e80fbfb9
[NFC] Correct C++ standard names (#81421) 2024-02-11 19:43:34 +01:00
Mark de Wever
fe0d277f31
[libc++][ratio] Avoids accepting unrelated types. (#80491)
The arithmetic and comparison operators are ill-formed when R1 or R2 is
not a std::ratio.

Fixes: https://github.com/llvm/llvm-project/issues/63753
2024-02-11 13:53:59 +01:00
Mark de Wever
4fb7b3301b
[libc++][print] Moves is_terminal to the dylib. (#80464)
Having the test in the header requires including unistd.h on POSIX
platforms. This header has other declarations which may conflict with
code that uses named declarations provided by this header. For example
code using "int pipe;" would conflict with the function pipe in this
header.

Moving the code to the dylib means std::print would not be available on
Apple backdeployment targets. On POSIX platforms there is no transcoding
required so a not Standard conforming implementation is still a useful
and the observable differences are minimal. This behaviour has been done
for print before https://github.com/llvm/llvm-project/pull/76293.

Note questions have been raised in LWG4044 "Confusing requirements for
std::print on POSIX platforms", whether or not the isatty check on POSIX
platforms is required. When this LWG issue is resolved the
backdeployment targets could become Standard compliant.

This patch is intended to be backported to the LLVM-18 branch.

Fixes: https://github.com/llvm/llvm-project/issues/79782
2024-02-10 17:09:53 +01:00
Mark de Wever
f66f44eb0c [libc++][modules] Regenerates files.
After applying the review comments of
https://github.com/llvm/llvm-project/pull/80478
I've forgotten to update the generated files. This fixes the issue and
removes trailing whitespace.
2024-02-10 15:25:30 +01:00
Po-yao Chang
30cd1838dc
[libc++][modules] Fix disabling Unicode (#81294)
-DLIBCXX_ENABLE_UNICODE=OFF or -D_LIBCPP_HAS_NO_UNICODE doesn't build
without this change.
2024-02-10 15:22:16 +01:00
Mark de Wever
7d9540ea96
[libc++][chrono] Implements duration Rep constraints. (#80539)
Applies LWG3050 to the constraints of operator*, operator/, and
operator%. The changes to the constructor were done in
https://reviews.llvm.org/D118902, but that patch did not identify the
related LWG-issue, and only adjusted the constructor to the wording in
the Standard.

Implements:
- LWG 3050: Conversion specification problem in chrono::duration
constructor

---------

Co-authored-by: h-vetinari <h.vetinari@gmx.com>
2024-02-10 14:21:57 +01:00
Vlad Serebrennikov
c58c6aac77
[clang][Sema] Add checks for validity of default ctor's class (#78898)
Fixes #10518
Fixes #67914
Fixes #78388
Also addresses the second example in #49103

This patch is based on suggestion from @cor3ntin in
https://github.com/llvm/llvm-project/issues/67914#issuecomment-1896011898
2024-02-09 20:59:02 +04:00
Mark de Wever
4bf9fa5fb5
[libc++][modules] Guard missing header validation on Windows. (#80478)
On Windows the libc++ test suite sees the MSVC STL headers and may
conclude these are libc++ headers when inspecting the name. Modules
guard against forgetting to export new headers. Finding MSVC STL's
headers gives false positives. Since the CI tests non-Windows platforms
too, the validation will be disabled on Windows.

Fixes: https://github.com/llvm/llvm-project/issues/79010

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-02-09 17:41:46 +01:00
Mark de Wever
6d13961489
[libc++][test] Improves substitution naming (#80471)
Using the `-dir` suffix for directories makes it easier to understand.

Fixes: https://github.com/llvm/llvm-project/issues/78310
2024-02-09 17:40:08 +01:00
Mark de Wever
7291761669
[libc++] Fixes charconv operator bool tests. (#80598)
This was spotted by @philnik.
2024-02-09 17:30:30 +01:00
Mark de Wever
a5cc1dc82d
[NFC][libc++] Removes obsolete compiler support. (#80481)
These work-arounds were slated for removal in LLVM-18, but missed the
deadline.
2024-02-09 17:29:02 +01:00
Mark de Wever
4f423e4989
[libc++][test] Adds backdeployment shorthands. (#78204)
Some changes in libc++ affect the dylib. These changes are not present
on systems that use the system dylib. Currently that are the Apple
backdeployment targets. Figuring out which MacOS versions to target is
not trivial for non-Apple engineers. These shorthands make it easier to
select the proper feature make a test UNSUPPORTED or XFAIL.

During the design discussion with Louis we considered whether or not to
add preprocessor definitions to allow partial disabling of a test. This
would be useful when an existing feature is changed by modifying the
dylib. In the end we decided not to add this feature to avoid additional
complexity in the tests. Instead the test will be disabled for that
target.
2024-02-09 17:26:16 +01:00
Nikolas Klauser
1b5f691619
[libc++] Avoid including <cmath> in <compare> (#80418)
This reduces the time to include `<compare>` from 84ms to 36ms.
2024-02-08 19:23:10 +01:00
Nikolas Klauser
d272d944de
[libc++][NFC] Simplify the implementation of numeric_limits (#80425)
The cv specializations for `numeric_limits` inherited privately for some
reason. We can simplify the implementation by inheriting publicly and
removing the members that just replicate the values from the base class.
2024-02-08 19:22:49 +01:00
Nikolas Klauser
544f610d53
[libc++] Use __is_pointer_in_range inside vector::insert (#80624) 2024-02-08 19:22:16 +01:00
Louis Dionne
3e33b6f5de [libc++][NFC] Reformat a few files that had gotten mis-formatted
Those appear to be oversights when committing patches
in the last few months.
2024-02-08 10:12:42 -05:00
Nikolas Klauser
08457e1f76
[libc++] Add tests to pin down the ABI of deque, list and vector (#80191)
This patch adds tests that lock down the ABI of types like deque, list
and vector.
An upcoming patch will replace the usage of __compressed_pair in these
classes
by [[no_unique_address]], so we are adding these tests to pin down their
ABI
before making the change. That way, we can be confident that the patch
making
the actual ABI-sensitive change is safe if it doesn't break these tests.
2024-02-07 00:52:10 +01:00
Konstantin Varlamov
091fc81d48
[libc++][hardening] Check that _LIBCPP_HARDENING_MODE_DEFAULT is defined (#80353)
If the `_LIBCPP_HARDENING_MODE_DEFAULT` macro is not defined,
`_LIBCPP_HARDENING_MODE` will be considered defined but fail the check
for a valid hardening mode, resulting in a slightly less understandable
error (that error is really meant more to prevent users from passing
incorrect values such as `0` or `1` directly rather than catching
configuration issues).
2024-02-06 13:45:31 -08:00
Nikolas Klauser
e2cfdf7b6a
[libc++] Fix vector<const T> (#80711)
#80558 introduced code that assumed that the element type of `vector` is
never const. This fixes it and adds a test. Eventually we should remove
the `allocator<const T>` extension.
2024-02-05 15:51:32 -08:00
Louis Dionne
64a317ad07 [libc++][NFC] Fix typo in comment 2024-02-05 14:31:16 -05:00
Mark de Wever
04f99bec9a
[libc++][doc] Updates LWG3346 status. (#80536)
The issue addresses an obvious wording issue. Implementing the
constructors as specified in the synposis, as libc++ did, already
implements the fixed behaviour.

Updates:
- LWG3346 pair and tuple copy and move constructor have backwards
specification
2024-02-05 12:15:55 -05:00
Louis Dionne
09531e34ee [libc++] Add missing include of <wchar.h> in POSIX locale fallbacks 2024-02-05 12:04:07 -05:00
Rajveer Singh Bharadwaj
341d3a5999
[libc++] Fix ambiguity when using std::scoped_allocator constructor (#80261)
Fixes #78754
2024-02-05 11:41:36 -05:00
Dimitry Andric
1ec2522989
[libc++] Rename __bit_reference template parameter to avoid conflict (#80661)
As of 4d20cfcf4eb08217ed37c4d4c38dc395d7a66d26, `__bit_reference`
contains a template `__fill_n` with a bool `_FillValue` parameter.

Unfortunately there is a relatively widely used piece of scientific
software called NetCDF, which exposes a (C) macro `_FillValue` in its
public headers.

When building the NetCDF C++ bindings, this quickly leads to compilation
errors when the macro interferes with the template in `__bit_reference`.

Rename the parameter to `_FillVal` to avoid the conflict.
2024-02-05 17:41:12 +01:00
Louis Dionne
30f776f814
[libc++] Add missing <errno.h> include in threading support headers (#80311)
This was incorrectly removed when I split up the header.
2024-02-05 11:18:10 -05:00
Louis Dionne
f2c84211d2
[libc++] Add missing conditionals for feature-test macros (#80168)
We noticed that some feature-test macros were not conditional on
configuration flags like _LIBCPP_HAS_NO_FILESYSTEM. As a result, code
attempting to use FTMs would not work as intended.

This patch adds conditionals for a few feature-test macros, but more
issues may exist.

rdar://122020466
2024-02-05 11:05:46 -05:00
Louis Dionne
daea082082 [libc++] Add missing include of <string.h> in POSIX fallbacks for locale 2024-02-05 09:21:01 -05:00
Hui
825658856d
[libc++] fix counting_semaphore lost wakeups (#79265)
Fixes #77659
Fixes #46357

Picked up from https://reviews.llvm.org/D114119
2024-02-05 13:59:48 +00:00
Nikolas Klauser
4e112e5c1c
Reapply "[libc++] Optimize vector growing of trivially relocatable types" (#80558)
This reapplies #76657. Non-trivial elements didn't get destroyed
previously. This fixes the bug and adds tests for all the vector
insertion functions.
2024-02-04 00:28:29 +01:00
Nikolas Klauser
f87e3b61c8
[libc++] Move the locale support headers to __locale_dir/locale_base_api/ (#74522)
Differential Revision: https://reviews.llvm.org/D147869
2024-02-03 20:50:06 +01:00
Mark de Wever
5ca2777c69
[libc++] Fixes valarray proxy type compound assignment operations. (#76528)
The valarray<>::operator[](...) const functions return proxy objects.
The valarray<>::operator[](...) functions return valarray objects.

However the standard allows functions returning valarray objects to
return custom proxy objects instead. Libc++ returns __val_expr proxies.
Functions taking a valarray object must work with the custom proxies
too. Therefore several operations have a custom proxy overload instead
of valarray overloads.

Libc++ doesn't specify a valarray overload. This is an issue with the
standard proxy types; these can implicitly be converted to a valarray.

The solution is to allow the standard proxies to behave as-if they are
custom proxies.

This patch fixes the valarray compound assignments. Other operations,
like the binary non-member functions are not fixed. These will be done
in a followup patch.

Fixes: https://github.com/llvm/llvm-project/issues/21320
2024-02-03 17:23:31 +01:00
Kirill Stoimenov
2352fdd202 Revert "[libc++] Optimize vector growing of trivially relocatable types (#76657)"
Broke sanitizer bots: https://lab.llvm.org/buildbot/#/builders/5/builds/40641

This reverts commit 67eee4a029797c09129889c3655416d1be487cfe.
2024-02-02 20:43:51 +00:00
Mark de Wever
74fb205876
[libc++][format] Improves tests. (#76291)
Tests the returned type. This was first done for the vector<bool>
formatters. This adds it to the other formatters where it wasn't done
yet.
2024-02-02 19:55:36 +01:00
Nikolas Klauser
9cc2122bf5
[Clang][libc++] Implement __is_nothrow_convertible and use it in libc++ (#80436)
GCC 13 has implemented this builtin.
2024-02-02 19:15:58 +01:00
Nikolas Klauser
67eee4a029
[libc++] Optimize vector growing of trivially relocatable types (#76657)
This patch introduces a new trait to represent whether a type is
trivially
relocatable, and uses that trait to optimize the growth of a std::vector
of trivially relocatable objects.

```
--------------------------------------------------
Benchmark                           old        new
--------------------------------------------------
bm_grow<int>                    1354 ns    1301 ns
bm_grow<std::string>            5584 ns    3370 ns
bm_grow<std::unique_ptr<int>>   3506 ns    1994 ns
bm_grow<std::deque<int>>       27114 ns   27209 ns
```

This also changes to order of moving and destroying the objects when
growing the vector. This should not affect our conformance.
2024-02-02 17:13:55 +01:00
Nikolas Klauser
589b21f389 [libc++][NFC] Remove <__type_traits/alignment_of.h> include 2024-02-02 12:02:05 +01:00
Nikolas Klauser
ffb3589b8c
[libc++] Remove transitive <locale> include from <vector> (#80282)
This reduces the time to include `<vector>` from 468ms to 367ms.
2024-02-02 11:33:08 +01:00
Nikolas Klauser
ecb5a1b0e2
[libc++][NFC] Remove <experimental/__memory> (#80194)
The header is unused now, so we can remove it.
2024-02-01 19:11:51 +01:00
Hristo Hristov
7d78ccf7d5
[libc++][memory] P2652R2: Disallow Specialization of allocator_traits (#79978)
Implements P2652R2 <https://wg21.link/P2652R2>:
- https://eel.is/c++draft/allocator.requirements.general
- https://eel.is/c++draft/memory.syn
- https://eel.is/c++draft/allocator.traits.general
- https://eel.is/c++draft/allocator.traits.members
- https://eel.is/c++draft/diff.cpp20.concepts
- https://eel.is/c++draft/diff.cpp20.utilities

---------

Co-authored-by: Zingam <zingam@outlook.com>
2024-02-01 12:31:25 +01:00
Konstantin Varlamov
85a847fd1d
[libc++] Simplify features for detecting atomics' support. (#75553)
`non-lockfree-atomics` is very similar to `has-64-bit-atomics`; to
simplify, we can have uniform features for atomic types of
increasing sizes (`has-128-bit-atomics`, `has-256-bit-atomics`, etc.).

`is-lockfree-runtime-function` feature was a workaround for the partial
support for large atomic types on older versions of macOS (see
https://reviews.llvm.org/D91911). While we still support macOS 10.14,
conceptually it's simpler to check for support for all the atomic
functionality inside the `has-*-atomics` features, and the workaround is
no longer worth the maintenance cost.
2024-01-30 11:44:15 -08:00
Louis Dionne
e1ddc33312
[libc++] Move __libcpp_timespec_t into namespace std (#80004)
It was previously defined outside of namespace std for apparently no
good reason.
2024-01-30 13:53:14 -05:00
Louis Dionne
a3e35a4ea6 [libc++] Move scoped allocator adaptor test to .compile.pass.cpp 2024-01-30 09:59:51 -05:00