317 Commits

Author SHA1 Message Date
Damien L-G
557e931d95
[libc++] Implement P2897R7 aligned_accessor: An mdspan accessor expressing pointer over-alignment (#122603)
Closes #118372
2025-04-14 17:33:57 -04:00
Nikolas Klauser
af9c04fa68
[libc++] Remove _LIBCPP_TEMPLATE_VIS (#134885)
The need for `_LIBCPP_TEMPLATE_VIS` has been removed in #133233.
2025-04-09 23:47:57 +02:00
Nikolas Klauser
c13c04fdfe
[libc++] Simplify the implementation of the pointer aliases in allocator_traits (#127079) 2025-03-28 10:27:00 +01:00
Nikolas Klauser
a8e168e0c1
[libc++][NFC] Replace structs with variable templates in <__memory/allocator_traits.h> (#129237)
Variable templates are a bit easier on the compiler and improve the
readability of the code.
2025-03-25 15:58:24 +01:00
Nikolas Klauser
fb44f00641
[libc++] Add [[gnu::nodebug]] on type traits (#128502) 2025-03-23 21:01:25 +01:00
Mark de Wever
9feac2cbd0 [libc++] Improve deprecated diagnostic guards.
Recent Clang-21 builds improved the deprecated diagnotics. This
uncovered missing guards in libc++ internally.

Note: This patch should be a separate commit and not merged.
For testing purposes they are combined.

Reviewed as part of #130497.
2025-03-18 18:30:48 +01:00
Louis Dionne
c53caae1d0 [libc++][NFC] Remove dead link in comment 2025-03-17 13:39:58 -04:00
Mark de Wever
fd973d2512
[libc++] Protect more code against -Wdeprecated. (#130419)
This seems needed when updating the CI Docker image.
2025-03-09 17:33:59 +01:00
Mark de Wever
da618cf0a7
[NFC][libc++] Guard against operator& hijacking. (#128351)
This set usage of operator& instead of std::addressof seems not be easy
to "abuse". Some seem easy to misuse, like basic_ostream::operator<<,
trying to do that results in compilation errors since the `widen`
function is not specialized for the hijacking character type. Hence
there are no tests.
2025-02-27 17:47:34 +01:00
Louis Dionne
5e26fb1699
[libc++] Qualify calls to nullary functions like __throw_foo (#122465)
This is technically not necessary in most cases to prevent issues with ADL,
but let's be consistent. This allows us to remove the libcpp-qualify-declval
clang-tidy check, which is now enforced by the robust-against-adl clang-tidy check.
2025-02-21 07:59:46 -05:00
Nikolas Klauser
55b0fde20a
[libc++][NFC] Simplify unique_ptr a bit (#121230) 2025-02-14 10:08:23 +01:00
Louis Dionne
f332455dd9
[libc++] Extract destroy algorithms into separate headers (#126449)
This patch separates the destroy algorithms from the primitive
construct_at and destroy_at operations, which are conceptually not
algorithms. This makes it easier to start using these destroy algorithms
from upcoming relocation facilities.

As part of this, it also implements `std::destroy_at` for arrays without
relying on the `std::destroy` algorithm, which is conceptually a
higher-level facility.
2025-02-10 21:19:46 +01:00
A. Jiang
733a98db4a
[libc++] Fix input-only range handling for vector (#116157)
Changes:
- Carve out sized but input-only ranges for C++23.
- Call `std::move` for related functions when the iterator is possibly input-only.

Fixes #115727
2025-01-21 16:30:42 -05:00
PaulXiCao
438e2ccd4a
[libc++] Make std::stable_sort constexpr friendly (#110320)
Implementing `constexpr std::stable_sort`. This is part of P2562R1,
tracked via issue #105360.

Closes #119394

Co-authored-by: A. Jiang <de34@live.cn>
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-01-14 10:24:35 -05:00
Louis Dionne
cedb44af53
[libc++] Pass type information down to __libcpp_allocate (#118837)
Currently, places where we call __libcpp_allocate must drop type
information on the ground even when they actually have such information
available. That is unfortunate since some toolchains and system
allocators are able to provide improved security when they know what
type is being allocated.

This is the purpose of http://wg21.link/p2719, where we introduce a new
variant of `operator new` which takes a type in its interface. A
different but related issue is that `std::allocator` does not honor any
in-class `T::operator new` since it is specified to call the global
`::operator new` instead.

This patch closes the gap to make it trivial for implementations that
provide typed memory allocators to actually benefit from that
information in more contexts, and also makes libc++ forward-compatible
with future proposals that would fix the existing defects in
`std::allocator`. It also makes the internal allocation API higher level
by operating on objects instead of operating on bytes of memory.

Since this is a widely-used function and making this a template could
have an impact on debug info sizes, I tried minimizing the number of
templated layers by removing `__do_deallocate_handle_size`, which was
easy to replace with a macro (and IMO this leads to cleaner code).
2025-01-13 09:10:36 -05:00
Nikolas Klauser
f69585235e
[libc++] Put _LIBCPP_NODEBUG on all internal aliases (#118710)
This significantly reduces the amount of debug information generated
for codebases using libc++, without hurting the debugging experience.
2025-01-08 11:12:59 -05:00
Nikolas Klauser
b41d50aaa9 [libc++][NFC] Name unique_ptr function arguments __ptr and __deleter
This makes the code a bit more readable and users will see `ptr` and
`deleter` instead of `p` and `d` when using an IDE that shows the
argument names.
2024-12-22 03:03:42 +01:00
Nikolas Klauser
3b8faee6c6
[libc++] Switch _LIBCPP_NODEBUG to [[gnu::nodebug]] (#120720)
This makes the placement of the attribute more consistent. This also
avoids clang dropping the attribute silently (see #120722).
2024-12-22 00:55:35 +01:00
Nikolas Klauser
59890c1334
[libc++] Granularize <new> includes (#119964) 2024-12-17 11:29:16 +01:00
Louis Dionne
9474e09459
[libc++] Granularize the <new> header (#119270)
This disentangles the code which previously had a mix of many #ifdefs, a
non-versioned namespace and a versioned namespace. It also makes it
clearer which parts of <new> are implemented on Windows by including <new.h>.
2024-12-13 14:17:56 -05:00
cmtice
384e69a914
[libc++] Add _LIBCPP_NODEBUG on internal allocator trait aliases (#118835)
Put _LIBCPP_NODEBUG on the new allocator trait aliases introduced in
https://github.com/llvm/llvm-project/pull/115654. This prevents a large
increase in the gdb_index size that was introduced by that PR.
2024-12-06 08:53:56 -05:00
Louis Dionne
2393ab65ed
[libc++] Fix unintended ABI break in associative containers with reference comparators (#118685)
While reference comparators are a terrible idea and it's not entirely
clear whether they are supported, fixing the unintended ABI break is
straightforward so we should do it as a first step.

Fixes #118559
2024-12-05 15:56:00 -05:00
Nikolas Klauser
7ae61a36f9
[libc++] Add __detected_or_t and use it to implement some of the allocator traits aliases (#115654)
This simplifies the implementation a bit, since we don't need a lot of
the `__has_x` classes anymore. We just need two template aliases to
implement the `allocator_traits` aliases now.
2024-11-26 23:53:26 +01:00
Louis Dionne
748a29f052 [libc++][NFC] Fix incorrect include guard 2024-11-18 14:29:14 +01:00
Louis Dionne
5c3befb91c [libc++] Add forgotten call to std::__to_address in __uninitialized_allocator_relocate 2024-11-14 14:07:57 +01:00
Louis Dionne
6721bcfd1b
[libc++] Accept iterators instead of raw pointers in __uninitialized_allocator_relocate (#114552)
This generalizes the algorithm a bit. Unfortunately, we can't make 
the call sites cleaner inside std::vector because the arguments being
passed can all be fancy pointers, which may not be contiguous iterators.
2024-11-14 11:22:48 +01:00
Nikolas Klauser
67b81e2120
[libc++] Split __shared_count out of <__memory/shared_ptr.h> (#115943)
`__shared_count` is used in a few places where `shared_ptr` isn't. This
avoids a bunch of transitive includes needed for the implementation of
`shared_ptr` in these places.
2024-11-13 12:14:02 +01:00
Nikolas Klauser
c6f3b7bcd0
[libc++] Refactor the configuration macros to being always defined (#112094)
This is a follow-up to #89178. This updates the `<__config_site>`
macros.
2024-11-06 10:39:19 +01:00
Nikolas Klauser
5acc4a3dc0
[libc++] Remove <stddef.h> includes from the granularized <cstddef> headers (#114788)
We can define some of these aliases without having to include the system
<stddef.h> and there doesn't seem to be much of a reason we shouldn't do
it this way.
2024-11-06 10:38:19 +01:00
Nikolas Klauser
de87dda2da
[libc++][NFC] Use more appropriate type traits for a few cases (#114025) 2024-11-04 18:58:49 +01:00
Louis Dionne
dfe737f231
[libc++] Apply post-commit review comments for unique_ptr<T[]> hardening (#111704) 2024-11-04 10:45:12 -05:00
Nikolas Klauser
30213e99b8
[libc++] Use enable_if_t to constrain make_unique{,_for_overwrite} (#95044)
This improves the diagnostics a bit by using `enable_if_t` which clang
is aware of, instead of a custom SFINAE class, as well as writing the
functions in a more canonical style.

As a drive-by this also makes `__is_{,un}bounded_array` variable
templates instead of class templates.
2024-11-03 12:16:55 +01:00
Nikolas Klauser
e99c4906e4
[libc++] Granularize <cstddef> includes (#108696) 2024-10-31 02:20:10 +01:00
serge-sans-paille
71315698c9
[clang] Warn about memset/memcpy to NonTriviallyCopyable types (#111434)
This implements a warning that's similar to what GCC does in that
context: both memcpy and memset require their first and second operand
to be trivially copyable, let's warn if that's not the case.
2024-10-28 20:40:52 +00:00
Louis Dionne
3a30955cb7
[libc++] Remove obsolete _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF (#112745)
I don't know if that macro was ever truly defined by Clang, however it's
not anymore, so that is effectively dead code.
2024-10-18 08:32:47 -04:00
Nikolas Klauser
ba87515fea
[libc++][RFC] Always define internal feature test macros (#89178)
Currently, the library-internal feature test macros are only defined if
the feature is not available, and always have the prefix
`_LIBCPP_HAS_NO_`. This patch changes that, so that they are always
defined and have the prefix `_LIBCPP_HAS_` instead. This changes the
canonical use of these macros to `#if _LIBCPP_HAS_FEATURE`, which means
that using an undefined macro (e.g. due to a missing include) is
diagnosed now. While this is rather unlikely currently, a similar change
in `<__configuration/availability.h>` caught a few bugs. This also
improves readability, since it removes the double-negation of `#ifndef
_LIBCPP_HAS_NO_FEATURE`.

The current patch only touches the macros defined in `<__config>`. If
people are happy with this approach, I'll make a follow-up PR to also
change the macros defined in `<__config_site>`.
2024-10-12 09:49:52 +02:00
Louis Dionne
848b20de76
[libc++] Correctly handle custom deleters in hardened unique_ptr<T[]> (#110685)
It turns out that we can never do bounds-checking for unique_ptrs with
custom deleters, except when converting from a unique_ptr with a default
deleter to one with a custom deleter.

If we had an API like `std::make_unique` that allowed passing a custom
deleter, we could at least get bounds checking when the unique_ptr is
created through those APIs, but for now that is not possible.

Fixes #110683
2024-10-03 11:45:58 -04:00
A. Jiang
19c6958d24
[libc++] Re-apply LWG3870: Remove voidify (#110944)
This reverts commit f3d58f4161b86a479f68acb453e9622911c688a0.

Relands #110355.
2024-10-03 08:28:26 -04:00
Nikolas Klauser
d278fa5e1a
[libc++] Fix constant initialization of unique_ptr in C++17 and prior (#108956)
This is already tested in
`std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp`
except that `TEST_CONSTINIT` doesn't do anything before C++20 without
this patch.
2024-10-02 17:09:06 +02:00
serge-sans-paille
0eb26021d2
[libc++] Remove potential 0-sized array in __compressed_pair_padding (#109028) 2024-10-01 11:58:25 -04:00
Michael Buch
f3d58f4161
Revert "[libc++] LWG3870: Remove voidify (#110355)" (#110587)
This reverts commit 78f9a8b82d772ff04a12ef95f2c9d31ee8f3e409.

This caused the LLDB test `TestDataFormatterGenericOptional.py` to fail, and we need
a bit more time to look into it.
2024-10-01 08:57:03 -04:00
A. Jiang
78f9a8b82d
[libc++] LWG3870: Remove voidify (#110355)
Instead of changing the cast sequence to implicit conversion in
_`voidify`_, I think it is better to totally remove `__voidify` and use
`static_cast` to `void*`, which has equivalent effects.

Test coverage for const iterators are removed.

Now most affected algorithms are underconstrained, for which I submitted
[LWG3888](https://cplusplus.github.io/LWG/issue3888). I'm not sure
whether we should speculatively implement it at this moment, and thus
haven't added any `*.verify.cpp`.

In some control block types and `optional`, the stored objects are
changed to have cv-unqualified type.

Fixes #105119.
2024-10-01 01:24:00 +08:00
Louis Dionne
18df9d23ea [libc++] Add an ABI setting to harden unique_ptr<T[]>::operator[] (#91798)
This allows catching OOB accesses inside `unique_ptr<T[]>` when the size
of the allocation is known. The size of the allocation can be known when
the unique_ptr has been created with make_unique & friends or when the
type necessitates an array cookie before the allocation.

This is a re-aplpication of 45a09d181 which had been reverted in
f11abac6 due to unrelated CI failures.
2024-09-30 08:32:35 -04:00
Chris B
f11abac652
Revert "[libc++][modules] Rewrite the modulemap to have fewer top-level modules (#107638)" (#110384)
This reverts 3 commits:
45a09d1811d5d6597385ef02ecf2d4b7320c37c5
24bc3244d4e221f4e6740f45e2bf15a1441a3076
bc6bd3bc1e99c7ec9e22dff23b4f4373fa02cae3

The GitHub pre-merge CI has been broken since this PR went in. This
change reverts it to see if I can get the pre-merge CI working again.
2024-09-28 21:47:09 -05:00
Louis Dionne
45a09d1811
[libc++] Add an ABI setting to harden unique_ptr<T[]>::operator[] (#91798)
This allows catching OOB accesses inside `unique_ptr<T[]>` when the size
of the allocation is known. The size of the allocation can be known when
the unique_ptr has been created with make_unique & friends or when the
type necessitates an array cookie before the allocation.
2024-09-27 08:49:22 -04:00
A. Jiang
fd11c81a80
[libc++] Add _LIBCPP_NO_CFI to __allocate_unique_temporary_buffer (#109682)
Follows up #100914. Addresses the issue revealed in
https://github.com/llvm/llvm-project/pull/100914#discussion_r1771647801.
2024-09-24 09:29:34 +08:00
Louis Dionne
09e3a36058
[libc++][modules] Fix missing and incorrect includes (#108850)
This patch adds a large number of missing includes in the libc++ headers
and the test suite. Those were found as part of the effort to move
towards a mostly monolithic top-level std module.
2024-09-16 15:06:20 -04:00
A. Jiang
94e7c0b051
[libc++] Remove get_temporary_buffer and return_temporary_buffer (#100914)
Works towards P0619R4 / #99985.

The use of `std::get_temporary_buffer` and `std::return_temporary_buffer`
are replaced with `unique_ptr`-based RAII buffer holder.

Escape hatches:
- `_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER` restores
`std::get_temporary_buffer` and `std::return_temporary_buffer`.

Drive-by changes:
- In `<syncstream>`, states that `get_temporary_buffer` is now removed,
because `<syncstream>` is added in C++20.
2024-09-16 11:53:05 -04:00
Nikolas Klauser
27c83382d8
[libc++] Replace __compressed_pair with [[no_unique_address]] (#76756)
This significantly simplifies the code, improves compile times and
improves the object layout of types using `__compressed_pair` in the
unstable ABI. The only downside is that this is extremely ABI sensitive
and pedantically breaks the ABI for empty final types, since the address
of the subobject may change. The ABI of the whole object should not be
affected.

Fixes #91266
Fixes #93069
2024-09-16 11:08:57 +02:00
Nikolas Klauser
17e0686ab1
[libc++][NFC] Use [[__nodiscard__]] unconditionally (#80454)
`__has_cpp_attribute(__nodiscard__)` is always true now, so we might as
well replace `_LIBCPP_NODISCARD`. It's one less macro that can result in
bad diagnostics.
2024-09-12 21:18:43 +02:00