5234 Commits

Author SHA1 Message Date
Gergely Nagy
afec0f0ec3 [libcxx] Make stdatomic.h work when included from a C source file
If a C source file includes the libc++ stdatomic.h, compilation will
break because (a) the C++ standard check will fail (which is expected),
and (b) `_LIBCPP_COMPILER_CLANG_BASED` won't be defined because the
logic defining it in `__config` is guarded by a `__cplusplus` check, so
we'll end up with a blank header. Move the detection logic outside of
the `__cplusplus` check to make the second check pass even in a C context
when you're using Clang. Note that `_LIBCPP_STD_VER` is not defined when
in C mode, hence stdatomic.h needs to check if in C++ mode before using
that macro to avoid a warning.

In an ideal world, a C source file wouldn't be including the libc++
header directory in its search path, so we'd never have this issue.
Unfortunately, certain build environments make this hard to guarantee,
and in this case it's easy to tweak this header to make it work in a C
context, so I'm hoping this is acceptable.

Fixes https://github.com/llvm/llvm-project/issues/57710.

Differential Revision: https://reviews.llvm.org/D134591
2022-09-27 13:13:11 -04:00
Hui Xie
4851fbc3cf fix errors on passing input iterator to std::views::take
In the implementation of `std::views::take`, it uses `subrange<Iter>` as part of the return type. But in case of input iterator, `subrange<Iter>` can be ill-formed

Differential Revision: https://reviews.llvm.org/D133220
2022-09-25 15:41:13 +01:00
Mark de Wever
34dfdd17af [libc++][test] Improves transitive includes.
This test generates the include graph of the Standard headers of libc++ in
a CSV file. This was originally used to generate graphviz dot files. During
review it was noticed these files have all information needed to replace
the current transitive includes. Therefore the output, with the same information as the .dot file is stored in a .csv file. This removes
all the existing transitive include files.

The .cvs can be converted by a .dot file by the script in D134188.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D133127
2022-09-25 13:20:27 +02:00
Mark de Wever
088c7f7e3c [libc++] Applies P0602R4 retro-actively.
While testing a test failure of C++17 with Clang ToT it was noticed the
paper
  P0602R4 variant and optional should propagate copy/move triviality
was not applied as a DR in libc++.

This was discovered while investigating the issue "caused by" D131479.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D133326
2022-09-20 19:01:34 +02:00
Mark de Wever
d23f609d9c [libc++][test] Adds format string helper.
Update the formatter day tests to the new style.
Other test will be done separately.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D134031
2022-09-20 18:58:37 +02:00
Mark de Wever
f2a263512c [libc++][chrono] Removes format include.
Switch to the new granular format_functions header. Since the chrono's
format dependency in C++20 hasn't been in a release it's save to remove
it.

Depends on D133665

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D133796
2022-09-20 18:58:13 +02:00
Mark de Wever
00798e5006 [libc++][format] Granularizes the format header.
Moves the last pieces of code to its own header.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D133665
2022-09-20 18:57:10 +02:00
Louis Dionne
f1a601fe88 [libc++] Always query the compiler to find whether a type is always lockfree
In https://llvm.org/D56913, we added an emulation for the __atomic_always_lock_free
compiler builtin when compiling in Freestanding mode. However, the emulation
did (and could not) give exactly the same answer as the compiler builtin,
which led to a potential ABI break for e.g. enum classes.

After speaking to the original author of D56913, we agree that the correct
behavior is to instead always use the compiler builtin, since that provides
a more accurate answer, and __atomic_always_lock_free is a purely front-end
builtin which doesn't require any runtime support. Furthermore, it is
available regardless of the Standard mode (see https://godbolt.org/z/cazf3ssYY).

However, this patch does constitute an ABI break. As shown by https://godbolt.org/z/1eoex6zdK:
- In LLVM <= 11.0.1, an atomic<enum class with 1 byte> would not contain a lock byte.
- In LLVM >= 12.0.0, an atomic<enum class with 1 byte> would contain a lock byte.

This patch breaks the ABI again to bring it back to 1 byte, which seems
like the correct thing to do.

Fixes #57440

Differential Revision: https://reviews.llvm.org/D133377
2022-09-19 11:10:02 -04:00
Nikolas Klauser
7afa1598a3 [libc++] Avoid including <tuple> in compressed_pair.h
compressed_pair is widely used in the library, but most of the uses don't use the tuple parts. To avoid including <tuple> everywhere, use the forward declaration instead in compressed_pair.h

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D133331
2022-09-18 10:49:35 +02:00
Nikolas Klauser
d3a0ac92e9 [libc++] Add test to ensure that type trait aliases in dependent return types can be mangled
Reviewed By: ldionne, #libc

Spies: libcxx-commits, jeroen.dobbelaere

Differential Revision: https://reviews.llvm.org/D133196
2022-09-17 14:25:09 +02:00
Xing Xue
8ace9ea258 [libc++][lit][AIX] Enable test case last_write_time.pass.cpp for AIX
Summary:
This patch enables libc++ LIT test case last_write_time.pass.cpp for AIX. Because system call utimensat() of AIX which is used in the libc++ implementation of last_write_time() does not accept the times parameter with a negative tv_sec or tv_nsec field, testing of setting file time to before epoch time is excluded for AIX.

Reviewed by: ldionne, libc++

Differential Revision: https://reviews.llvm.org/D133124
2022-09-16 16:08:40 -04:00
Mark de Wever
c0ac3c1142 [NFC][libc++][test] Uses public functions.
Replaces std::__format_context_create with the public wrapper
test_format_context_create.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D133781
2022-09-16 14:57:21 +02:00
Colin Cross
13c6828bed Fix std::fpos pretty printer on musl
The mbstate_t field in std::fpos is an opaque type provied by libc,
and musl's implementation does not match the one used by glibc.
Change StdFposPrinter to verify its assumptions about the layout
of mbstate_t, and leave out the state printing if it doesn't match.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D132983
2022-09-15 21:58:24 +00:00
Mark de Wever
24e1736d84 [libc++][random] Removes transitive includes.
It seems these includes are still provided by the sub headers, so it only
removes the duplicates.

There is no change in the list of includes, but the change affects the
modular build. By not having the includes in the top-level header the
module map has changed. This uncovers missing includes in the tests
and missing exports in the module map. This causes the huge amount of
changes in the patch.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D133252
2022-09-11 17:39:27 +02:00
Tom Honermann
7e7013c5d4 [libc++][cuchar] Declare std::c8rtomb and std::mbrtoc8 in <cuchar> if available.
This change implements the C library dependent portions of P0482R6
(char8_t: A type for UTF-8 characters and strings (Revision 6)) by
declaring std::c8rtomb() and std::mbrtoc8() in the <cuchar> header
when implementations are provided by the C library as specified by
WG14 N2653 (char8_t: A type for UTF-8 characters and strings
(Revision 1)) as adopted for C23.

A _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 macro is defined by the libc++ __config
header unless it is known that the C library provides these functions
in the current compilation mode. This macro is used for testing purposes
and may be of use to libc++ users. At present, the only C library known
to implement these functions is GNU libc as of its 2.36 release.

Reviewed By: ldionne

Differential Revision: https://reviews.llvm.org/D130946
2022-09-10 21:10:33 -04:00
Louis Dionne
d529e8110b [libc++] Fix compilation error on platforms that don't implement std::tm
Instead of mentioning tm directly in the definition of __convert_to_tm,
take it as a template argument. As a fly-by also fix incorrect Lit feature
(should have been no-localization instead of libcpp-has-no-localization).

Differential Revision: https://reviews.llvm.org/D133490
2022-09-08 18:10:53 -04:00
Mark de Wever
3695cf2065 [libc++] Removes Clang 13 support.
Reviewed By: #libc, ldionne, jloser

Differential Revision: https://reviews.llvm.org/D133435
2022-09-08 17:51:52 +02:00
Mark de Wever
de4a2b7381 [libc++] Fixes CI.
It seems merging the changes in transitive macros and recent commits
conflicted.
2022-09-07 19:58:21 +02: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
Mark de Wever
e5d2d3eafb [libc++][chrono] Implements formatter day.
This implements the enabled specializaton
template<class charT> struct formatter<chrono::day, charT>;

and
template<class charT, class traits>
    basic_ostream<charT, traits>&
      operator<<(basic_ostream<charT, traits>& os, const day& d);

Implements:
- LWG 3241 chrono-spec grammar ambiguity in §[time.format]

Partially implements:
- P1361 Integration of chrono with text formatting

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D128577
2022-09-07 18:44:04 +02:00
Mark de Wever
b490c8a662 [libc++][format] Updates feature-test macros.
During the discussion on the SG-10 mailinglist regarding the format
feature-test macros voted in during the last plenary it turns out libc++
can't mark the format feature-test macro as implemented.

According to
  https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations#__cpp_lib_format
the not yet implemented paper
  P1361R2 Integration of chrono with text formatting
affects the feature test macro.

Note that P1361R2 doesn't mention the feature-test macro nor is there an
LWG-issue to address the issue. The reporter of the issue didn't recall
where this requirement exactly has been decided.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D133271
2022-09-07 18:39:39 +02:00
Vitaly Buka
beb413acce [test][libcxx] Mark ubsan test as UNSUPPORTED
It inconsistently fails on bots.
2022-09-06 13:44:28 -07:00
Nikolas Klauser
2d52c6bfae [libc++] Granularize __tuple
Reviewed By: ldionne, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D133081
2022-09-05 16:36:24 +02:00
Nikolas Klauser
e0b3356e67 [libc++] Enable rvalue overloads for pair in C++03
We require rvalue support anyways, so let's use it.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D133013
2022-09-05 14:40:17 +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
Igor Zhukov
30dadaa2eb [libc++] Implement P2273R3 (constexpr unique_ptr)
Reviewed By: mordante, #libc

Differential Revision: https://reviews.llvm.org/D131315
2022-09-03 18:49:50 +07:00
Mark de Wever
56065c4c8e [NFC][libc++] Removes GCC-11 support.
GCC-11 isn't supported in libc++ so remove UNSUPPORTED directives.
2022-09-03 13:20:10 +02:00
Mark de Wever
ba6ad62081 [libc++] Fixes generated output CI job.
It seems there was another file with the same issue, which didn't show
up initially.
2022-09-03 10:19:35 +02:00
Mark de Wever
ff06c2ded3 [libc++] Fixes generated output CI job. 2022-09-03 10:04:44 +02:00
Vitaly Buka
bc8fd9c633 Revert "[libc++] Granularize the rest of memory"
Breaks buildbots.

This reverts commit 30adaa730c4768b5eb06719c808b2884fcf53cf3.
2022-09-02 19:42:49 -07:00
Igor Zhukov
3a49cffe3a [libc++] Implement P2445R1 (std::forward_like)
Co-authored-by: A. Jiang <de34@live.cn>

Reviewed By: philnik, huixie90, #libc

Differential Revision: https://reviews.llvm.org/D132327
2022-09-03 09:17:53 +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
Nikolas Klauser
cac9a6fb0e [libc++] Remove noexcept specifier from operator""s
For some reason `operator""s(const char8_t*, size_t)` was marked `noexcept`. Remove it and add regression tests.

Reviewed By: ldionne, huixie90, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D132340
2022-09-02 21:37:32 +02:00
Nikolas Klauser
3c355e2881 [libc++] Enable [[nodiscard]] extensions by default
Adding `[[nodiscard]]` to functions is a conforming extension and done extensively in the MSVC STL.

Reviewed By: ldionne, EricWF, #libc

Spies: #libc_vendors, cjdb, mgrang, jloser, libcxx-commits

Differential Revision: https://reviews.llvm.org/D128267
2022-09-02 21:34:20 +02:00
Mark de Wever
9185d6e6bc [libc++] Avoids self references in transitive include test.
The output of --trace-includes starts with the header whose includes are
being processed. Since the sanitize script processed all lines this
include was added to the list of transitive includes. This looks odd
since it implies all headers have a cyclic dependency on themselves.
This change removes this self-include.

Instead of just dropping the first line extract that header and use it
to guard against cyclic dependencies in the header itself.

The regex used has a small improvement; don't capture groups that aren't
extracted.

Depends on D132284

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D132787
2022-09-01 20:33:37 +02:00
Mark de Wever
2928b230ce [NFC][libc++] char_traits code cleanups.
These cleanups were identified while working on D130295.

Reviewed By: #libc, ldionne, philnik

Differential Revision: https://reviews.llvm.org/D131185
2022-08-31 22:18:10 +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
Mark de Wever
f92c733cc2 [libc++][format] Fixes floating-point formatting.
Formatting the alternate form for the general categories should keep the
trailing zeros. This was reported by @fsb4000 in D131336.

The default format uses general formatting but this should not keep the
trailing zeros so the default format is not passed to the formatter.

While testing I found an off by one error; finding the exponent character
`e` in 1e+03 will start at after the `1` so a size of `4` can contain an
exponent.

Reviewed By: fsb4000, ldionne, #libc

Differential Revision: https://reviews.llvm.org/D131417
2022-08-31 19:25:53 +02:00
Mark de Wever
36e0e2c485 [libc++][format] Allows width arg-id with value 0.
Implements:
- LWG3721 Allow an arg-id with a value of zero for width in std-format-spec

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D130649
2022-08-31 19:19:13 +02:00
Mark de Wever
87dd8c7289 [libc++][CI] increases constexpr evaluation limit.
This was discovered as an issue in D131317.

Depends on D131835

Reviewed By: #libc, var-const, ldionne, philnik

Differential Revision: https://reviews.llvm.org/D131836
2022-08-31 19:16:40 +02:00
Mark de Wever
722ee9049d [libc++] Tests transitive includes for all C++03.
A followup of D132534 with C++03 enabled after fixing the experimental
PMR issues.

Depends on D132582

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D132584
2022-08-31 19:16:01 +02:00
Mark de Wever
a72f6b032c [libc++] Improves feature-test macro diagnostics.
This was mentioned in review D131326.

Reviewed By: var-const, #libc, philnik

Differential Revision: https://reviews.llvm.org/D132293
2022-08-30 17:56:35 +02:00
Nikolas Klauser
a13822b35d [libc++] Simplify type_traits a bit more
Reviewed By: ldionne, #libc

Spies: STL_MSFT, CaseyCarter, huixie90, libcxx-commits

Differential Revision: https://reviews.llvm.org/D129094
2022-08-27 10:19:11 +02:00
Nikolas Klauser
59d246e55f [libc++] Remove __deque_base
This patch simplifies the implementation of `deque` by removing the `__deque_base` class which results in a lot less indirections and removes the need for `__base::`.

Reviewed By: ldionne, #libc

Spies: AdvenamTacet, libcxx-commits

Differential Revision: https://reviews.llvm.org/D132081
2022-08-26 21:59:33 +02:00
Nikolas Klauser
786366b18f [libc++][NFC] Remove some of the code duplication in the string tests
Reviewed By: ldionne, #libc, huixie90

Spies: huixie90, libcxx-commits, arphaman

Differential Revision: https://reviews.llvm.org/D131856
2022-08-26 21:57:42 +02:00
Nikolas Klauser
98f6a56f5e [libc++] Enable hash only for the correct types
Also implement LWG3705.
Fixes https://github.com/llvm/llvm-project/issues/55823

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D132338
2022-08-26 17:40:23 +02:00
Nikolas Klauser
56e1f0f056 [libc++][NFC] Remove reserved names from support/constexpr_char_traits.h
Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D132341
2022-08-26 17:37:47 +02:00
Joe Loser
eb1ceb17ae [libc++][test] Use TEST_HAS_NO_CHAR8_T to simplify #ifdefs. NFCI.
Many tests in `libcxx/test/std/strings` use
`#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L`
which can be replaced with the more terse `#ifndef TEST_HAS_NO_CHAR8_T`.

Differential Revision: https://reviews.llvm.org/D132626
2022-08-25 21:09:10 -06:00
Louis Dionne
f2d957f036 [libc++] Allow specifying conditional compile flags dependent on basic Lit features
This patch adds support for passing basic Lit features to the
ADDITIONAL_COMPILE_FLAGS keyword by enclosing them in parentheses.
This is done to support https://llvm.org/D131836.

In the future, we should instead add proper support for conditional
keywords in Lit, so that we can evaluate arbitrary Lit boolean
expressions such as `ADDITIONAL_COMPILE_FLAGS(x && !y): -flag`.

Note that I can see this being exceptionally useful when combined
with RUN commands, which would allow using different commands on
different systems. For example:

     RUN(!buildhost=windows): something
     RUN(buildhost=windows): something-else

Differential Revision: https://reviews.llvm.org/D132575
2022-08-25 17:33:44 -04:00
Nikolas Klauser
6ffd39731a [libc++][NFC] Remove tab in filebuf/traits_mismatch.fail.cpp 2022-08-25 22:46:17 +02:00