6699 Commits

Author SHA1 Message Date
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
Louis Dionne
bc6bd3bc1e
[libc++][modules] Rewrite the modulemap to have fewer top-level modules (#107638)
This patch rewrites the modulemap to have fewer top-level modules.
Previously, our modulemap had one top level module for each header in
the library, including private headers. This had the well-known problem
of making compilation times terrible, in addition to being somewhat
against the design principles of Clang modules.

This patch provides almost an order of magnitude compilation time
improvement when building modularized code (certainly subject to
variations). For example, including <ccomplex> without a module cache
went from 22.4 seconds to 1.6 seconds, a 14x improvement.

To achieve this, one might be tempted to simply put all the headers in a
single top-level module. Unfortunately, this doesn't work because libc++
provides C compatibility headers (e.g. stdlib.h) which create cycles
when the C Standard Library headers are modularized too. This is
especially tricky since base systems are usually not modularized: as far
as I know, only Xcode 16 beta contains a modularized SDK that makes this
issue visible. To understand it, imagine we have the following setup:

   // in libc++'s include/c++/v1/module.modulemap
   module std {
      header stddef.h
      header stdlib.h
   }

   // in the C library's include/module.modulemap
   module clib {
      header stddef.h
      header stdlib.h
   }

Now, imagine that the C library's <stdlib.h> includes <stddef.h>,
perhaps as an implementation detail. When building the `std` module,
libc++'s <stdlib.h> header does `#include_next <stdlib.h>` to get the C
library's <stdlib.h>, so libc++ depends on the `clib` module.

However, remember that the C library's <stdlib.h> header includes
<stddef.h> as an implementation detail. Since the header search paths
for libc++ are (and must be) before the search paths for the C library,
the C library ends up including libc++'s <stddef.h>, which means it
depends on the `std` module. That's a cycle.

To solve this issue, this patch creates one top-level module for each C
compatibility header. The rest of the libc++ headers are located in a
single top-level `std` module, with two main exceptions. First, the
module containing configuration headers (e.g. <__config>) has its own
top-level module too, because those headers are included by the C
compatibility headers.

Second, we create a top-level std_core module that contains several
dependency-free utilities used (directly or indirectly) from the __math
subdirectory. This is needed because __math pulls in a bunch of stuff,
and __math is used from the C compatibility header <math.h>.

As a direct benefit of this change, we don't need to generate an
artificial __std_clang_module header anymore to provide a monolithic
`std` module, since our modulemap does it naturally by construction.

A next step after this change would be to look into whether math.h
really needs to include the contents of __math, and if so, whether
libc++'s math.h truly needs to include the C library's math.h header.
Removing either dependency would break this annoying cycle.

Thanks to Eric Fiselier for pointing out this approach during a recent
meeting. This wasn't viable before some recent refactoring, but wrapping
everything (except the C headers) in a large module is by far the
simplest and the most effective way of doing this.

Fixes #86193
2024-09-26 13:19:48 -04:00
Louis Dionne
78c6506543
[libc++] Disable the clang-tidy checks to get CI back (#109989)
The CI has been a complete mess for the past week, and the only thing
preventing it from being back is the Clang tidy checks. Disable them (as
a total hack) to get CI back.
2024-09-25 12:40:14 -04:00
Ryan Prichard
2d26fc8c6c
[libc++] Enable C++ stdatomic.h for all C++ versions (#95498)
This extension is motivated by Android's use of libc++, where
<stdatomic.h> has redirected to <atomic> for many years, long before it
was standardized in C++23.

When libc++'s stdatomic.h is included in C translation units, delegate
to the next stdatomic.h, which could come from Clang or libc.
2024-09-19 09:43:54 -04:00
Louis Dionne
c4a42f6115
[libc++] Fix the declarative generation of FTMs (#108843)
We were incorrectly computing whether a FTM has been implemented.
Instead of checking whether any version of the FTM is implemented for
the current Standard, we need to make sure that the correct version of
the FTM has been implemented.

As a drive-by fix, also correctly close the file that we load JSON from,
which was forgotten.
2024-09-17 14:27:37 -04:00
Jake Egan
e99755d41c
[libc++][test] Adjust expected hexfloat format (#95011)
The test expects a hex float format of `0x0p+0`, but AIX prints
`0x0.0p+0`. This change adjusts the test to accept both.
2024-09-16 16:21:41 -04:00
A. Jiang
2d13302d38
[libc++][test] Confirm that P0508R0 has been implemented (#108172)
The paper was implemented by commit b0386a515b60c
(https://reviews.llvm.org/D46845) in LLVM 7.0. But it would be nice to
have test coverage for desired properties of `insert_return_type`.

Closes #99944
2024-09-16 15:34:40 -04: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
Louis Dionne
165f0e80f6
[libc++][modules] Don't error when including <wchar.h> or <wctype.h> without wide character support (#108639)
Instead, make the headers empty like we do for all the other carve-outs.
2024-09-16 10:21:50 -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
Louis Dionne
9282c9d282 [libc++] Avoid name conflict with declaration in <unistd.h>
It appears that ::link is also declared as another kind of symbol
in <unistd.h>, which we seem to get transitively when we start using
a single top-level module. Instead of declaring these names as global
extern variables, use function parameters to achieve the same thing.
2024-09-13 09:16:17 -04:00
David Spickett
cdd608b8f0
[libcxx][test] Use smaller time range for 32 bit time_t (#104762)
This fixes the test on Arm 32 bit Ubuntu Jammy where time_t is 32 bit.
2024-09-13 09:14:53 +01:00
Robin Caloudis
c6b2aa1896
[libc++][math] Provide overloads for cv-unqualified floating point types for std::signbit (#106566)
## Why
Following up on https://github.com/llvm/llvm-project/pull/105946, this
patch provides the floating point overloads for `std::signbit` as
defined by
[P0533R9](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0533r9.pdf).

## What
* Test and add overloads for cv-unqualified floating point types
* Remove constrained overload as it is not needed anymore
* Make use of `template<class = void>` as the universal C runtime (UCRT)
needed for Clang-Cl comes with overloads for all cv-unqualified floating
point types (float, double, long double) for `std::signbit()` by itself
[in the
WinSDK](e012b29924/generation/WinSDK/RecompiledIdlHeaders/ucrt/corecrt_math.h (L309-L322)).
In a certain way, this can be seen as a deviation from the C standard.
We need to work around it as the compilation would otherwise error out
due to duplicated definitions.
2024-09-12 21:14:00 +02:00
Louis Dionne
33325524f5
[libc++][modules] Refactor poisoned_hash_helper (#108296)
The poisoned_hash_helper header was relying on an implicit forward
declaration of std::hash located in <type_traits>. When we improve the
modularization of the library, that causes issues, in addition to being
a fundamentally non-portable assumption in the test suite.

It turns out that the reason for relying on a forward declaration is to
be able to test that std::hash is *not* provided if we don't include any
header that provides it. But testing that is actually both non-portable
and not really useful.

Indeed, what harm does it make if additional headers provide std::hash
specializations? That would certainly be conforming -- the Standard
never requires an implementation to avoid providing a declaration when a
given header is included, instead it mandates what *must* be provided
for sure. In that spirit, it would be conforming for e.g. `<cstddef>` to
define the hash specializations if that was our desire. I also don't
read https://wg21.link/P0513R0 as going against that statement. Hence,
this patch just removes that test which doesn't carry its weight.

Fixes #56938
2024-09-12 15:07:49 -04:00
Louis Dionne
99174842ae
[libc++] Make std::jthread supported in non-experimental mode (#107900)
We waited before supporting std::jthread fully because we wanted to
investigate other implementation strategies (in particular one involving
std::mutex). Since then, we did some benchmarking and decided that we
wouldn't be moving forward with std::mutex. Hence, there is no real
reason to punt on making std::jthread & friends non-experimental.
2024-09-12 09:48:59 -04:00
A. Jiang
3a0ef2a2d3
[libc++] Reland LWG2921 and LWG2976 (#107960)
They were originally implemented in d42db7e083ee0 but reverted later in
a2f3c63282330be0.

This PR implement both LWG issues again, guarding the removed functions
with `_LIBCPP_STD_VER <= 14`, because they should be treated as patches 
for P0302R1 which was adopted for C++17.

Fixes #103598
Fixes #103755
2024-09-11 17:46:59 -04:00
Nikolas Klauser
748023dc32
[libc++][NFC] Replace _LIBCPP_NORETURN and TEST_NORETURN with [[noreturn]] (#80455)
`[[__noreturn__]]` is now always available, so we can simply use the
attribute directly instead of through a macro.
2024-09-11 08:59:46 +02:00
A. Jiang
46a76c3334
[libc++][test] LWG2593: Moved-from state of Allocators (#107344)
The resolution of LWG2593 didn't require the standard library
implementation to change. It merely strengthened requirements on
user-defined allocator types and allowed the implementation to make
stronger assumptions. The status is tentatively set to Nothing To Do.

However, `test_allocator` in libc++'s test suit needs to be fixed to
conform to the strengthened requirements.

Closes #100220.
2024-09-10 09:53:23 -04:00
Louis Dionne
930915a27a
[libc++] Include the full set of libc++ transitive includes in the CSV files (#107911)
When we introduced the machinery for transitive includes validation, at
some point we stopped including the full set of transitive includes in
the CSV files and instead only tracked the set of public headers
included *directly* by a top-level header.

The reason for doing that was so that the CSV files containing
"transitive" includes could be used to draw the dependency graph of
libc++ headers. However, the downside was that it made the contents of
the CSV files much harder to interpret.

In particular, many changes that modify the CSV files do not in fact
modify the effective set of transitive includes, which is confusing.
This patch goes back to storing the full set of transitive includes in
the CSV files and removes the ability to graph the libc++ includes
directly from those CSV files, which we never actually used.
2024-09-10 08:46:31 -04:00
Eduard Satdarov
b1b9b7b853
[libc++] Cache file attributes during directory iteration (#93316)
This patch adds caching of file attributes during directory iteration
on Windows. This improves the performance when working with files being
iterated on in a directory.
2024-09-09 14:17:53 -04:00
Louis Dionne
37086ea21c
[libc++] Decouple iterator_traits test from precise Clang diagnostics (#107478)
This makes the test more robust and prevents it from breaking when the
diagnostic changes subtly (e.g. under modules).
2024-09-06 12:12:29 -04:00
Louis Dionne
eb0f12188a
[libc++][modules] Tweak a few includes (#107467)
Add a few missing includes, remove two unnecessary ones and use
__cstddef/size_t.h instead of <cstddef> in a few places. This is a
collection of miscellaneous findings that collectively unblock other
modularization patches.
2024-09-06 12:10:04 -04:00
Louis Dionne
953af0e7f1 [libc++][NFC] Increase consistency for namespace closing comments 2024-09-05 12:41:20 -04:00
Robin Caloudis
1a1264726d
[libc++][math] Add constexpr for std::signbit() (#105946)
## Why
Since 18th of August, the floating point comparison builtin
``__builtin_signbit`` is available in Clang as constant expression
(https://github.com/llvm/llvm-project/pull/94118).

## What
* Implement `constexpr` for `std::signbit()` as defined by
[P0533R9](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0533r9.pdf)
(new C++23 feature)
* Restrict execution of tests to tip-of-trunk Clang as builtin is not
yet available (note that builtin is available in GCC)
2024-09-05 15:44:16 +02:00
Louis Dionne
d6832a611a
[libc++][modules] Modularize <cstddef> (#107254)
Many headers include `<cstddef>` just for size_t, and pulling in
additional content (e.g. the traits used for std::byte) is unnecessary.
To solve this problem, this patch splits up `<cstddef>` into
subcomponents so that headers can include only the parts that they
actually require.

This has the added benefit of making the modules build a lot stricter
with respect to IWYU, and also providing a canonical location where we
define `std::size_t` and friends (which were previously defined in
multiple headers like `<cstddef>` and `<ctime>`).

After this patch, there's still many places in the codebase where we
include `<cstddef>` when `<__cstddef/size_t.h>` would be sufficient.
This patch focuses on removing `<cstddef>` includes from __type_traits
to make these headers non-circular with `<cstddef>`. Additional
refactorings can be tackled separately.
2024-09-05 08:28:33 -04:00
Nikolas Klauser
fa385274ba
[libc++] Add ABI tests for unordered_{map,set} (#107200)
These are used to ensure #76756 is correct.
2024-09-05 13:53:19 +02:00
Louis Dionne
52dc4918ca [libc++][NFC] Use consistent layout for license in Python files
Most Python files were using `# === [...]` instead of `#=== [...]`
so I went with what was the most common in the codebase.
2024-09-04 16:48:41 -04:00
Louis Dionne
5e19fd1720
[libc++][modules] Consolidate leaf modules into their own top-level modules (#107147)
Some modules are leaf modules in the sense that they are not used by any
other part of the headers. These leaf modules are easy to consolidate
since there is no risk to create a cycle. As a result of regrouping
these modules, several missing includes were found and fixed in this
patch.
2024-09-04 16:39:55 -04:00
Louis Dionne
23f6c3370b
[libc++][modules] Remove dependency on __algorithm/max from hypot.h (#107150)
That dependency was added recently when we made improvements to
std::hypot, but that resulted in `__math` depending on `__algorithm`,
which is a very heavyweight module. This patch uses `__math::fmax`
instead.
2024-09-04 16:39:09 -04:00
Louis Dionne
d9019d478d
[libc++] Remove unused pair.h include from hypot.h (#106798)
This was added in #100820 by mistake since the final version of that PR
didn't depend on std::pair anymore.
2024-09-04 11:17:32 -04:00
Nikolas Klauser
42f5277de1
[libc++] Fix __datasizeof_v for Clang17 and 18 in C++03 (#106832)
This also disables the use of `__datasizeof`, since it's currently
broken for empty types.
2024-09-03 19:46:08 +02:00
Nikolas Klauser
5e19e317c0 [libc++][NFC] Canonicalize the benchmark suite a bit
This replaces `BENCHMARK_TEMPLATE` with `BENCHMARK` and uses
`BENCHMARK_MAIN()` when possible.
2024-09-03 13:22:01 +02:00
David Spickett
5bd3ee0ac0
[libcxx][test] Use long double test macro in strong_order.pass.cpp (#106742) 2024-09-02 09:06:14 +01:00
Nikolas Klauser
0f7400c4c9 [libc++] Add missing include to std/utilities/charconv/charconv.to.chars/integral.pass.cpp 2024-08-31 12:30:32 +02:00
Louis Dionne
57fe53cae4
[libc++] First attempt to regroup a few modules in the modulemap (#98214)
We split up all the headers into top-level modules when we broke up
cycles with the C compatibility headers. However, this resulted in a
large number of small modules, which is awkward and clearly against the
philosophy of Clang modules. This was necessary to make things work.

This patch regroups a few headers from two leaf modules: stop_token and
pstl. It should be pretty uncontroversial that grouping these headers
into a single module doesn't introduce any cyclic dependency, yet it's a
first step towards reducing the number of top-level modules we have in
our modulemap.
2024-08-30 16:54:09 -04:00
Mark de Wever
f4ea19b47e
[libc++][syncbuf] Implement LWG3253 (#99778)
Closes #100264
2024-08-30 10:13:47 -04:00
David Spickett
c792de28df
[libcxx][test] Add macro for when long double is just double (#106708)
This removes the need for the long list of platforms in
strong_order_long_double_verify.
2024-08-30 15:05:29 +01:00
Matheus Izvekov
67ffd14383
libcxx: [NFC] relax error expectation for clang diagnostics (#106591)
This is a split-off from #96023, where this change has already been
reviewed by libcxx maintainers.

This will prevent that PR from triggering libcxx-ci from now on.
2024-08-29 14:36:39 -03:00
Nikolas Klauser
a705e8cb5b
[libc++][NFC] Remove __constexpr_is{nan,finite} (#106205)
They're never used in `constexpr` functions, so we can simply use
`std::isnan` and `std::isfinite` instead.
2024-08-29 17:05:56 +02:00
A. Jiang
7808541fde
[libc++] P2747R2: constexpr placement new (library part) (#105768)
This patch implements https://wg21.link/P2747R2.

The library changes affect direct `operator new` and `operator new[]`
calls even when the core language changes are absent.

The changes are not available for MS ABI because the `operator new` and
`operator new[]` are from VCRuntime's `<vcruntime_new.h>`. A feature
request was submitted for that [1].

As a drive-by change, the patch reformatted the whole `new.pass.cpp` and
`new_array.pass.cpp` tests.

Closes #105427

[1]: https://developercommunity.visualstudio.com/t/constexpr-for-placement-operator-newope/10730304.
2024-08-28 09:35:57 -04:00
Louis Dionne
0e8208eca1
[libc++] Run the Lit test suite against an installed version of the library (#96910)
We always strive to test libc++ as close as possible to the way we are
actually shipping it. This was approximated reasonably well by setting
up the minimal driver flags when running the test suite, however we were
running the test suite against the library located in the build
directory.

This patch improves the situation by installing the library (the
headers, the built library, modules, etc) into a fake location and then
running the test suite against that fake "installation root".

This should open the door to getting rid of the temporary copy of the
headers we make during the build process, however this is left for a
future improvement.

Note that this adds quite a bit of verbosity whenever running the test
suite because we install the headers beforehand every time. We should be
able to override this to silence it, however CMake doesn't currently
give us a way to do that, see https://gitlab.kitware.com/cmake/cmake/-/issues/26085.
2024-08-28 09:23:00 -04:00
A. Jiang
026210e80d
[libc++][ranges] P2609R3: Relaxing Ranges Just A Smidge (#101715)
This patch implements https://wg21.link/p2609r3.
The test code was originally authored by JMazurkiewicz.

Notes:
- P2609R3 is not officially a Defect Report, but MSVC STL
  implements it in C++20 mode.

  Moreover, P2609R3 and P2997R1 touch exactly the same set of
  concepts, and MSVC STL and libc++ have already treated P2997R1
  as a DR.

- This patch also adjusted feature-test macros.
  + In C++20 mode, the value of __cpp_lib_ranges should be `202110L` because
    - `202202L` covers `range_adaptor_closure` (P2387R3), and
    - `202207L` covers move-only types in range adaptors (P2494R2).
  And all of these changes are only available since C++23 mode.

  + In C++23 mode, the value should be `202406L` because
    - `202211L` covers removing poison overloads (P2602R2),
    - `202302L` covers relaxing projected value types (P2609R3), and
    - `202406L` covers removing requirements on `iter_common_reference_t` (P2997R1).
  And all of these changes are already or being implemented.

Fixes #105253.

Co-authored-by: Jakub Mazurkiewicz <mazkuba3@gmail.com>
2024-08-28 08:55:44 -04:00
Robin Caloudis
866bec7d3f
[libc++][math] Provide overloads for cv-unqualified floating point types for std::isnormal (#104773)
## Why
Currently, the following does not work when compiled with clang:

```c++
#include <cmath>

struct ConvertibleToFloat {
    operator float();
};

bool test(ConvertibleToFloat x) {
    return std::isnormal(x);
}
```
See https://godbolt.org/z/5bos8v67T for differences with respect to
msvc, gcc or icx. It fails for `float`, `double` and `long double` (all
cv-unqualified floating-point types).

## What
Test and provide overloads as expected by the ISO C++ standard. The
classification/comparison function `isnormal` is defined since C++11
until C++23 as
```c++
bool isnormal( float num );
bool isnormal( double num );
bool isnormal( long double num );
```
and since C++23 as
```c++
constexpr bool isnormal( /* floating-point-type */ num );
```
for which "the library provides overloads for all cv-unqualified
floating-point types as the type of the parameter num". See §28.7.1/1 in
the [ISO C++
standard](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.pdf)
or check
[cppreference](https://en.cppreference.com/w/cpp/numeric/math/isnormal).
2024-08-28 10:34:47 +02:00
A. Jiang
4ea2c73886
[libc++] Deprecate and remove std::uncaught_exception (#101830)
Works towards P0619R4/#99985.

- std::uncaught_exception was not previously deprecated. This patch
  deprecates it since C++17 as per N4259. std::uncaught_exceptions is
  used instead as libc++ unconditionally provides this function.

- _LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION restores
  std::uncaught_exception.

- As a drive-by, this patch updates the C++20 status page to 
  explain that D.11 is already done, since it was done in 
  578d09c1b195d859ca7e62840ff6bb83421a77b5.
2024-08-27 17:15:03 -04:00
A. Jiang
74e70bae15
[libc++] Disallow character types being index types of extents (#105832)
#78086 provided the trait we want to use for this: `__libcpp_integer`.

In some `libcxx/containers/views/mdspan` tests, improper uses of `char` 
are replaced with `signed char`. 

Fixes #73715
2024-08-27 16:41:55 -04:00
Louis Dionne
06edc1c07b
[libc++] Avoid including <__config> directly in the test suite (#106080)
Fixes #105878
2024-08-26 17:52:33 -04:00
Louis Dionne
0f58ab851c [libc++] Undo unintended renaming in bc695f522743
Renaming the test will require fixing additional issues, which
I will tackle in a separate patch.
2024-08-26 11:51:29 -04:00
Stephan T. Lavavej
bc695f5227
[libc++][test] Add missing <concepts> in is_always_lock_free test (#105966)
That test was using std::same_as without including <concepts>.
2024-08-26 11:49:47 -04:00
S. B. Tam
499e13514a
[libc++][test] Do not test Clang bug in is_constructible.pass.cpp (#105964)
A comment in `is_constructible.pass.cpp` suggests that Clang is
non-conforming in accepting construction of `const int&` from
`ExplicitTo<int&&>`.

This PR changes the test to expect the standard-conforming behavior,
which makes the test pass on MSVC.
2024-08-26 10:08:52 -04:00