1338 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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 491b2810fb7fe5f080fa9c4f5945ed0a6909dc92.

This change broke valid code and generated incorrect diagnostics, see
https://reviews.llvm.org/D155064
2023-09-27 18:58:01 +02: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
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
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
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
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
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
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
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
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
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
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
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
yronglin
9f67143be0 [libc++] Implement LWG3938 (Cannot use std::expected monadic ops with move-only error_type)
Implement LWG3938 (Cannot use std::expected monadic ops with move-only error_type)
https://wg21.link/LWG3938

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D154116
2023-09-06 22:38:29 +08:00
Mark de Wever
8930d04d55 [libc++][format] Fixes out of bounds access.
Fixes https://llvm.org/PR65011

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D158940
2023-08-30 17:40:58 +02:00
Louis Dionne
7a5ecbd891 [libc++][NFC] Fix typos in comments 2023-08-25 14:37:31 -04:00
Mark de Wever
ea82a822d9 [libc++] Adds string_view constructor overload
Implements
- P2697R1 Interfacing bitset with string_view

Depends on D153192

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D153201
2023-08-25 17:56:27 +02:00
Mark de Wever
92ac360063 [libc++][charconv] Adds operator bool.
Implements
- P2497R0 Testing for success or failure of <charconv> functions

Depends on D153192

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D153199
2023-08-23 19:25:10 +02:00
yrong
96377e5cc1 [libc++][expected] Implement LWG3836
Implement LWG3836 (https://wg21.link/LWG3836)
`std::expected<bool, E1>` conversion constructor `expected(const expected<U, G>&)` should take precedence over `expected(U&&)` with operator `bool`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D155701
2023-08-20 20:18:09 +08:00
Nikolas Klauser
925a11a5f2 [libc++] Simplify is_convertible
GCC 13 has added __is_convertible(), so we don't need to keep the fallback implementation around.

Reviewed By: #libc, Mordante

Spies: Mordante, libcxx-commits

Differential Revision: https://reviews.llvm.org/D157939
2023-08-15 12:18:36 -07:00
Nikolas Klauser
f29c54998d [libc++] Fix problems with GCC 13 and switch to it in the CI
Reviewed By: #libc, #libc_abi, Mordante

Spies: arphaman, Mordante, libcxx-commits, arichardson

Differential Revision: https://reviews.llvm.org/D157060
2023-08-14 16:54:50 -07:00
Nikolas Klauser
e30a148b09 [libc++] Remove generic char_traits implementation
This has been deprecated and should be removed now.

Reviewed By: #libc, Mordante

Spies: Mordante, libcxx-commits

Differential Revision: https://reviews.llvm.org/D157058
2023-08-09 15:55:28 -07:00
Konstantin Varlamov
000d2b8582 [libc++][hardening][NFC] Rework the Lit feature for detecting the hardening mode.
Make it a multichoice string to closer mirror the CMake variable. This
allows writing `UNSUPPORTED: libcpp-hardening-mode=unchecked` rather
than `UNSUPPORTED: !libcpp-has-hardened-mode && !libcpp-has-debug-mode`.

Differential Revision: https://reviews.llvm.org/D155906
2023-08-04 00:21:55 -07:00
Nikolas Klauser
5d976edd3f [libc++][NFC] Move libc++-specific unique_ptr test to test/libcxx 2023-07-28 10:32:33 -07:00
Konstantin Varlamov
91876eab93 [libc++] Increase the constexpr steps limit on some bitset tests.
Prevent these tests from failing on some platforms (the number of
constexpr steps increased by https://reviews.llvm.org/D154860).
2023-07-27 15:29:37 -07:00
varconst
66bd177a77 [libc++][hardening] Don't trigger uncategorized assertions in the hardened mode.
The hardened mode is intended to only include security-critical,
relatively low-overhead checks that are intended to be usable in
production. By default, assertions are excluded from this mode.

Differential Revision: https://reviews.llvm.org/D155866
2023-07-20 22:50:52 -07:00
Haowei Wu
310255abef [libcxx] Fix copy_move.pass test
When LLVM is built under MSVC and libcxx ABI is set to 2, the
'copy_move.pass' test will unexpectedly pass. This patch mitigate
this issue by setting this test will only expecting FAIL when libcxx
ABI version is set to 1.

This is a re-land of be9f55f4fff47badcdca17be5bcc0a4a15894739

Differential Revision: https://reviews.llvm.org/D155760
Fixes: https://github.com/llvm/llvm-project/issues/63442
2023-07-19 16:52:10 -07:00
Louis Dionne
b9a599cfe2 [libc++] Revert "[libcxx] Fix copy_move.pass test"
This reverts commit be9f55f4fff47badcdca17be5bcc0a4a15894739.

The commit was both not approved by the libc++ review group, and also
the only change it contained was incorrect.
2023-07-19 19:10:27 -04:00
Haowei Wu
be9f55f4ff [libcxx] Fix copy_move.pass test
When LLVM is built under MSVC and libcxx ABI is set to 2, the
'copy_move.pass' test will unexpectedly pass. This patch mitigate this
issue by setting this test will only expecting FAIL when libcxx ABI
version is set to 1.

Differential Revision: https://reviews.llvm.org/D155760
Fixes: https://github.com/llvm/llvm-project/issues/63442
2023-07-19 15:51:27 -07: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
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
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
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
Mark de Wever
2c07ca853b [NFC][libc++] Fixes some comments. 2023-07-16 11:34:41 +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
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
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
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
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