Commit Graph

7596 Commits

Author SHA1 Message Date
zoecarver
7ed7d4ccb8 [libcxx][gardening] Move all algorithms into their own headers.
This is a fairly mechanical change, it just moves each algorithm into its own header. This is a NFC.

Note: during this change, I burned down all the includes, so this follows "include only and exactly what you use."

Differential Revision: https://reviews.llvm.org/D103583
2021-06-04 09:37:12 -07:00
Louis Dionne
a9c9183ca4 [libc++] Use the using_if_exists attribute when provided
As discussed on cfe-dev [1], use the using_if_exists Clang attribute when
the compiler supports it. This makes it easier to port libc++ on top of
new platforms that don't fully support the C Standard library.

Previously, libc++ would fail to build when trying to import a missing
declaration in a <cXXXX> header. With the attribute, the declaration will
simply not be imported into namespace std, and hence it won't be available
for libc++ to use. In many cases, the declarations were *not* actually
required for libc++ to work (they were only surfaced for users to use
them as std::XXXX), so not importing them into namespace std is acceptable.

The same thing could be achieved by conscious usage of `#ifdef` along
with platform detection, however that quickly creates a maintenance
problem as libc++ is ported to new platforms. Furthermore, this problem
is exacerbated when mixed with vendor internal-only platforms, which can
lead to difficulties maintaining a downstream fork of the library.

For the time being, we only use the using_if_exists attribute when it
is supported. At some point in the future, we will start removing #ifdef
paths that are unnecessary when the attribute is supported, and folks
who need those #ifdef paths will be required to use a compiler that
supports the attribute.

[1]: http://lists.llvm.org/pipermail/cfe-dev/2020-June/066038.html

Differential Revision: https://reviews.llvm.org/D90257
2021-06-04 09:55:21 -04:00
Martin Storsjö
b0cc7b53a5 [libcxx] Don't use an undefined '+' in unsigned/octal/hexal print formats
If building code like this:

    unsigned long val = 1000;
    snprintf(buf, sizeof(buf), "%+lu", val);

with clang, clang warns

    warning: flag '+' results in undefined behavior with 'u' conversion specifier [-Wformat]

Therefore, don't construct such undefined format strings. (There's
no compiler warnings here, as the compiler can't inspect dynamically
assembled format strings.)

This fixes number formatting in mingw-w64 if built with
`__USE_MINGW_ANSI_STDIO` defined (there, the '+' flag causes a
leading plus to be printed when formatting unsigned numbers too,
while the '+' flag doesn't cause any extra leading plus in other
stdio implementations).

Differential Revision: https://reviews.llvm.org/D103444
2021-06-04 12:07:30 +03:00
Louis Dionne
d515a52a3a [libc++] Simplify apple-install-libcxx since we always use the same CMake cache 2021-06-03 18:26:38 -04:00
Louis Dionne
db757ba7c5 [libc++] Define _LIBCPP_NO_NATIVE_SEMAPHORES even outside of pthread
<semaphore> needs to know about whether native semaphores are supported
or not, even if we're not using the pthread API.
2021-06-03 18:18:42 -04:00
Louis Dionne
56b6e4e2df [libc++] Also build the static library in the Apple cache 2021-06-03 18:15:20 -04:00
Louis Dionne
e4d3a993c2 [libc++] Implement LWG3435 (constraints on reverse_iterator and move_iterator) 2021-06-03 15:49:41 -04:00
Louis Dionne
10d3869952 [libc++] NFC: Tidy up the reverse_iterator tests
Incidentally, that fixes an error with the modules build.
2021-06-03 15:00:13 -04:00
Christopher Di Bella
f1417eb9b1 [libcxx][module-map] creates submodules for private headers
Most of our private headers need to be treated as submodules so that
Clang modules can export things correctly. Previous commits that split
monolithic headers into smaller chunks were unaware of this requirement,
and so this is being addressed in one fell swoop. Moving forward, most
new headers will need to have their own submodule (anything that's
conditionally included is exempt from this rule, which means `__support`
headers aren't made into submodules).

This hasn't been marked NFC, since I'm not 100% sure that's the case.

Differential Revision: https://reviews.llvm.org/D103551
2021-06-03 18:18:30 +00:00
Mark de Wever
fd3a526085 [libc++][nfc] Add more nasty macros.
D101613 added some macros used by Microsofts SAL. D103425 uses `__pre`
and `__post`. They are also used by SAL and cause issues when used on
Windows. Add them to the blacklist making it easier to figure out what
the issue is.

Differential Revision: https://reviews.llvm.org/D103541
2021-06-03 18:22:52 +02:00
Louis Dionne
2cf78d4ead [libc++] Remove unused variable warnings
Since D100581, Clang started flagging this variable which is set but
never read. Based on comparing this function with __match_at_start_posix_nosubs
(which is very similar), I am pretty confident that `__j` was simply left
behind as an oversight in Howard's 6afe8b0a23.

Also workaround some unused variable warnings in the <random> tests.
It's pretty lame that we're not asserting the skew and kurtosis of
the binomial and negative binomial distributions, but that should be
tackled separately.

Differential Revision: https://reviews.llvm.org/D103533
2021-06-03 09:43:08 -04:00
Louis Dionne
875ff8e059 [libc++] Enable tests for the experimental library by default
This matches the fact that we build the experimental library by default.
Otherwise, by default we'd be building the library but not testing it,
which is inconsistent.

Differential Revision: https://reviews.llvm.org/D102109
2021-06-02 18:39:27 -04:00
Louis Dionne
05d164b25c Revert "[libc++] NFC: Move unwrap_iter to its own header"
This reverts commit 924ea3bb53 *again*, this time because it broke the
LLDB build with modules. We need to figure out what's up with the libc++
modules build once and for all.

Differential Revision: https://reviews.llvm.org/D103369
2021-06-02 15:58:27 -04:00
Daniel McIntosh
06e047227d [libcxx][NFC] Tidy up calculation of __nbuf in num_put::do_put, and add comments
In 07ef8e6796 and 3ed9f6ebde, `__nbuf` started to diverge from the amount
of space that was actually needed for the buffer. For 32-bit longs for example,
we allocate a buffer that is one larger than needed. Moreover, it is no longer
clear exactly where the extra +1 or +2 comes from - they're just numbers pulled
from thin air. This PR cleans up how `__nbuf` is calculated, and adds comments
to further clarify where each part comes from.

Specifically, it corrects the underestimation of the max size buffer needed
that the above two commits had to compensate for. The root cause looks to be
the use of signed type parameters to numeric_limits<>::digits. Since digits
only counts non-sign bits, the calculation was acting as though (for a signed
64-bit type) the longest value we would print was 2^63 in octal. However,
printing in octal treats values as unsigned, so it is actually 2^64. Thus,
using unsigned types and changing the final +2 to a +1 is probably a better
option.

Reviewed By: #libc, ldionne, Mordante

Differential Revision: https://reviews.llvm.org/D103339
2021-06-02 11:46:17 -04:00
Louis Dionne
ae4dad2b73 [libc++] Add a CI job to test libc++ when building for 32 bit
Differential Revision: https://reviews.llvm.org/D92508
2021-06-01 22:07:43 -04:00
Louis Dionne
924ea3bb53 [libc++] NFC: Move unwrap_iter to its own header
This re-applies 9968896cd6, which was reverted in b13edf6e90 because
it broke the build.

Differential Revision: https://reviews.llvm.org/D103369
2021-06-01 21:46:59 -04:00
zoecarver
065cf3f9d7 [libcxx][ranges] Add default_sentinel and default_sentinel_t.
Refs https://eel.is/c++draft/default.sentinel and https://eel.is/c++draft/iterator.synopsis

Differential Revision: https://reviews.llvm.org/D103487
2021-06-01 14:03:54 -07:00
Louis Dionne
ba95fa03ce [libc++] Fix the std_include.sh.cpp test that has been failing since c9385297ce
The compiler used on Apple bots doesn't know about -std=c++20 yet, so
we can't use that just yet.

Differential Revision: https://reviews.llvm.org/D103475
2021-06-01 16:31:51 -04:00
zoecarver
5671ff20d9 [libcxx] Implement view.interface.
This will unblock work on ranges::view. Based on D101396.

Refs http://eel.is/c++draft/view.interface.

Differential Revision: https://reviews.llvm.org/D101737
2021-06-01 12:34:47 -07:00
Louis Dionne
95cb06d234 [libc++] Temporary hack to unbreak CI
Until I figure out what the issue is with this test on AppleClang (and
in particular which change caused it), I want to avoid all CI being broken.
2021-06-01 13:49:55 -04:00
Martin Storsjö
41d7909368 [libcxx] [test] Fix the _supportsVerify check on Windows by fixing quoting
The pipes.quote function quotes using single quotes, the same goes
for the newer shlex.quote (which is the preferred form in Python 3).
This isn't suitable for quoting in command lines on Windows (and the
documentation for shlex.quote even says it's only usable for Unix
shells).

In general, the python subprocess.list2cmdline function should do
proper quoting for the platform's current shell. However, it doesn't
quote the ';' char, which we pass within some arguments to run.py.
Therefore use the custom reimplementation from lit.TestRunner which
is amended to quote ';' too.

The fact that arguemnts were quoted with single quotes didn't matter
for command lines that were executed by either bash or the lit internal
shell, but if executing things directly using subprocess.call, as in
_supportsVerify, the quoted path to %{cxx} fails to be resolved by the
Windows shell.

This unlocks 114 tests that previously were skipped on Windows.

Differential Revision: https://reviews.llvm.org/D103310
2021-06-01 09:51:41 +03:00
Martin Storsjö
23f7f56cec [libcxx] [test] Fix the include_as_c.sh.cpp test in MSVC configurations
Avoid including a header that is known not to work with clang in MSVC
mode when compiling as C.

(Alternatively, this could be something like "XFAIL: clang && msvc",
but I think it's more useful to actually check the rest of the test
instead of expecting the whole test to fail.)

Differential Revision: https://reviews.llvm.org/D103400
2021-05-31 22:13:22 +03:00
Martin Storsjö
be34d5f74a [libcxx] [test] Remove an incorrect TEST_HAS_ALIGNED_ALLOC define from test_macros.h
This was added inconsistently in
19fd9039ca242f408493b5c662f9d908eab8555e; Windows doesn't have the
aligned_alloc function (neither MSVC nor MinGW toolchains) and we don't
define _LIBCPP_HAS_ALIGNED_ALLOC while building libcxx.

Differential Revision: https://reviews.llvm.org/D103399
2021-05-31 22:13:22 +03:00
Martin Storsjö
c8644ae1e9 [libcxx] Define LIBCPP_HAS_TIMESPEC_GET for MSVC configurations
This define was out of sync with the corresponding define in tests, it
was added inconsistently in 171c77b7da.

Modern MSVC environments do have these typedefs and functions.

Differential Revision: https://reviews.llvm.org/D103398
2021-05-31 22:13:22 +03:00
Martin Storsjö
b48a256e9c [libcxx] [test] Don't look for the literal spelling __mbstate_t in warnings
While the code uses the type name `std::mbstate_t`, the warning message
mentions the original underlying type, which is a C library internal
type name.

On Windows this type is called `_Mbstatet` instead of `__mbstate_t`. Use
expect-warning-re to avoid spelling out the literal name of the type.

Due to issues with the detection of the clang-verify feature, these
tests have been skipped in the Windows CI configuration so far.

Differential Revision: https://reviews.llvm.org/D103309
2021-05-31 22:13:21 +03:00
Christopher Di Bella
bf92bdad77 [libcxx][nfc] moves std advance, next, and prev into their headers
Differential Revision: https://reviews.llvm.org/D103329
2021-05-31 17:14:52 +00:00
Harald van Dijk
73cdc7599b [libc++] [test] Fix a few tests for 32-bit x86
Fixes bug https://llvm.org/PR48939.

Differential Revision: https://reviews.llvm.org/D102359
2021-05-31 12:38:43 -04:00
Louis Dionne
41bdf64d3e [libc++] Update all the pre-defined iterator types for C++20
Make sure we provide the correct It::difference_type member and update
the tests and synopses to be accurate.

Supersedes D102657 and D103101 (thanks to the original authors).

Differential Revision: https://reviews.llvm.org/D103273
2021-05-31 11:59:40 -04:00
Arthur O'Dwyer
d39f5c3cb9 [libc++] Avoid result_type and unary/binary_function in <valarray>.
Give each of the relevant functional operators a `__result_type`
instead, so that we can keep using those typedefs in <valarray>
even when the public binder typedefs are removed in C++20.

Differential Revision: https://reviews.llvm.org/D103371
2021-05-31 11:29:16 -04:00
Martin Storsjö
7d7b72bad7 [libcxx] [test] Add UNSUPPORTED: msvc in a couple verify.cpp tests
Due to issues with the detection of the clang-verify feature, these
tests have been skipped in the Windows CI configuration so far.

Differential Revision: https://reviews.llvm.org/D103308
2021-05-31 10:58:32 +03:00
Arthur O'Dwyer
bfbd73f87d [libc++] Alphabetize and include-what-you-use. NFCI.
Differential Revision: https://reviews.llvm.org/D102781
2021-05-29 19:54:48 -04:00
Arthur O'Dwyer
c9385297ce [libc++] [modules] Add __threading_support to the modulemap.
It looks to me as if *every* helper header needs to be added to the modulemap,
actually; which is unfortunate since we keep proliferating them at such a
rapid pace.
2021-05-29 19:54:38 -04:00
Arthur O'Dwyer
5cc55fdb57 [libc++] [test] Update "test_compare.h" users to avoid removed-in-C++20 members. NFCI.
Drive-by minor improvements to a couple of uses of min_pointer.

Differential Revision: https://reviews.llvm.org/D103366
2021-05-29 16:54:24 -04:00
Mark de Wever
b13edf6e90 Revert "[libc++] NFC: Move unwrap_iter to its own header"
This reverts commit 9968896cd6.

This commit seems to cause the build failures of main.
2021-05-29 09:50:26 +02:00
Arthur O'Dwyer
8a5f0d8838 [libc++] [test] Constexpr-ify a couple of insert-iterator tests.
This should have been done in D96385; thanks ldionne for the catch!
Also, make the back/front inserter behavior tests a little more thorough,
which incidentally caught a cut-and-paste-bug in `nasty_list`, so fix that.

Differential Revision: https://reviews.llvm.org/D103318
2021-05-28 15:15:50 -04:00
Louis Dionne
9968896cd6 [libc++] NFC: Move unwrap_iter to its own header 2021-05-28 12:42:07 -04:00
Louis Dionne
58b29a4efc [libc++] Add all indirect callable concepts and projected
Differential Revision: https://reviews.llvm.org/D101277
2021-05-28 10:10:44 -04:00
Martin Storsjö
b3ceffdf35 [libcxx] [test] Convert an XFAIL LIBCXX-WINDOWS-FIXME into UNSUPPORTED with explanation
Differential Revision: https://reviews.llvm.org/D103149
2021-05-27 23:51:24 +03:00
Louis Dionne
aad878f112 [libc++] NFC: Make it easier for vendors to extend the run-buildbot script 2021-05-27 16:51:47 -04:00
Louis Dionne
8d7d7f340e [libc++] NFC: Refactor raw_storage_iterator test to use UNSUPPORTED markup
The test would previously disable itself using `#if TEST_STD_VER` instead
of using UNSUPPORTED markup.
2021-05-27 14:23:32 -04:00
Louis Dionne
b6399e85d8 Revert "[libc++] NFC: Parenthesize expression to satisfy GCC 11"
That fix was actually incorrect and caused tests to start failing.
2021-05-27 13:42:39 -04:00
Louis Dionne
73099e786a [libc++] NFC: Parenthesize expression to satisfy GCC 11
Otherwise it issues a -Werror=parentheses suggesting parentheses.
2021-05-27 11:41:29 -04:00
Louis Dionne
1055cb91b4 [libc++] Deprecate std::iterator and remove it as a base class
C++17 deprecated std::iterator and removed it as a base class for all
iterator adaptors. We implement that change, but we still provide a way
to inherit from std::iterator in the few cases where doing otherwise
would be an ABI break.

Supersedes D101729 and the std::iterator base parts of D103101 and D102657.

Differential Revision: https://reviews.llvm.org/D103171
2021-05-27 11:34:04 -04:00
Christopher Di Bella
0dc7fd1bc1 [libcxx][iterator] adds std::ranges::prev
Implements part of P0896 'The One Ranges Proposal'.
Implements [range.iter.op.prev].

Depends on D102563.

Differential Revision: https://reviews.llvm.org/D102564
2021-05-27 04:41:27 +00:00
Christopher Di Bella
857fa7b7b1 [libcxx][iterator] adds std::ranges::next
Implements part of P0896 'The One Ranges Proposal'.
Implements [range.iter.op.next].

Depends on D101922.

Differential Revision: https://reviews.llvm.org/D102563
2021-05-27 04:41:26 +00:00
zoecarver
52123c96c0 [libcxx][nfc] Fix the ASAN bots: update expected.pass.cpp.
Ensures that `get_return_object`'s return type is the same as the return type for the function calling `co_return`. Otherwise, we try to construct an object, then free it, then return it.

Differential Revision: https://reviews.llvm.org/D103196
2021-05-26 14:06:25 -07:00
zoecarver
367cb9fbd6 [libcxx][docs] Take mutex for common_iterator, common_view, and empty_view. 2021-05-26 13:29:16 -07:00
Louis Dionne
cc622aee30 [libc++] Add a job testing on GCC 11
I'm adding the job as a soft-fail for now, but once all the tests have
been fixed to work on it, we'll switch over from GCC 10 to GCC 11 and
remove the soft-fail.

Differential Revision: https://reviews.llvm.org/D103116
2021-05-26 15:48:33 -04:00
Mark de Wever
963495f0d4 [libc++][format] Adds availability macros for std::format.
This prevents std::format to be available until there's an ABI stable
version. (This only impacts the Apple platform.)

Depends on D102703

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D102705
2021-05-26 17:54:33 +02:00
Mark de Wever
de9df3f5b9 [libc++][NFC] Move basic_format_parse_context to its own header.
This is a preparation to split the format header in smaller parts for the
upcoming patches.

Depends on D101723

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D102703
2021-05-26 17:50:09 +02:00