12553 Commits

Author SHA1 Message Date
Nikolas Klauser
4075ddad71
[libc++] Run clang-tidy only once per header (#121436)
There doesn't seem to be much of a reason to run clang-tidy twice per
headers, and running it only once makes the test a few seconds faster.
2025-01-02 17:30:48 +01:00
Nikolas Klauser
40ac34c518
[libc++] Make __type_list variadic (#121117)
This makes these lists signficiantly more readable.
2025-01-02 17:23:52 +01:00
Vitaly Buka
ed572f2003
Reapply "[libc++] Explicitly convert to masks in SIMD code (#107983)" (#121352)
This reverts commit 0ea40bf02138c02e7680ce6fa8169502f2a8bd42.

Passes with https://github.com/llvm/llvm-project/issues/121365 fix: 
https://lab.llvm.org/buildbot/#/builders/55/builds/4930
2025-01-01 11:30:35 +01:00
Konstantin Varlamov
ac1d560709
[libc++][hardening] Add a bounds check for valarray and bitset. (#120685)
Add a `valid-element-access` check to `valarray::operator[]` and
`bitset::operator[]`.
2024-12-24 18:22:18 -08:00
Nikolas Klauser
ffc7380ff4
[libc++] Avoid including shared_ptr.h in basic_ostream.h (#121049) 2024-12-24 16:18:25 +01:00
Petr Hosek
902e62cf15
[libcxx] Fix the #endif comments (#120949)
The order of comments is swapped.
2024-12-23 07:33:26 -08:00
Petr Hosek
d039ac3955
[libcxx] Remove the second inclusion of the system header (#120946)
This was introduced in #119025 and not only seems unnecessary, it broke
the build with older versions of glibc.
2024-12-23 07:33:09 -08:00
Peng Xie
6285c46e16
[libc++] Refactor some code in monotonic_buffer_resource (#117271)
1. remove unused __default_buffer_alignment
2. two __try_allocate_from_chunk are same, put it together

This patch refactor some code in monotonic_buffer_resource.
2024-12-23 14:32:59 +08:00
Nikolas Klauser
b84218526d [libc++] Mark num_get.bench.cpp as unsupported in C++03 2024-12-23 00:55:14 +01:00
Nikolas Klauser
c5492e3c65 [libc++] Add a benchmark for std::num_get 2024-12-22 20:44:16 +01:00
Nikolas Klauser
6261599245 [libc++] Mark P0270R3 as Nothing To Do
The paper is fixing a wording bug, so there's nothing to do for
implementations.
2024-12-22 13:52:36 +01:00
Nikolas Klauser
e8f1902cca
[libc++] Add a test to make sure the type traits derive from integral_constant (#120732) 2024-12-22 12:40:53 +01:00
Nikolas Klauser
21e6f16517 [libc++] Mark N4089 as complete
The paper has been implemented since at least LLVM 5, maybe earlier.
2024-12-22 03:43:27 +01: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
037da01022 [libc++] Mark P0175R1 as 'Nothing To Do'
The paper is purely editorial.

Fixes #99941
2024-12-22 02:51:55 +01:00
Nikolas Klauser
9b0c8ef37a
[libc++] Don't declare pmr::polymorphic_allocator before C++17 (#120850)
Fixes #120790
2024-12-22 00:56:06 +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
fd784726db [libc++] Rewrite minmax_element benchmark
The benchmark currently uses makeCartesianProductBenchmark, which
doesn't make a ton of sense, since minmax_element always goes through
every element one by one. The runtime doesn't depend on the values
of the elements.

Fixes #120758
2024-12-21 20:07:28 +01:00
Nikolas Klauser
b9a2658a3e
[libc++][C++03] Use __cxx03/ headers in C++03 mode (#109002)
This patch implements the forwarding to frozen C++03 headers as
discussed in
https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc. In the
RFC, we initially proposed selecting the right headers from the Clang
driver, however consensus seemed to steer towards handling this in the
library itself. This patch implements that direction.

At a high level, the changes basically amount to making each public
header look like this:

```
// inside <vector>
#ifdef _LIBCPP_CXX03_LANG
#  include <__cxx03/vector>
#else
  // normal <vector> content
#endif
```

In most cases, public headers are simple umbrella headers so there isn't
much code in the #else branch. In other cases, the #else branch contains
the actual implementation of the header.
2024-12-21 13:01:48 +01:00
Louis Dionne
ef42e9c59a
[libc++] Remove allocation.bench.cpp (#120767)
That benchmark isn't really useful, since it doesn't benchmark anything
from libc++ (besides `operator new`). The implementation of the
benchmark also has serious problems like the fact that it allocates an
unknown amount of memory without deallocating it.
2024-12-20 15:33:52 -05:00
Louis Dionne
34e0f9cd36
[libc++] Remove the need for uselocale() (#120158)
Instead of requiring `uselocale()` as part of the base locale API,
define __locale_guard in the few places that need it directly, without
making __locale_guard part of the base API.

In practice, most mainstream platforms never used __locale_guard, so
they also didn't need to define uselocale(), and after this patch they
actually don't define it anymore.
2024-12-19 16:06:08 -05:00
Nico Weber
8dfae0c462 Revert "[libcxx] Use alias for detecting overriden function (#114961)"
This reverts commit 62bd10f7d18ca6f544286767cae2c9026d493888.
Breaks building with -flto=thin, see
https://github.com/llvm/llvm-project/pull/114961#issuecomment-2555754056
2024-12-19 15:54:06 -05:00
Peng Liu
fafdf97047
[libc++] Simplify vector<bool>::flip() and add new tests (#119607)
This PR simplifies the internal bitwise logic of the `flip()` function
for `vector<bool>`, and creates new tests to validate the changes.
2024-12-19 11:48:51 -05:00
Peng Liu
4039a79de7
[libc++][test] Improve tests for assign in std::vector and vector<bool> (#119163)
This PR enhances the test coverage for std::vector::assign by adding new
tests for several important test cases that were previously missing, as
shown in the following table:

| test cases                        | forward_iterator | input_iterator |
|-----------------------------------|------------------|----------------|
| new_size > capacity()             | Yes              | Yes            |
| size() < new_size <= capacity()   | No               | No             |
| new_size <= size()                | No               | No             |

Similarly, no tests have previously covered `assign(InputIterator, InputIterator)`
and `assign(size_type, const value_type&)` for `vector<bool>`.

With this patch applied, all missing tests are covered.
2024-12-19 11:19:25 -05:00
Nikolas Klauser
b905bcc509
[libc++] Remove some unused includes (#120219) 2024-12-18 21:10:27 +01:00
Petr Hosek
edf9439e00
[libcxx] Support for using timespec_get (#117362)
clock_gettime is a POSIX API that may not be available on platforms like
baremetal; timespec_get is the C11 equivalent. This change adds support
for using timespec_get instead of clock_gettime to improve compatibility
with non-POSIX platforms. For now, this is only enabled with LLVM libc
which implemented timespec_get in #116102, but in the future this can be
expanded to other platforms.

Related to #84879.
2024-12-17 08:16:55 -08:00
Petr Hosek
62bd10f7d1
[libcxx] Use alias for detecting overriden function (#114961)
This mechanism is preferable in environments like embedded since it
doesn't require special handling of the custom section.
2024-12-17 08:16:26 -08:00
Louis Dionne
d8a0709b10
[libc++] Bump the version of CMake built in the CI Docker image (#120240)
This will allow using the $<LINK_LIBRARY> generator expression in some
of our configurations. We should separately pursue officially bumping
the minimum CMake version across all LLVM so we can use this feature
more widely.
2024-12-17 10:29:18 -05:00
Louis Dionne
ce4ac99452
[libc++] Remove explicit mentions of __need_FOO macros (#119025)
This change has a long history. It was first attempted naively in
https://reviews.llvm.org/D131425, which didn't work because we broke the
ability for code to include e.g. <stdio.h> multiple times and get
different definitions based on the pre-defined macros.

However, in #86843 we managed to simplify <stddef.h> by including the
underlying system header outside of any include guards, which worked.

This patch applies the same simplification we did to <stddef.h> to the
other headers that currently mention __need_FOO macros explicitly.
2024-12-17 09:52:34 -05:00
Nikolas Klauser
59890c1334
[libc++] Granularize <new> includes (#119964) 2024-12-17 11:29:16 +01:00
Louis Dionne
084309a0ef
[libc++] Refactor the Windows and MinGW implementation of the locale base API (#115752)
This patch reimplements the locale base support for Windows flavors in a
way that is more modules-friendly and without defining non-internal
names.

Since this changes the name of some types and entry points in the built
library, this is effectively an ABI break on Windows (which is
acceptable after checking with the Windows/libc++ maintainers).
2024-12-16 17:46:05 -05:00
Vitaly Buka
31272e4f83
[libc++] Update locale grouping tests (#119463)
Fixes #119047
2024-12-16 12:50:59 -05:00
Louis Dionne
4104906a23 [libc++] Revert new test for integral_constant that breaks CI
This commit reverts c3276a96d9 and 1901da32, which added a test to
ensure that type traits are derived from integral_constant. While that
is a fine test to add, the commit didn't go through a PR and as a result
it looks like some of our CI has been broken by it.

This should be an uncontroversial change, but let's re-land it via a PR
to get our usual CI coverage.
2024-12-16 10:41:16 -05:00
Nikolas Klauser
c3276a96d9 [libc++] Disable deprecation warnings in derived_from_integral_constant.compile.pass.cpp 2024-12-14 16:19:40 +01:00
Nikolas Klauser
1901da32a4 [libc++] Add a test to make sure all the type traits derived from bool_constant 2024-12-14 15:19:19 +01:00
Nikolas Klauser
6157dbe48c
[libc++] Introduce __forward_as (#118168)
This allows forwarding an object as a specific type. This is usually
useful when using `deducing this` to avoid calling any functions in a
deriving class.
2024-12-14 15:09:16 +01:00
Louis Dionne
2135babe28
[libc++] Save benchmark results in a json file (#119761)
When running a benchmark, also save the benchmark results in a JSON
file. That is cheap to do and useful to compare benchmark results
between different runs.
2024-12-13 14:19:35 -05: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
Louis Dionne
62bdb85f9b [libc++][NFC] Fix incorrect comment for vector::assign(iter, iter) test 2024-12-13 09:35:56 -05:00
Peng Liu
979e9361f0
[libc++] Fix improper static_cast in std::deque and __split_buffer (#119106)
This PR addresses the improper use of `static_cast` to `size_t` where
`size_type` is intended. Although the `size_type` member type of STL
containers is usually a synonym of `std::size_t`, there is no guarantee
that they are always equivalent. The C++ standard does not mandate this
equivalence.

In libc++'s implementations of `std::deque`, `std::vector`, and
`__split_buffer`, the `size_type` member type is defined as
`std::allocator_traits<allocator_type>::size_type`, which is either
`allocator_type::size_type` if available or
`std::make_unsigned<difference_type>::type`. While it is true for
`std::allocator` that the `size_type` member type is `std::size_t`, for
user-defined allocator types, they may mismatch. This justifies the need
to replace `static_cast<size_t>` with `static_cast<size_type>` in this
PR.
2024-12-13 09:28:30 -05:00
Nikolas Klauser
5fd385b3c1
[libc++][NFC] Simplify the implementation of string and string_views operator== (#117184) 2024-12-13 13:17:19 +01:00
Louis Dionne
81dcbefba3
[libc++] Add testing configurations for libstdc++ and a native stdlib (#98539)
This allows running the test suite against the native Standard Library
on most systems, and against libstdc++ installed at a custom location.

Of course, these configurations don't run 100% clean at the moment. In
particular, running against the native stdlib is almost guaranteed not
to work out-of-the-box, since the test suite generally contains tests
for things that have been implemented on tip-of-trunk but not released
to most major platforms yet. However, having an easy way to run the test
suite against that library is still both useful and interesting.
2024-12-12 17:01:46 -05:00
Louis Dionne
6a9279ca40
[libc++] Slight reorganization of the benchmarks (#119625)
Move various container benchmarks to the same subdirectory, and regroup
some format-related benchmarks.
2024-12-12 08:14:50 -05:00
Louis Dionne
4b8bf6aac8
[libc++] Properly guard flat_map includes based on C++ version (#119227)
That's what we (try to) do consistently for all other umbrella headers.

As a drive-by, remove the <__assert> header which is not mandated
anymore.
2024-12-11 16:53:33 -05:00
Louis Dionne
7b2d592a19 [libc++] Fix test FTM header guard
That template is actually not used to generate the version header yet,
but we can at least fix the include guards which are clearly incorrect.
2024-12-11 12:39:43 -05:00
Nikolas Klauser
323bedd0d6
[libc++][C++03] Add #if 0 to the experimental/ and ext/ headers as well (#119541)
This has already been done for the most headers in
https://github.com/llvm/llvm-project/pull/119234, but I
forgot to also do it for the experimental/ and ext/ headers.

This is part of https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc.
2024-12-11 10:35:21 -05:00
Peng Liu
eacdbc269e
[libc++][test] Fix invalid const conversion in limited_allocator (#118189)
This patch fixes a const-qualification on the return type of a method
of `limited_allocator`, which is widely used for testing allocator-aware
containers.
2024-12-10 10:24:40 -05:00
Louis Dionne
01512d29b7
[libc++] Document guidelines for symbols baked into the ABI (#118526)
Closes #112395
2024-12-10 10:15:13 -05:00
Louis Dionne
bd8eb7894f [libc++] Temporarily disable FreeBSD runners
They have been out for over 10 days, which only causes confusion
when looking at CI results.
2024-12-10 10:11:27 -05:00
Nikolas Klauser
c166a9c713
[libc++] Add #if 0 block to all the top-level headers (#119234)
Including The frozen C++03 headers results in a lot of formatting
changes in the main headers, so this splits these changes into a
separate commit instead.

This is part of
https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc.
2024-12-10 16:02:12 +01:00