Commit Graph

200 Commits

Author SHA1 Message Date
Louis Dionne
9783f28cbb
[libc++] Format the code base (#74334)
This patch runs clang-format on all of libcxx/include and libcxx/src, in
accordance with the RFC discussed at [1]. Follow-up patches will format
the benchmarks, the test suite and remaining parts of the code. I'm
splitting this one into its own patch so the diff is a bit easier to
review.

This patch was generated with:

   find libcxx/include libcxx/src -type f \
      | grep -v 'module.modulemap.in' \
      | grep -v 'CMakeLists.txt' \
      | grep -v 'README.txt' \
      | grep -v 'libcxx.imp' \
      | grep -v '__config_site.in' \
      | xargs clang-format -i

A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh
to help resolve merge and rebase issues across these formatting changes.

[1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
2023-12-18 14:01:33 -05:00
Louis Dionne
77a00c0d54
[libc++] Replace uses of _VSTD:: by std:: (#74331)
As part of the upcoming clang-formatting of libc++, this patch performs
the long desired removal of the _VSTD macro.

See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
for the clang-format proposal.
2023-12-05 11:19:15 -05:00
Louis Dionne
4c19854222
[libc++] Rename _LIBCPP_INLINE_VISIBILITY to _LIBCPP_HIDE_FROM_ABI (#74095)
In preparation for running clang-format on the whole code base, we are
also removing mentions of the legacy _LIBCPP_INLINE_VISIBILITY macro in
favor of the newer _LIBCPP_HIDE_FROM_ABI.

We're still leaving the definition of _LIBCPP_INLINE_VISIBILITY to avoid
creating needless breakage in case some older patches are checked-in
with mentions of the old macro. After we branch for LLVM 18, we can do
another pass to clean up remaining uses of the macro that might have
gotten introduced by mistake (if any) and remove the macro itself at the
same time. This is just a minor convenience to smooth out the transition
as much as possible.

See
https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
for the clang-format proposal.
2023-12-04 10:25:14 -05:00
Konstantin Varlamov
b85fdc4ffd
[libc++][hardening] Add _LIBCPP_ASSERT_NON_NULL to check for null pointers (#71428) 2023-11-07 16:12:15 -10:00
Louis Dionne
3e24a77a86 [libc++] Use the default initializer for char_type in std::num_get::do_get
This is to fix an error that occurs when the char type is a class type.
Thanks to Yichen Yan for the patch.

Differential Revision: https://reviews.llvm.org/D100005
2023-09-11 14:16:47 -04:00
Alexander Richardson
bf1bcb68fc [libc++] Use intptr_t instead of ptrdiff_t for messages_base::catalog
On GLibc, FreeBSD and macOS systems nl_catd is a pointer type, and
round-tripping this in a variable of ptrdiff_t is not portable.
In fact such a round-trip yields a non-dereferenceable pointer on
CHERI-enabled architectures such as Arm Morello. There pointers (and
therefore intptr_t) are twice the size of ptrdiff_t, which means casting
to ptrdiff_t strips the high (metadata) bits (as well as a hidden pointer
validity bit).

Since catalog is now guaranteed to be the same size or larger than nl_catd,
we can store all return values safely and the shifting workaround from
commit 0c68ed006d should not be needed
anymore (this is also not portable to CHERI systems on since shifting a
valid pointer right will create a massively out-of-bounds pointer that
may not be representable).

This can be fixed by using intptr_t which should be the same type as
ptrdiff_t on all currently supported architectures.

See also: https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2028

Differential Revision: https://reviews.llvm.org/D134420

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-09-08 09:15:57 -04:00
Louis Dionne
c01794e7ae [libc++] Move once_flag outside of <mutex>
This allows including once_flag directly from <__locale> instead of
depending on all of <mutex>, which requires threading. In turn, this
makes it easier to support locales on platforms without threading.

Drive-by change: clang-format once_flag.h and use _LIBCPP_HIDE_FROM_ABI

Differential Revision: https://reviews.llvm.org/D155487
2023-08-31 14:56:42 -04:00
Nikolas Klauser
1e24b4d3fd [libc++] Fix template parameter naming and enforce it through readability-identifier-naming
Reviewed By: #libc, Mordante

Spies: Mordante, aheejin, libcxx-commits

Differential Revision: https://reviews.llvm.org/D156059
2023-07-24 19:54:12 -07:00
varconst
b5270ba20d [libc++] Remove the legacy debug mode.
See https://discourse.llvm.org/t/rfc-removing-the-legacy-debug-mode-from-libc/71026

Reviewed By: #libc, Mordante, ldionne

Differential Revision: https://reviews.llvm.org/D153672
2023-06-29 14:49:51 -07:00
varconst
cd0ad4216c [libc++][hardening][NFC] Introduce _LIBCPP_ASSERT_UNCATEGORIZED.
Replace most uses of `_LIBCPP_ASSERT` with
`_LIBCPP_ASSERT_UNCATEGORIZED`.

This is done as a prerequisite to introducing hardened mode to libc++.
The idea is to make enabling assertions an opt-in with (somewhat)
fine-grained controls over which categories of assertions are enabled.
The vast majority of assertions are currently uncategorized; the new
macro will allow turning on `_LIBCPP_ASSERT` (the underlying mechanism
for all kinds of assertions) without enabling all the uncategorized
assertions (in the future; this patch preserves the current behavior).

Differential Revision: https://reviews.llvm.org/D153816
2023-06-28 15:10:31 -07:00
Nikolas Klauser
f1ea0b11ca [libc++] Merge _LIBCPP_FUNC_VIS, _LIBCPP_TYPE_VIS and _LIBCPP_EXCEPTION_ABI into _LIBCPP_EXPORTED_FROM_ABI
These macros are always defined identically, so we can simplify the code a bit by merging them.

Reviewed By: ldionne, #libc

Spies: libcxx-commits, krytarowski, smeenai

Differential Revision: https://reviews.llvm.org/D152652
2023-06-15 08:56:45 -07:00
Hristo Hristov
7928ac4e6a [libc++][spaceship] P1612R2: Removed operator!= from locale
Implemented parts of P1612R2:
- Removed `operator!=` from `locale`

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D152654
2023-06-13 07:47:13 +03:00
Nikolas Klauser
140c375ab1 Revert "[libc++] Apply _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION only in classes that we have instantiated externally"
This reverts commit b3c9150062.

There were unexpected breakages downstream. @EricWF is investigating.
2023-05-24 08:48:18 -07:00
Nikolas Klauser
b3c9150062 [libc++] Apply _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION only in classes that we have instantiated externally
To make sure all member functions that require it are marked `_LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION` I compared the output of `objdump --syms lib/libc++.1.0.dylib` before and after, ignoring addresses.

Reviewed By: #libc, ldionne

Spies: Mordante, libcxx-commits, ldionne, arichardson, mstorsjo

Differential Revision: https://reviews.llvm.org/D150896
2023-05-23 13:32:55 -07:00
Nikolas Klauser
c847b8e24c [libc++] Make bsd_locale_fallbacks.h modular and move it into __locale/locale_base_api/
This is a first step towards granularizing `<locale>`.

Reviewed By: ldionne, #libc

Spies: arichardson, libcxx-commits, mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D146397
2023-04-21 05:36:41 +02:00
Nikolas Klauser
83ce139721 [libc++] Add hide_from_abi check for classes
We already have a clang-tidy check for making sure that `_LIBCPP_HIDE_FROM_ABI` is on free functions. This patch extends this to class members. The places where we don't check for `_LIBCPP_HIDE_FROM_ABI` are classes for which we have an instantiation in the library.

Reviewed By: ldionne, Mordante, #libc

Spies: jplehr, mikhail.ramalho, sstefan1, libcxx-commits, krytarowski, miyuki, smeenai

Differential Revision: https://reviews.llvm.org/D142332
2023-04-16 15:23:23 +02:00
Mark de Wever
e8cfbfd05a [libc++] Granularize system_error.
Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D147853
2023-04-09 17:57:14 +02:00
Nikolas Klauser
0a4aa8a122 [libc++] Granularize <type_traits> includes
Reviewed By: ldionne, #libc, #libc_abi

Spies: #libc_vendors, smeenai, libcxx-commits

Differential Revision: https://reviews.llvm.org/D145320
2023-03-08 22:05:04 +01:00
Nikolas Klauser
3c7a7a7b46 [libc++][NFC] Rename _LIBCPP_EXPLICIT_AFTER_CXX11 to _LIBCPP_EXPLICIT_SINCE_CXX14
We renamed the `_LIBCPP_CONSTEXPR_` a while ago. This matches the change for `_LIBCPP_EXPLICIT_`.

Reviewed By: Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D143165
2023-02-05 00:22:53 +01:00
Louis Dionne
5efc81166d [libc++] Remove HIDE_FROM_ABI from virtual functions
_LIBCPP_HIDE_FROM_ABI (which is what _LIBCPP_INLINE_VISIBILITY is) uses
ABI tags to avoid ODR violations when linking together object files
compiled against different versions of libc++. However, pointer
authentication uses the mangled name of the function to sign the
function pointer in the vtable, which means that the ABI tag effectively
changes how the pointers are signed.

This leads to PAC failures when passing an object that holds one of these
pointers in its vtable across an ABI boundary: one side will sign the
pointer using one function mangling (with one ABI tag), and the other
side will authenticate the pointer expecting it to have a different
mangled name, which won't work.

To make sure this does not regress in the future, this patch also adds
a clang-query test to detect incorrect applications of _LIBCPP_HIDE_FROM_ABI.

Differential Revision: https://reviews.llvm.org/D140453
2023-01-09 10:29:42 -05:00
Nikolas Klauser
430b397f67 [libc++] Granularize <type_traits> includes in <iterator>
Reviewed By: Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D140621
2022-12-27 02:32:16 +01:00
Nikolas Klauser
841399a218 [libc++] Add custom clang-tidy checks
Reviewed By: #libc, ldionne

Spies: jwakely, beanz, smeenai, cfe-commits, tschuett, avogelsgesang, Mordante, sstefan1, libcxx-commits, ldionne, mgorny, arichardson, miyuki

Differential Revision: https://reviews.llvm.org/D131963
2022-12-23 15:42:13 +01:00
Louis Dionne
b95379d20e [libc++][NFC] Add assertions before calling memmove
Since we're checking preconditions for calling memmove, we might
as well do that properly.

Differential Revision: https://reviews.llvm.org/D138798
2022-11-28 11:10:04 -05:00
Nikolas Klauser
3574b800cf [libc++][clang-tidy] Enable readability-simplify-boolean-expr
Reviewed By: ldionne, #libc

Spies: Eugene.Zelenko, aheejin, libcxx-commits, xazax.hun

Differential Revision: https://reviews.llvm.org/D137804
2022-11-24 00:42:19 +01:00
Louis Dionne
3465f02259 [libc++][NFC] Add missing conditionals for the existence of wide characters
Differential Revision: https://reviews.llvm.org/D138435
2022-11-21 18:00:53 -05:00
Nikolas Klauser
59ef4b3686 [libc++] Split __allocator_destructor out of shared_ptr.h
Reviewed By: ldionne, huixie90, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D134479
2022-11-05 21:25:54 +01:00
Nikolas Klauser
89b356f05a [libc++] Granularize <concept> includes
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D137283
2022-11-05 20:59:29 +01:00
Nancy Wang
8266eefd91 [SystemZ][z/OS][libcxx]: fix the mask in stage2_float_loop function
This patch is to fix issue related to __stage2_float_loop function, float point value comparison is not working on EBCDIC mode because the mask is hard-coded and assumes character is ASCII, fix is to use toupper function when do the comparison.

Differential Revision: https://reviews.llvm.org/D118930
2022-10-18 15:56:18 -04:00
David Tenty
1379899518 [libc++] Replace some _LIBCPP_HIDDEN with _LIBCPP_HIDE_FROM_ABI
These "implementation detail" function templates were already
hidden and have no specializations in the dylib, so they seem like they can safely
use _LIBCPP_HIDE_FROM_ABI instead and have the abi tags applied as well.

Seems some of these got over looked (e.g. D129823) in various places, and they
won't be flagged by the new checks added in D129968, as they were
already hidden.

Reviewed by: ldionne

Differential Revision: https://reviews.llvm.org/D135504
2022-10-12 16:45:58 -04:00
Mark de Wever
ab7b776cf9 [libc++][locale] Removes an transitive include.
Removes <cstdarg> transitive include from <locale> in C++23.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D133254
2022-09-07 18:54:26 +02:00
Nikolas Klauser
5fab33af7f [libc++] Avoid instantiating type_trait classes
Use `using` aliases to avoid instantiating lots of types

Reviewed By: ldionne, #libc

Spies: libcxx-commits, miyuki

Differential Revision: https://reviews.llvm.org/D132785
2022-09-06 19:09:42 +02:00
Nikolas Klauser
d5e26775d0 [libc++] Granularize the rest of memory
Reviewed By: ldionne, #libc

Spies: vitalybuka, paulkirth, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D132790
2022-09-05 12:36:41 +02:00
Mark de Wever
e31c2a1b1a [NFC][libc++] Moves transitive includes location.
As discussed in D132284 they will be moved to the end.

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D133212
2022-09-03 10:06:16 +02:00
Vitaly Buka
bc8fd9c633 Revert "[libc++] Granularize the rest of memory"
Breaks buildbots.

This reverts commit 30adaa730c.
2022-09-02 19:42:49 -07:00
Nikolas Klauser
30adaa730c [libc++] Granularize the rest of memory
Reviewed By: ldionne, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D132790
2022-09-02 21:42:41 +02:00
Mark de Wever
8ff2d6af69 [libc++] Reduces the number of transitive includes.
This defines a new policy for removal of transitive includes.
The goal of the policy it to make it relatively easy to remove
headers when needed, but avoid breaking developers using and
vendors shipping libc++.

The method used is to guard transitive includes based on the
C++ language version. For the upcoming C++23 we can remove
headers when we want, but for other language versions we try
to keep it to a minimum.

In this code the transitive include of `<chrono>` is removed
since D128577 introduces a header cycle between `<format>`
and `<chrono>`. This cycle is indirectly required by the
Standard. Our cycle dependency tool basically is a grep based
tool, so it needs some hints to ignore cycles. With the input
of our transitive include tests we can create a better tool.
However that's out of the scope of this patch.

Note the flag `_LIBCPP_REMOVE_TRANSITIVE_INCLUDES` remains
unchanged. So users can still opt-out of transitives includes
entirely.

Reviewed By: #libc, ldionne, philnik

Differential Revision: https://reviews.llvm.org/D132284
2022-08-31 19:50:03 +02:00
Nikolas Klauser
4262b523ff [libc++][NFC] Enable modernize-use-override
Reviewed By: Mordante, #libc

Spies: aheejin, libcxx-commits, smeenai

Differential Revision: https://reviews.llvm.org/D124714
2022-08-25 20:55:08 +02:00
Nikolas Klauser
3ee9a50a14 [libc++] Implement P0618R0 (Deprecating <codecvt>)
Reviewed By: ldionne, #libc

Spies: cfe-commits, llvm-commits, libcxx-commits

Differential Revision: https://reviews.llvm.org/D127313
2022-06-30 16:47:50 +02:00
Louis Dionne
de4a57cb21 [libc++] Re-add transitive includes that had been removed since LLVM 14
This commit re-adds transitive includes that had been removed by
4cd04d1687, c36870c8e7, a83f4b9cda, 1458458b55, 2e2f3158c6,
and 489637e66d. This should cover almost all the includes that had
been removed since LLVM 14 and that would contribute to breaking user
code when releasing LLVM 15.

It is possible to disable the inclusion of these headers by defining
_LIBCPP_REMOVE_TRANSITIVE_INCLUDES. The intent is that vendors will
enable that macro and start fixing downstream issues immediately. We
can then remove the macro (and the transitive includes) by default in
a future release. That way, we will break users only once by removing
transitive includes in bulk instead of doing it bit by bit a every
release, which is more disruptive for users.

Note 1: The set of headers to re-add was found by re-generating the
        transitive include test on a checkout of release/14.x, which
        provided the list of all transitive includes we used to provide.

Note 2: Several includes of <vector>, <optional>, <array> and <unordered_map>
        have been added in this commit. These transitive inclusions were
        added when we implemented boyer_moore_searcher in <functional>.

Note 3: This is a best effort patch to try and resolve downstream breakage
        caused since branching LLVM 14. I wasn't able to perfectly mirror
        transitive includes in LLVM 14 for a few headers, so I added a
        release note explaining it. To summarize, adding boyer_moore_searcher
        created a bunch of circular dependencies, so we have to break
        backwards compatibility in a few cases.

Differential Revision: https://reviews.llvm.org/D128661
2022-06-27 22:18:19 -04:00
Louis Dionne
23d6cde14d [libc++] Add a test to pin down the set of transitive public includes
A situation that happens fairly often in libc++ is that we remove some
transitive includes in a header (either purposefully or not) and that
ends up breaking users. Of course, we want to be able to remove our
transitive includes, however it's also good to have a grip on that
to know which commit changed what and when. Furthermore, it's good
to accumulate include removals for a couple of releases to avoid
breaking users at every release for this reason.

This commit adds a test that should break whenever we remove an
include. Hence, it should allow us to track which headers include
which other headers transitively, giving us a traceable way to
remove headers.

Differential Revision: https://reviews.llvm.org/D128236
2022-06-23 16:23:34 -04:00
Mark de Wever
4cd04d1687 [libc++] Removes unneeded <iterator> includes.
Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D127675
2022-06-15 18:14:05 +02:00
Nikolas Klauser
3cd4531b9b [libc++] Granularize <iterator> includes
Reviewed By: ldionne, #libc

Spies: libcxx-commits, wenlei

Differential Revision: https://reviews.llvm.org/D127445
2022-06-10 22:43:57 +02:00
Nikolas Klauser
976f37050d [libc++] Granularize __string
Reviewed By: ldionne, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D127156
2022-06-09 21:04:18 +02:00
Louis Dionne
2ae52326da [libc++] Towards a simpler extern template story in libc++
The flexibility around extern template instantiation declarations in
libc++ result in a very complicated model, especially when support for
slightly different configurations (like the debug mode or assertions
in the dylib) are taken into account. That results in unexpected bugs
like http://llvm.org/PR50534 (and there have been multiple similar
bugs in the past, notably around the debug mode).

This patch gets rid of the _LIBCPP_DISABLE_EXTERN_TEMPLATE knob, which
I don't think is fundamental. Indeed, the motivation for that knob was to
avoid taking a dependency on the library, however that can be done better
by linking against the static library instead. And in fact, some parts of
the headers will always depend on things defined in the library, which
defeats the original goal of _LIBCPP_DISABLE_EXTERN_TEMPLATE.

Differential Revision: https://reviews.llvm.org/D103960
2022-06-08 22:05:07 -04:00
Louis Dionne
f3966eaf86 [libc++] Make the Debug mode a configuration-time only option
The debug mode has been broken pretty much ever since it was shipped
because it was possible to enable the debug mode in user code without
actually enabling it in the dylib, leading to ODR violations that
caused various kinds of failures.

This commit makes the debug mode a knob that is configured when
building the library and which can't be changed afterwards. This is
less flexible for users, however it will actually work as intended
and it will allow us, in the future, to add various kinds of checks
that do not assume the same ABI as the normal library. Furthermore,
this will make the debug mode more robust, which means that vendors
might be more tempted to support it properly, which hasn't been the
case with the current debug mode.

This patch shouldn't break any user code, except folks who are building
against a library that doesn't have the debug mode enabled and who try
to enable the debug mode in their code. Such users will get a compile-time
error explaining that this configuration isn't supported anymore.

In the future, we should further increase the granularity of the debug
mode checks so that we can cherry-pick which checks to enable, like we
do for unspecified behavior randomization.

Differential Revision: https://reviews.llvm.org/D122941
2022-06-07 16:33:53 -04:00
Sam Clegg
b86771a2f7 [libc++] Minor emscripten changes from downstream
Differential Revision: https://reviews.llvm.org/D126583
2022-05-28 06:44:27 -07:00
David Spickett
ab07d06e7b [libcxx] Reject month 0 in get_date/__get_month
[libcxx] Reject month 0 in get_date/__get_month

This fixes #47663.

Months in dates should be >= 1 and <= 12.
We parse up to two digits then minus one, because
we want to store this as "months since January"
(0-11).

However we didn't check that the result of that
was not -1. For example if you had (MM/DD/YYYY)
00/21/2022.

Added tests for:
* Failing if month is 0
* Failing if month is 13
* Allowing a leading zero in month e.g. "01"

Note that libc++ and libstdc++ return different
values on parsing failure, and MSVC STL returns
end of stream instead.

Handle the first two by checking for defines, MSVC STL
expects these tests to fail for other reasons already:
https://github.com/microsoft/STL/blob/main/tests/libcxx/expected_results.txt#L372
so not handling that case here.

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D124175
2022-05-06 10:07:53 +00:00
Louis Dionne
385cc25a53 [libc++] Ensure that all public C++ headers include <__assert>
This patch changes the requirement for getting the declaration of the
assertion handler from including <__assert> to including any public
C++ header of the library. Note that C compatibility headers are
excluded because we don't implement all the C headers ourselves --
some of them are taken straight from the C library, like assert.h.

It also adds a generated test to check it. Furthermore, this new
generated test is designed in a way that will make it possible to
replace almost all the existing test-generation scripts with this
system in upcoming patches.

Differential Revision: https://reviews.llvm.org/D122506
2022-03-30 15:05:31 -04:00
Nikolas Klauser
01df675191 [libc++] Enable modernize-loop-convert
Reviewed By: ldionne, Mordante, #libc

Spies: var-const, aheejin, libcxx-commits

Differential Revision: https://reviews.llvm.org/D121216
2022-03-18 20:34:19 +01:00
Louis Dionne
f87aa19be6 [libc++] Move everything related solely to _LIBCPP_ASSERT to its own file
This is the first step towards disentangling the debug mode and assertions
in libc++. This patch doesn't make any functional change: it simply moves
_LIBCPP_ASSERT-related stuff to its own file so as to make it clear that
libc++ assertions and the debug mode are different things. Future patches
will make it possible to enable assertions without enabling the debug
mode.

Differential Revision: https://reviews.llvm.org/D119769
2022-02-16 12:49:50 -05:00