Commit Graph

13090 Commits

Author SHA1 Message Date
Ashwin Banwari
2599a9aeb5 [clang] [modules] Implement P3618R0: Allow attaching main to the global module (#146461)
Remove the prior warning for attaching extern "C++" to main.
2025-07-02 09:52:10 +08:00
Eric Fiselier
01d0171e7a Address formatting mistake in libc++ test 2025-06-30 13:53:24 -04:00
Eric
4aaab69314 [libc++] Fix wait_on_destruct.pass.cpp hanging sometimes (#146240)
This test was deadlocking on my machine. 

It seems to me the intention of `in_async.wait(...)` was to wait for the
value to be set to true, which requires a call of `wait(false)` (waits
if value matches argument).

~As a drive by change scoped_lock to unique_lock, since there shouldn't
be any functional difference between the two in this test.~

I've addressed the issues with the `in_async` by switching to a
condition variable instead, since my first attempt at fixing this with
`in_async` wasn't sufficient.
2025-06-30 11:54:12 -04:00
Nikolas Klauser
179cc202bd [libc++] Add missing _LIBCPP_NODEBUG in <__type_traits/invoke.h>
libc++ doesn't run clang-tidy in the bootstrapping build, so it wasn't
run when `__builtin_invoke` was introduced. Once libc++ upgrades to a
newer clang version, clang-tidy will start to fail due to missing
`_LIBCPP_NODEBUG` annotations.
2025-06-30 10:19:24 +02:00
Nikolas Klauser
e0864b56b0 [libc++] Fix <charconv> not exporting std::errc (#146268)
`<charconv>` doesn't properly export `std::errc` with locales disabled,
which causes the CI to fail. This fixed the modulemap to let
`from_chars_result` export `std::errc`, like it's supposed to do.
2025-06-30 10:06:34 +02:00
Nikolas Klauser
713839729c [Clang] Add __builtin_invoke and use it in libc++ (#116709)
`std::invoke` is currently quite heavy compared to a function call,
since it involves quite heavy SFINAE. This can be done significantly
more efficient by the compiler, since most calls to `std::invoke` are
simple function calls and 6 out of the seven overloads for `std::invoke`
exist only to support member pointers. Even these boil down to a few
relatively simple checks.

Some real-world testing with this patch revealed some significant
results. For example, instantiating `std::format("Banane")` (and its
callees) went down from ~125ms on my system to ~104ms.
2025-06-29 17:52:50 +02:00
Hristo Hristov
267945b665 [libc++][NFC] Refactored equality comparisons tests for pair and expected (#145668)
Refactored `std::expected` and `std::pair` tests to use the
canonicalized names from `test_comparisions.h`, which are shared between
tests.

This was split from https://github.com/llvm/llvm-project/pull/139368 as
per comment
https://github.com/llvm/llvm-project/pull/139368#pullrequestreview-2916040573

Towards implementing [P2944R3: Comparisons for
reference_wrapper](https://github.com/llvm/llvm-project/issues/105424)

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-06-29 16:34:49 +03:00
Hui
34b2e934ea [libc++] Introduce __product_iterator_traits and optimise flat_map::insert (#139454)
Fixes #108624

This allows `flat_map::insert(Iter, Iter)` to directly forward to
underlying containers' `insert(Iter, Iter)`, instead of inserting one
element at a time, when input models "product iterator". atm,
`flat_map::iterator` and `zip_view::iterator` are "product iterator"s.

This gives about almost 10x speed up in my benchmark with -03 (for both
before and after)

```cpp
Benchmark                                                          Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------
flat_map::insert_product_iterator_flat_map/32                   -0.5028         -0.5320           149            74           149            70
flat_map::insert_product_iterator_flat_map/1024                 -0.8617         -0.8618          3113           430          3112           430
flat_map::insert_product_iterator_flat_map/8192                 -0.8877         -0.8877         26682          2995         26679          2995
flat_map::insert_product_iterator_flat_map/65536                -0.8769         -0.8769        226235         27844        226221         27841
flat_map::insert_product_iterator_zip/32                        -0.5844         -0.5844           162            67           162            67
flat_map::insert_product_iterator_zip/1024                      -0.8754         -0.8754          3427           427          3427           427
flat_map::insert_product_iterator_zip/8192                      -0.8934         -0.8934         28134          3000         28132          3000
flat_map::insert_product_iterator_zip/65536                     -0.8783         -0.8783        229783         27960        229767         27958
OVERALL_GEOMEAN                                                 -0.8319         -0.8332             0             0             0             0
```

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-06-28 13:42:50 +01:00
Hristo Hristov
a19d37044b [libc++] P2944R3: Constrained comparisions - tuple (#145677)
Implements P2944R3 partially, which adds constrained comparisons
`std::tuple`.
The missing overloads introduced in [P2165R4](https://wg21.link/P2165R4)
are not implemented.

Uses
[`__all`](f7af33a9eb/libcxx/include/__type_traits/conjunction.h (L45))
instead of a fold expression, see comment:
https://github.com/llvm/llvm-project/pull/141396#discussion_r2161166077

Relates to #136765

# References

[tuple.rel](https://wg21.link//tuple.rel)
2025-06-27 20:12:18 +03:00
Nikolas Klauser
e9805235bf [libc++] Move libcxx/test/libcxx/extensions to libcxx/test/extensions and update the tests (#145476)
This patch adds a separate `extensions` directory, since there are quite
a few extensions in libc++ that aren't necessarily libc++-specific. For
example, the tests currently in `libcxx/test/libcxx/extensions` should
also pass with libstdc++, since they originally added the extension.
This also "documents" what users are allowed to rely on and what parts
are just libc++ tests to make sure our implementation is behaving as we
expect, which may be subject to change.

This patch also formats the tests and refactors `.fail.cpp` tests to
`.verify.cpp` tests.
2025-06-27 13:16:37 +02:00
Nikolas Klauser
d163ab3323 [libc++] Remove a bunch of unnecessary type indirections from __tree (#145295)
Most of the diff is replacing `__parent_pointer` with
`__end_node_pointer`. The most interesting diff is that the pointer
aliases are now defined directly inside `__tree` instead of a separate
traits class.
2025-06-27 10:11:20 +02:00
Nikolas Klauser
4c8fab399b [libc++] Avoid type-punning between __hash_value_type and pair (#143501)
This patch is very similar to #134819 in nature. Before this patch, we
were dereferencing pointers to objects which were never constructed. Now
we always assume that nodes store `pair<const KeyT, ValueT>` for
unordered_maps instead, as they actually do.
2025-06-26 19:43:59 +02:00
Qinkun Bao
04b60d29ba Disable HWSan for thread_creae_failure.pass.
See https://github.com/llvm/llvm-project/pull/130145
2025-06-26 15:41:31 +00:00
Qinkun Bao
06a4394b50 Disable HWSan for thread_creae_failure.pass.
See https://github.com/llvm/llvm-project/pull/130145
2025-06-26 14:49:12 +00:00
Nikolas Klauser
0905767610 [libc++] Address remaining comments from #130145
I've accidentally merged the PR before addressing all
comments. This patch fixes the remaining ones.
2025-06-26 12:34:19 +02:00
Nikolas Klauser
696c0f92e0 [libc++] Don't try to wait on a thread that hasn't started in std::async, take 2 (#130145)
If the creation of a thread fails, this causes an idle loop that will
never end because the thread wasn't started in the first place.

This also adds a test for the regression reported in #125433 to make
sure we're not reintroducing it later.

Fixes #125428
2025-06-26 12:13:19 +02:00
Hristo Hristov
f2f4b557aa [libc++] P2944R3: Constrained comparisions - variant (#141396)
This is a follow-up and depends on #139368 being merged first.

Implements [P2944R3](https://wg21.link/P2944R3) partially, which adds
constrained comparisons to `std::variant`

Closes #136769

Depends on #139368

# References

[variant.relops](https://wg21.link/variant.relops)
2025-06-25 12:12:23 +03:00
Louis Dionne
52b27c2bd6 [libc++] Refactor basic_filebuf::overflow() (#144793)
Refactor the function to streamline the logic so it matches the
specification in [filebuf.virtuals] more closely. In particular, avoid
modifying the put area pointers when we loop around after a partial
codecvt conversion.

Note that we're technically not up-to-spec in this implementation, since
the Standard says that we shouldn't try more than once after a partial
codecvt conversion. However, this refactoring attempts not to change any
functionality.
2025-06-24 13:58:49 -04:00
Hui
0b8f3cc6b7 [libc++] Fix no-localisation CI failure on <complex> (#145213) 2025-06-24 13:56:17 -04:00
Peng Liu
d80766152c [libc++] Fix bitset conversion functions and refactor constructor (#121348)
This patch addresses several implementation issues in `bitset`'s
conversion functions `to_ullong` and `to_ulong`, and refactors its
converting constructor `__bitset(unsigned long long __v)` to a more
generic and elegant implementation.
2025-06-24 12:38:10 -04:00
Nikolas Klauser
be00098632 [libc++] Remove a bunch of now unnecessary indirections in __tree (#142397)
Most notably, this removes the notion of a distinct `value_type` and
`__container_value_type` from `__tree`, since these are now always the
same type. There are a few places we need to keep `__value_type` around,
since they are ABI visibile. In these cases `_Tp` is used directly. The
second simplification here is that we use `const value_type&` instead of
`const key_type&` in a few places and make use of the fact that the
comparator is capable of comparing any combination of `key_type` and
`value_type`.

This is a follow-up to #134819.
2025-06-23 10:47:47 +02:00
Nikolas Klauser
43260b01dd [libc++] Add test to ensure that the mangling of types stays the same (#143556) 2025-06-23 10:43:47 +02:00
Hui
831fcb5e91 [libc++] constexpr flat_map (#137453)
Fixes #128673
2025-06-21 13:41:32 +01:00
Jakub Mazurkiewicz
1bb2328fd3 [libc++] Implement views::join_with (#65536)
* Implement "P2441R2 `views::join_with`" (https://wg21.link/P2441R2),
closes #105185
* Implement LWG4074 (https://wg21.link/LWG4074), closes #105346
* Complete implementation of "P2711R1 Making multi-param constructors of
views explicit" (https://wg21.link/P2711R1), closes #105252
* Complete implementation of "P2770R0 Stashing stashing iterators for
proper flattening" (https://wg21.link/P2770R0), closes #105250
2025-06-21 10:54:50 +01:00
Nikolas Klauser
685af55fe0 [libc++] Simplify <limits> a bit (#140021)
This does a few small things:
- inline `__libcpp_compute_min`, since we can don't have to put the
arithmetic behind a constraint. Simple arithmetic also tends to be
faster to compile than instantiating a type.
- Remove an unused include (and add missing includes elsewhere)
- Remove `__min` and `__max` from the `bool` specialization

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-06-21 09:58:45 +02:00
Nikolas Klauser
2050d2e181 [libc++] Simplify std::function further after removing allocator support (#144443)
Since we've removed allocator support, we can remove a few support
structures. This only affects the policy implementation, so this
shouldn't even be ABI sensitive.
2025-06-21 09:47:54 +02:00
Aiden Grossman
7157f33c6c [libc++] Disable a std::unexpected test in modules build (#144466)
This patch disables unexpected_disabled_cpp17.verify.cpp under clang
modules builds because it changes diagnostics criteria post #143423,
causing the test to fail.

This patch follows a similar style to 853059a150.
This was found when working on trying to land #144033.
2025-06-20 12:58:59 -04:00
Hristo Hristov
945ce1aa3d [libc++] Update the value of __cpp_lib_constrained_equality after P3379R0 (#144553)
https://wg21.link/P3379R0 updated the value of __cpp_lib_constrained_equality,
but we forgot to update it when we implemented the paper.
2025-06-20 12:36:46 -04:00
Nikolas Klauser
20245bbf66 [libc++][NFC] Format abs.pass.cpp test
I will modify the test in an upcoming PR. I'm formatting it now to avoid
a bunch of whitespace changes in that PR.
2025-06-19 10:41:12 +02:00
Nikolas Klauser
584cc37687 [libc++] Move std::abs into __math/abs.h (#139586)
`template <class = int>` is also added to our implementations to avoid
an ambiguity between the libc's version and our version when both are
visible.

This avoids including `<stdlib.h>` in `<math.h>`.
2025-06-19 10:37:18 +02:00
Nikolas Klauser
650b451d00 [libc++] Simplify the implementation of pointer_traits a bit (#142260) 2025-06-19 10:06:59 +02:00
S. B. Tam
a9a71b6d31 [libc++][test] Don't pass ill-formed UTF-8 to MAKE_STRING_VIEW (#136403) 2025-06-19 15:21:28 +08:00
Kazu Hirata
ca9a09dbe6 [libc++] Fix a typo in documentation (#144763) 2025-06-18 15:03:17 -04:00
Peng Liu
9827440f1e [libc++] Optimize ranges::{for_each, for_each_n} for segmented iterators (#132896)
Previously, the segmented iterator optimization was limited to `std::{for_each, for_each_n}`. This patch
extends the optimization to `std::ranges::for_each` and `std::ranges::for_each_n`, ensuring consistent
optimizations across these algorithms. This patch first generalizes the `std` algorithms by introducing
a `Projection` parameter, which is set to `__identity` for the `std` algorithms. Then we let the `ranges`
algorithms to directly call their `std` counterparts with a general `__proj` argument. Benchmarks
demonstrate performance improvements of up to 21.4x for ``std::deque::iterator`` and 22.3x for
``join_view`` of ``vector<vector<char>>``.

Addresses a subtask of #102817.
2025-06-18 12:22:47 -04:00
Peng Liu
dd40c460c4 [libc++] Clean up casts in std::forward_list (#130310)
The patch removes unnecessary casts to `void*` pointers, inline some
casts, and eliminates an identity cast.
2025-06-18 12:16:01 -04:00
Peng Liu
13510c0736 [libc++] Make list constexpr as part of P3372R3 (#129799)
This patch makes `std::list` constexpr as part of P3372R3.

Fixes #128659.
2025-06-18 12:13:50 -04:00
Nikolas Klauser
9db7502d22 [libc++] Move __has_iterator_typedefs to the up-to-C++17 implementation of iterator_traits (#144265)
`__has_iterator_typedefs` is only used in the up-to-C++17 implementation
of `type_traits`. To make that clearer the struct is moved into that
code block.
2025-06-18 15:55:06 +02:00
Martin Storsjö
c3efe7d64c [libcxx] [test] Fix odr_signature tests with optimizations enabled (#144317)
If optimization is enabled, the inline `f()` function actually gets
inlined, meaning that the functions `tu1()` and `tu2()` trivially return
1 and 2, instead of actually referencing the potentially linker
deduplicated function `f()`, which is what the test tries to test.

Therefore, this test previously actually failed to test what it was
supposed to test, if optimization was enabled.

Mark the inline functions with `TEST_NOINLINE` to make sure that they
don't get inlined even with optimizations enabled.

Also update the TODO comments to explain why we have an XFAIL for msvc
mode here.

This avoids these tests unexpectedly passing if building in msvc mode,
with optimizations enabled
(`-DLIBCXX_TEST_PARAMS="optimization=speed"`).
2025-06-18 14:12:14 +03:00
Daniel Thornburgh
fd7e46b864 Revert "[libc++] Remove trailing newline from _LIBCPP_ASSERTION_HANDLER calls" (#144615)
Reverts llvm/llvm-project#143573
2025-06-17 15:50:42 -07:00
Sam Clegg
a5a0d88073 [libc++] Remove trailing newline from _LIBCPP_ASSERTION_HANDLER calls (#143573)
This newline was originally added in https://reviews.llvm.org/D142184
but I think updating `__libcpp_verbose_abort` to add newline instead is
more consistent, and works for other callers of `_LIBCPP_VERBOSE_ABORT`.

The `_LIBCPP_ASSERTION_HANDLER` calls through to either
`_LIBCPP_VERBOSE_ABORT` macro or the `__builtin_verbose_trap`. From what
I can tell neither of these function expect a trailing newline (at least
none of the usage of `_LIBCPP_VERBOSE_ABORT` or `__builtin_verbose_trap`
that I can find include a trailing newline except `_LIBCPP_ASSERTION_HANDLER`).

I noticed this discrepancy when working on
https://github.com/emscripten-core/emscripten/pull/24543
2025-06-17 17:07:16 -04:00
Louis Dionne
8d1610afd0 [libc++] Mark two assertion tests as unsupported in C++03 mode
Our assertion checking facility requires at least C++11, so these
tests were failing when run in C++03 mode.
2025-06-17 16:51:35 -04:00
Louis Dionne
7c4b2be983 [libc++][NFC] Refactor basic_streambuf to use public API functions when possible (#144547)
The implementation of std::basic_streambuf used private member variables
to manipulate the get and the put areas. Using public API functions is
equivalent but leads to code that is easier to understand, since the
public API functions are known more widely than our internal member
variables. Using the public API functions removes the need to map the
internal member variables back to get/put area manipulation functions in
one's head.

Finally, it also makes it easier to find subtle issues by instrumenting
accessor functions, which is impossible if the class uses the member
variables directly.
2025-06-17 16:38:27 -04:00
Louis Dionne
b1aa845595 [libc++][NFC] Consistently qualify calls to C functions in <fstream> (#144539) 2025-06-17 15:48:58 -04:00
Nikolas Klauser
79a2b15a4c [libc++] Remove a few workarounds for old Clang versions (#143858) 2025-06-16 11:12:15 +02:00
Hristo Hristov
a0c00ccd5f [libc++] P2944R3: Constrained comparisons - update reference_wrapper implementation (#139368)
Updates the implementation `std::reference_wrapper` -
[P2944R3](https://wg21.link/P2944R3) as discussed in
https://github.com/llvm/llvm-project/pull/117664#discussion_r1857826166
This PR also refactors the tests in preparation to implements the
constrained comparisons for `optional`, `variant` etc.

- Moves the test helpers (concepts and types) for testing constrained
comparisons to `test_comparisons.h`.
- Updates the `std::reference_wrapper` implementation to use the concept
`__core_convertible_to<bool>` as per comments in #135759.

Closes #138233

# References:
- [refwrap.comparisons](https://wg21.link/refwrap.comparisons)

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-06-15 07:45:48 +03:00
halbi2
eab1a1d491 [libc++][test] Improve test coverage for flat_set (lack of) SCARY iterators (#139649)
Missing from 5e94e26a7a.
2025-06-12 13:15:41 -04:00
kotborealis
a53003fe23 [libc++] Update GDB pretty-printer to work with GDB 17 (#142106)
This patch fixes an issue in libcxx/utils/gdb/libcxx/printers.py.

With gdb 17 (binutils 2_44) pretty-printers do not work anymore because
calls to `gdb.printing` requires `import gdb.printing` statement, which
was missing from the `printers.py`.

This was broken after commit https://github.com/bminor/binutils-gdb/commit/fc14343205d3a
and `import gdb.printing` was first referenced in https://github.com/bminor/binutils-gdb/commit/ee06c79b0f.

Co-authored-by: Dmitry Chestnykh <dm.chestnykh@gmail.com>
2025-06-12 11:51:22 -04:00
tynasello-google
13fe07d670 [libc++] Expand Android libc++ test config files (#142846)
Parameterize (and rename) existing libc++/libc++abi test configuration
files for the Android NDK to work for both the NDK and platform.

Android LLVM downstream seeks to test libc++ for both the NDK and
platform build (currently only testing the NDK), which will use almost
identical test configuration files. The only difference is the name of
the libc++ shared object used. Because of this we parameterize the
current test files (for both libc++ and libc++abi) with the existing
LIBCXX_SHARED_OUTPUT_NAME cmake variable, and rename the file
accordingly.
2025-06-12 11:39:28 -04:00
Kazu Hirata
5c1a021f7f [libc++] Fix typos in documentation (#143912) 2025-06-12 10:54:36 -04:00
A. Jiang
bba4ded3c2 [libc++] Fix constructing bitset from non-null-terminated arrays (#143691)
Unconditional evaluation of `char_traits<_CharT>::length(__str)` is problematic, because it causes
UB when `__str` points to a non-null-terminated array. We should only call `length` (currently, in
`basic_string_view`'s constructor) when `__n == npos` per [bitset.cons]/8.

Drive-by change: Reduction of conditional compilation, given that
- both `basic_string_view<_CharT>::size_type` and `basic_string<_CharT>::size_type` must be 
  `size_t`, and thus
- both `basic_string_view<_CharT>::npos` and `basic_string<_CharT>::npos` must be `size_t(-1)`.

For the type sameness in the standard wording, see:
- [string.view.template.general]
- [basic.string.general]
- [allocator.traits.types]/6
- [default.allocator.general]/1

Fixes #143684
2025-06-12 10:53:41 -04:00