Drive-by: Rename `constexpr_noexcept.compile.pass.cpp` to
`ctor.default.pass.cpp` as test coverage is added to it, and compile and
run it in all modes.
Consistency improvements and other small tweaks.
A follow-up to https://github.com/llvm/llvm-project/pull/193891 - the
changes were deferred to reduce the size of an already large and
approved PR.
I believe these headers were relevant when we actually implemented
functions in `<cmath>`, but they are not anymore. Note that ::hypot in
particular is obtained from <math.h> like all the other math functions.
Co-authored-by: A. Jiang <de34@live.cn>
[mem.res.monotonic.buffer.ctor] requires initial_size to be greater than
zero for the two constructors that take one, but we silently accepted
zero. Add a hardening assertion for that precondition.
Fixes#213059
Two insert benchmarks were registered with lambdas capturing insert_iter_iter_bench
by reference, unlike every other registration in this file, which captures by value.
RegisterBenchmark() stores the lambda by value and only invokes it from
RunSpecifiedBenchmarks(), which happens long after associative_container_benchmarks()
has returned, creating a dangling reference.
This essentially copies the `.clang-tidy` file from libc++ into
libc++abi, except that the naming conventions are updated to not add
underscores and some checks are disabled that don't pass currently. They
will be fixed in follow-ups.
This PR adds an implementation of parallel
`std::lexicographical_compare()` based on parallel `std::mismatch()`.
The implementation is close to a one-liner:
```c++
auto __res = _Mismatch()(__policy, __first1, __last1, __first2, __last2, [&](_Ref1 __lhs, _Ref2 __rhs) {
return !__comp(__lhs, __rhs) && !__comp(__rhs, __lhs);
});
```
Included tests check that:
- Semantics of the iterator-only version is correct.
- Semantics of the predicated version is correct.
- The functions correctly SFINAE out when the first argument is not an
execution policy.
- The `noexcept` policy is followed.
- The `nodiscard` policy is followed.
- `static_assert` verifies iterators' categories.
Part of #99938.
This fixes incorrect expectations in:
```
libcxx/test/std/ranges/range.adaptors/range.adjacent/iterator/member_types.compile.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.zip.transform/iterator/member_types.compile.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.adjacent.transform/iterator/member_types.compile.pass.cpp
```
These iterators define difference_type as `range_difference_t<Base>`.
For `ForwardSizedView` and `InputCommonView`, the `difference_type` of
the underlying iterators is `std::intptr_t` in `test_iterators.h`.
The tests instead assert `std::ptrdiff_t`. That happens to hold on
platforms where `std::intptr_t` and `std::ptrdiff_t` are the same type,
but fails elsewhere.
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
This PR fixes a bug in `std::mersenne_twister_engine::seed(_Sseq&)`
where the initialization twist is bypassed when the vectorized engine
optimization (`_LIBCPP_ABI_VECTORIZED_MERSENNE_TWISTER_ENGINE`) is
enabled.
In the vectorized implementation introduced in #206423, the engine state
must be pre-twisted during initialization by calling
`__update_all_states()` at the end of the `seed` functions.
However, in `seed(_Sseq& __q)`, the all-zero state check contains an
early `return;` when a non-zero state is verified. This early return
bypasses the trailing `__update_all_states()` call. Consequently, the
generator is initialized with raw, untwisted seed values (tempered)
rather than the standard twisted values.
This only manifests when compiled with unstable ABI settings
(`_LIBCPP_ABI_VERSION >= 2`) which enables the vectorized
implementation.
I replaced the early `return;` inside the all-zero state verification
block with a loop break, and conditionalized the zero-state fix using
the loop index `__i`, ensuring `__update_all_states()` is always
executed at the end of the function. Added regression tests to
`seed_sseq.pass.cpp` asserting the exact deterministic outputs for both
32-bit and 64-bit engines.
Implements https://wg21.link/P3059R2 (DR)
Closes#189599
1. Made constructors of iterator and sentinel types of the following
views private:
- `iota_view`
- `basic_istream_view`
- `filter_view`
- `transform_view`
- `take_view`
- `take_while_view`
- `join_view`
- `lazy_split_view`
- `split_view`
- `elements_view`
2. Updated all relevant tests to fix the usages of the now private
constructor, including:
1. Removed now obsolete tests (files and cases).
2. Updated all relevant tests to get the iterators and the sentinels via
`begin()` and `end()`, wherever applicable .
3. Added test cases to confirm that P3059R2 was implemented properly.
4. Minor other (necessary) tweaks.
---------
Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: A. Jiang <de34@live.cn>
We have multiple macros for different Windows. However, most of them
don't actually define different things. We can condense the macros to
- `_WIN32` directly if it only depends on windows, or
- `_LIBCPP_MSVCRT`
This patch drops `_LIBCPP_MSVCRT_LIKE` and `_LIBCPP_WIN32API`, since
they are equivalent to `_WIN32`.
This refactors `streambuf` to contain a `_GetArea` and a `_PutArea`.
This makes the code significantly easier to read, since the pointers
belonging together are bundled in a struct.
Certain headers require `optional<T&>`, so it may be beneficial to split
out `optional<T>` and `optional<T&>`. This can allow consumers to only
bring in the `optional` flavour it needs..
- Parcel out the respective pieces into their own header.
- Certain sources rely on transitive includes brought in by
`<optional>`, so they're kept there for now, and only tests have been
fixed.
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
This PR implements a parallel `std::adjacent_find()` based on parallel
`std::mismatch`. The implementation reshapes the input range as two ranges
offset by 1 element and asks `std::mismatch` to find the first equal pair.
Part of #99938.
This verifies that libc++ has implemented the resolution of LWG3133,
which modernizes the requirements on `T` for `std::complex<T>` and
`std::valarray<T>` in [numeric.requirements].
- No code changes were needed for `std::valarray<T>`: its `operator[]`
already indexes through a raw pointer and never relies on a
user-overloadable `operator&`, so it already conforms to the revised
wording.
- Added o`perator_hijacker`-based tests to `valarray`'s
`access.pass.cpp`/`const_access.pass.cpp`, confirming `operator[]`
doesn't rely on a user-overloadable `operator&`.
The sequence containers were registered for 32, 1024 and 8192. This
patch drops the mid-size point to get roughly a 30% speedup when running
the benchmarks.
The string benchmarks instantiated every benchmark for char, char8_t and
wchar_t. char8_t exercises the same code paths as char, so drop it to
get roughly a 30% speedup on this benchmark time.
After #206453 we don't correctly handle `unget()` anymore. This fixes
the issue by updating the internal buffer to contain the tail of the
read data.
Fixes#210203
It was intentional in https://llvm.org/PR204116 that tests for
`operator<<`, `operator<<=`, `operator>>`, `operator>>=` used `bool`
operands, because `bool` is an integral type and thus satisfies the
constraints of these operators.
However, MSVC considers `bool` is unsafe as an operand of bitwise shift
operators and emits warning C4804. So this patch suppresses the warning
for MSVC.
Currently, library support for `_BitInt(N)` is an extension explicitly
supported by libc++. However, when using Clang with other standard
library implementations, `TEST_HAS_BITINT` is currently `1` as the
condition only detects compiler support of `_BitInt`.
This patch disables `_BitInt` coverage for other implementations for
now.
Fixes#99984
Implement P0528R3 The Curious Case of Padding Bits, Featuring Atomic
Compare-and-Exchange
The unit test padding.pass.cpp is assisted by Cursor. However, all tests
have been modified to test what I wanted to test
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
**_Implementation details_**:
- Use `is_unsigned_v` instead of `numeric_limits<Rep>::is_signed`, which
is used by `chrono::abs`. `numeric_limits<Rep>::is_signed` may return
false when a custom `Rep` does not specialize `numeric_limits`. Relying
on it to detect the unsigned case could therefore be unreliable for such
a type. `is_unsigned_v` instead gives a compile-time path for built-in
unsigned types, while the sign check keeps signed types correct.
- The constructor calls `__abs_d` four times because each member is
initialized separately. This should not affect runtime performance
because the compiler should inline `__abs_d` and eliminate the repeated
calculations. We could use another helper function or helper class to
explicitly compute the absolute duration only once. However, this would
add extra glue code, and the added complexity is not worthwhile I think.
---------
Co-authored-by: A. Jiang <de34@live.cn>
This PR adds a parallel version of `std::mismatch` as one of the backend
operations.
It also provides an implementation based on `__pstl::__parallel_find()`
which does the heavy lifting.
`libdispatch` and `std_thread` backends expose this implementation under
their backend tags, while the `serial` backend redirects the calls to
the serial `std::mismatch`.
4 flavours of the function are exposed: 3-legged, 3-legged with
predicate, 4-legged, 4-legged with predicate.
3-legged flavours are implemented in the `default` (`composition`)
backend by redirecting the call to the 4-legged flavours.
Included tests check that:
- Semantics of the iterator-only functions is correct.
- Semantics of the predicated functions is correct.
- Custom types are supported by the implementation.
- The functions correctly SFINAE out when the first argument is not an
execution policy.
- The `nodiscard` policy is followed.
- The `noexcept` policy is followed.
- `static_assert` verifies iterators' categories.
Part of #99938.
Papers:
- P0792R14: function_ref: a type-erased callable reference
- P3948R1 constant_wrapper is the only tool needed for passing constant
expressions via function arguments
- P3961R1 Less double indirection in function_ref (RU-220)
LWG issues:
- LWG4256: Incorrect constraints for function_ref constructors from
nontype_t
- LWG4425: CTAD function_ref of data member pointer should produce
noexcept signature
Fixes#189606Fixes#105376Fixes#189604Fixes#171321Fixes#171387
---------
Co-authored-by: Xiaoyang Liu <siujoeng.lau@gmail.com>
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
This updates the standard streams so that the buffers are replaced with
`basic_filebuf`s.
Fixes#21566
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
We already test the `_slow_path` and `_fast_path` functions through the
generic `BM_lexicographical_compare_three_way`. We don't need to
benchmark them again.
These benchmarks are expected to run for a very short time, and
`{Pause,Resume}Timing` should only be used when operations are expected
to take a long time. Removing them reduces the amount of noise in these
benchmarks.
Fixes#208719
Closes https://github.com/llvm/llvm-project/issues/105066.
When libc++ implemented `ranges::distance` in
c965d5448e, LWG3664 was implemented
together. The patch additionally changed cast result type from `const
decay_t<I>&` to `decay_t<I>`, which partially implemented LWG4242.
Currently, we are using `iter_difference_t<_Ip>` as the return type of
one `operator()` overload while LWG3664 modified that overload to return
`iter_difference_t<decay_t<_Ip>>`. The change is NFC because when
`iter_difference_t<decay_t<_Ip>>` is valid, `iter_difference_t<_Ip>` is
also valid and denotes the same type.
References:
- https://wg21.link/LWG3664
- https://eel.is/c++draft/range.iter.op.distance
---------
Co-authored-by: A. Jiang <de34@live.cn>
This was previously not required, but the patch to introduce a new
size-based vector layout unintentionally added this new requirement. We
almost certainly not want to promise this guarantee going forward, but
we should actually land this change explicitly and consider the
transition story, not do it as a fallout of another refactoring.
Fixes#210732
This PR adds a "one-liner" default implementation of parallel
`std::adjacent_difference` on top of parallel binary `std::transform`.
The implementation builds two iterator ranges out of the input one, so
that a zip of these ranges yields adjacent pairs. Then performs a binary
transform to calculate and output the adjacent differences.
Part of https://github.com/llvm/llvm-project/issues/99938
Closes#105418.
Since gcc does not currently support `__atomic_fetch_min/max`, we use a
CAS loop in `atomic_ref` and `support/gcc.h`.
---------
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>