Commit Graph

3120 Commits

Author SHA1 Message Date
Nico Weber cc89063bff libcxx: Rename .hpp files in libcxx/test/support to .h
LLVM uses .h as its extension for header files.

Files renamed using:

    for f in libcxx/test/support/*.hpp; do git mv $f ${f%.hpp}.h; done

References to the files updated using:

    for f in $(git diff master | grep 'rename from' | cut -f 3 -d ' '); do
        a=$(basename $f);
        echo $a;
        rg -l $a libcxx | xargs sed -i '' "s/$a/${a%.hpp}.h/";
    done

HPP include guards updated manually using:

    for f in $(git diff master | grep 'rename from' | cut -f 3 -d ' '); do
      echo ${f%.hpp}.h ;
    done | xargs mvim

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

llvm-svn: 369481
2019-08-21 00:14:12 +00:00
Marshall Clow 7fa6865392 Fix a couple of unguarded operator, calls in algorithm. Fixes PR#43063. Updated all the heap tests to check this.
llvm-svn: 369448
2019-08-20 21:31:51 +00:00
Zoe Carver 80ddfcb5b8 [libc++] Fix std::abs tests
On systems where sizeof(long) == sizeof(int)
the current tests failed. This commit updates
those tests to work on all systems.
std::abs has specific long specializations
which can be used instead.

llvm-svn: 369437
2019-08-20 20:44:59 +00:00
Louis Dionne c310e5a7ab [libc++] Avoid implicit conversion warning in a <random> test
By stashing the computation of `E::max() - E::min()` in a variable, we
avoid the warning introduced in r367497. Note that we use `auto` to
avoid having to deduce the type of the computation, which is not a
problem since Clang provides `auto` as an extension even in C++03 (and
we disable warnings related to using C++11 extensions in the test suite).

llvm-svn: 369429
2019-08-20 19:28:26 +00:00
Louis Dionne fc4486c247 [libc++] Implement LWG 3199
Summary:
The resolution of LWG 3199 makes sure that input-streaming into an empty bitset
does not set the failbit on the input stream.

Reviewers: mclow.lists, EricWF

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

Tags: #libc

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

llvm-svn: 369422
2019-08-20 18:21:06 +00:00
Louis Dionne 958987bfdd [libc++] Precise XFAIL for AppleClang 11
This test doesn't fail on all patch levels of AppleClang 11

llvm-svn: 369420
2019-08-20 18:05:06 +00:00
Zoe Carver 86d560ff1b [libc++] fix test for unsigned char
On some systems char is unsigned.
If that is the case, we will now
test signed char twice in std::abs.
NFC. Fixes the build bots.

llvm-svn: 369413
2019-08-20 17:09:00 +00:00
Louis Dionne cb93f650b6 [libc++] Disable <chrono> ""d and ""y literal tests on AppleClang 10.0.0
In r368882, I enabled those tests for all AppleClang's above version 9.
However, it turns out that the feature is only supported starting with
AppleClang 10.0.1, not AppleClang 10.0.0. This commit fixes that hole.

llvm-svn: 369409
2019-08-20 16:45:27 +00:00
Zoe Carver 6585f018ad [libc++] std::abs should not return double
Implement LWG Issue 2735 by adding std::abs
tests for several types and checking their
return value. NFC.

llvm-svn: 369394
2019-08-20 15:43:25 +00:00
Louis Dionne 296757c07c [libc++] Add XFAIL for is_base_of test on AppleClang 11
llvm-svn: 369280
2019-08-19 17:29:42 +00:00
Louis Dionne 3f274d4a55 [libc++] Mark <chrono> test as unsupported on AppleClang 9
llvm-svn: 368914
2019-08-14 20:27:56 +00:00
Louis Dionne b4aebff4f1 [libc++] Mark std::tuple CTAD test as failing on AppleClang 9
Like CTAD for std::unordered_set, AppleClang 9's support for CTAD is
insufficient. I suspect the corresponding LLVM Clang is broken too,
but we don't seem to have testers using that Clang.

llvm-svn: 368911
2019-08-14 20:17:18 +00:00
Louis Dionne 619172a818 [libc++] Enable <chrono> ""d and ""y literals for AppleClang 10 and up
AppleClang supports those literals starting in version 10.0.1.

llvm-svn: 368882
2019-08-14 17:04:31 +00:00
Louis Dionne 10f0668b57 [libc++] Mark two <chrono> tests as unsupported on AppleClang 11
The operator""y and operator""d will eventually be supported by
AppleClang, but no released version supports them at the moment.

llvm-svn: 368749
2019-08-13 21:34:49 +00:00
Louis Dionne fa8cb90e6f [libc++] Fix incorrect UNSUPPORTED annotation
The test was marked as UNSUPPORTED for clang-6 and clang-6, instead of
clang-6 and clang-7.

llvm-svn: 368666
2019-08-13 11:25:16 +00:00
Louis Dionne 86dd28a547 [libc++] Use [[nodiscard]] for lock_guard, as an extension
Summary:
D64914 added support for applying [[nodiscard]] to constructors. This
commit uses that capability to flag incorrect uses of std::lock_guard
where one forgets to actually create a variable for the lock_guard.

rdar://45790820

Reviewers: mclow.lists, EricWF

Subscribers: christof, jkorous, dexonsmith, libcxx-commits, Quuxplusone, lebedev.ri

Tags: #libc

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

llvm-svn: 368664
2019-08-13 11:12:28 +00:00
Louis Dionne 1308011e1b [libc++] Implement CTAD for std::tuple
Summary:
We were using implicit deduction guides instead of explicit ones,
however the implicit ones don't do work anymore when changing the
constructors.

This commit adds the actual guides specified in the Standard to make
libc++ (1) closer to the Standard and (2) more resistent to changes
in std::tuple's constructors.

Reviewers: Quuxplusone

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

Tags: #libc

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

llvm-svn: 368599
2019-08-12 18:30:31 +00:00
Marshall Clow fde236b1f7 Implement hh_mm_ss from P1466R3. Reviewed as https://reviews.llvm.org/D65365.
llvm-svn: 368299
2019-08-08 14:36:07 +00:00
Louis Dionne bf4808439f [pstl] Add a __pstl_config_site header to record the CMake configuration
This commit adds a __pstl_config_site header that contains the value of
macros specified at CMake configuration time. It works similarly to
libc++'s __config_site header, except we always include it as a separate
file instead of concatenating it to the main configuration header.

It is necessary to thread the includes for that header into libc++'s
lit configuration, otherwise we'd be requiring an installation step
prior to running the test suite.

llvm-svn: 368284
2019-08-08 12:43:04 +00:00
Louis Dionne 0a06eb911b [libc++] Take 2: Integrate the PSTL into libc++
Summary:
This commit allows specifying LIBCXX_ENABLE_PARALLEL_ALGORITHMS when
configuring libc++ in CMake. When that option is enabled, libc++ will
assume that the PSTL can be found somewhere on the CMake module path,
and it will provide the C++17 parallel algorithms based on the PSTL
(that is assumed to be available).

The commit also adds support for running the PSTL tests as part of
the libc++ test suite.

The first attempt to commit this failed because it exposed a bug in the
tests for modules. Now that this has been fixed, it should be safe to
commit this.

Reviewers: EricWF

Subscribers: mgorny, christof, jkorous, dexonsmith, libcxx-commits, mclow.lists, EricWF

Tags: #libc

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

llvm-svn: 367903
2019-08-05 18:29:14 +00:00
Eric Fiselier 278d593014 Revert "Suppress -Wctad-maybe-unsupported on types w/o deduction guides."
Some modules builds are issuing buggy diagnostics. The cause of which is
TBD.

This reverts commit r@367770.

llvm-svn: 367777
2019-08-04 07:13:43 +00:00
Eric Fiselier fcd549a7d8 Suppress -Wctad-maybe-unsupported on types w/o deduction guides.
There are a handful of standard library types that are intended
to support CTAD but don't need any explicit deduction guides to
do so.

This patch adds a dummy deduction guide to those types to suppress
-Wctad-maybe-unsupported (which gets emitted in user code).

llvm-svn: 367770
2019-08-03 23:54:29 +00:00
Eric Fiselier d544d1441d Refactor deque to centralize handling of spare blocks.
I have upcoming changes that modify how deque handles spare blocks.
This cleanup is intended to make those changes easier to review
and understand. This patch should have NFC.

llvm-svn: 367631
2019-08-01 23:11:18 +00:00
Eric Fiselier 8f2124b47a Teach malloc_allocator how to count bytes
llvm-svn: 367606
2019-08-01 19:52:46 +00:00
Eric Fiselier 3eb5aec61f Change default bucket count in hash_set/hash_map.
Previously these types rehashed to a table of 193 elements
upon construction. But this is non-ideal, first because default
constructors should not allocate unless necessary, and second
because 193 is big and can waste a bunch of memory.

This number had previously been chosen to match GCC's implementation.

llvm-svn: 367605
2019-08-01 19:48:29 +00:00
Nico Weber 9aae539d4c libcxx: Define __STDCPP_THREADS__ to 1, not to __cplusplus.
[cpp.predefined]p2:

   __STDCPP_THREADS__
    Defined, and has the value integer literal 1, if and only if a program
    can have more than one thread of execution .

Also define it only if it's not defined already, since it's supposed
to be defined by the compiler.

Also move it from thread to __config (which requires setting it only
if _LIBCPP_HAS_NO_THREADS is not defined).

Part of PR33230. The intent is to eventually make the compiler define
this instead.

llvm-svn: 367316
2019-07-30 14:32:47 +00:00
Eric Fiselier b49d45925c Fix tests with modules enabled
llvm-svn: 367268
2019-07-29 22:48:51 +00:00
Marshall Clow 736e8aa8ed Fix a bug in std::chrono::abs where it would fail when the duration's period had not been reduced.s
llvm-svn: 367120
2019-07-26 15:10:46 +00:00
Marshall Clow db99d3a2a2 Implement change #4 of P1466: Change weekday to accept both 0 and 7 as Sunday. Add accessors 'c_encoding' and 'iso_encoding' to provide different interpretations of the weekday. Remove 'operator unsigned'
llvm-svn: 366981
2019-07-25 03:26:05 +00:00
Marshall Clow 30f12a4247 Implement most of P1612R1: Relocate endian. Moves the std::endian functionality from 'type-traits' to 'bit'. No other change. The reason that this is 'partial' is that P1621 also recommends a feature-test macro, but I don't have the value for that one yet. In a month or so, I'll add that
llvm-svn: 366776
2019-07-23 04:20:19 +00:00
Petr Hosek 89385633ba [libc++] Set __file_ to 0 in basic_filebuf::close() even if fclose fails
This issue was detected by ASan in one of our tests. This test manually
invokes basic_filebuf::cloe(). fclose(__h.release() returned a non-zero
exit status, so __file_ wasn't set to 0. Later when basic_filebuf
destructor ran, we would enter the if (__file_) block again leading to
heap-use-after-free error.

The POSIX specification for fclose says that independently of the return
value, fclose closes the underlying file descriptor and any further
access (including another call to fclose()) to the stream results in
undefined behavior. This is exactly what happened in our test case.

To avoid this issue, we have to always set __file_ to 0 independently of
the fclose return value.

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

llvm-svn: 366730
2019-07-22 19:54:34 +00:00
Louis Dionne 4e8c8aa959 [libc++] Mark libcpp_deallocate.sh.cpp as UNSUPPORTED instead of XFAIL on AppleClang 9
Some minor versions of AppleClang 9 appear not to fail the test. It's
such a mess that the only sane thing to do is to mark the test as
UNSUPPORTED.

llvm-svn: 366606
2019-07-19 19:41:40 +00:00
Louis Dionne a3c83b7511 Revert "[libc++] Integrate the PSTL into libc++"
This reverts r366593, which caused unforeseen breakage on the build bots.
I'm reverting until the problems have been figured out and fixed.

llvm-svn: 366603
2019-07-19 18:52:46 +00:00
Louis Dionne 910323e667 [libc++] Integrate the PSTL into libc++
Summary:
This commit allows specifying LIBCXX_ENABLE_PARALLEL_ALGORITHMS when
configuring libc++ in CMake. When that option is enabled, libc++ will
assume that the PSTL can be found somewhere on the CMake module path,
and it will provide the C++17 parallel algorithms based on the PSTL
(that is assumed to be available).

The commit also adds support for running the PSTL tests as part of
the libc++ test suite.

Reviewers: rodgert, EricWF

Subscribers: mgorny, christof, jkorous, dexonsmith, libcxx-commits, mclow.lists, EricWF

Tags: #libc

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

llvm-svn: 366593
2019-07-19 17:02:42 +00:00
Louis Dionne 9e6a42a185 [libc++] Add missing %link_flags to .sh.cpp test
Without the link flags, the test always fails on Linux. For some reason,
however, it works on Darwin -- which is why it wasn't caught at first.

llvm-svn: 366579
2019-07-19 14:01:48 +00:00
Louis Dionne e068c7463f [libc++] Fix link error with _LIBCPP_HIDE_FROM_ABI_PER_TU and std::string
Summary:
This is effectively a revert of r344616, which was a partial fix for
PR38964 (compilation of <string> with GCC in C++03 mode). However, that
configuration is explicitly not supported anymore and that partial fix
breaks compilation with Clang when per-TU insulation is provided.

PR42676
rdar://52899715

Reviewers: mclow.lists, EricWF

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

Tags: #libc

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

llvm-svn: 366567
2019-07-19 11:52:55 +00:00
Louis Dionne e1eabcdfad [libc++] Add C++17 deduction guides for std::function
Summary: http://llvm.org/PR39606

Reviewers: Quuxplusone

Subscribers: christof, dexonsmith, libcxx-commits

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

llvm-svn: 366484
2019-07-18 19:50:56 +00:00
Louis Dionne 66412df94f [libc++] XFAIL a test that does not behave properly on older Clang
rdar://53015486

llvm-svn: 366359
2019-07-17 18:54:29 +00:00
Louis Dionne e559f62506 [libcxx] Rejigger test for destroying delete feature-test macros
In r361572, we introduced library support for C++20 destroying delete
and decided to only define the library feature-test macro when the
compiler supports the underlying language feature. This patch reworks
the tests to mirror that.

llvm-svn: 366263
2019-07-16 21:13:40 +00:00
Louis Dionne 12154ee8f1 [libc++] Add missing UNSUPPORTED for CTAD tests
The tests for unordered_set and unordered_multiset were missing UNSUPPORTED
markup for Apple Clang 9.1, which is still being used on some CI bots.

llvm-svn: 366259
2019-07-16 20:41:33 +00:00
Zoe Carver a17b1aed6a Add contains method to associative containers. This patch implements P0458R2, adding contains to map, multimap, unordered_map, unordered_multimap, set, multiset, unordered_set, and unordered_multiset.
llvm-svn: 366170
2019-07-16 03:21:01 +00:00
Louis Dionne dfcd4384cb [libc++] Implement P0433: deduction guides for <unordered_map>
Thanks to Arthur O'Dwyer for the patch.

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

llvm-svn: 366124
2019-07-15 20:06:01 +00:00
Eric Fiselier 4066978cb7 Improve compile time of variant.
In particular, improve the compile time of the overload set builder
that variant uses to determine which alternative to construct.

Instead of having the __overload type construct itself recursively,
this patch uses a flat construction for the overload set.

llvm-svn: 366033
2019-07-14 21:29:39 +00:00
Eric Fiselier 3c0e2bb0cb Add test for variant construction with duplicate types.
llvm-svn: 366032
2019-07-14 20:59:51 +00:00
Eric Fiselier 273857d1ea Harden variant test added in r366022
The test was brittle since it only went boom for one specific type, when
really it should go boom for all of them.

llvm-svn: 366025
2019-07-14 18:30:34 +00:00
Eric Fiselier 194b337f33 Avoid eager template instantiation caused by the variant narrowing checks.
The standard disallows narrowing conversions when constructing a variant.
This is checked by attempting to perform braced initialization of the
destination type from the argument type. However, braced initialization
can force the compiler (mostly clang) to eagerly instantiate the
constructors of the destintation type -- which can lead to errors in
a non-immediate context.

However, as variant is currently specified, the narrowing checks only
observably apply when the destination type is arithmetic. Meaning we can
skip the check for class types. Hense avoiding the hard errors.

In order to cause fewer build breakages, this patch avoids the narrowing
check except when the destination type is arithmetic.

llvm-svn: 366022
2019-07-14 18:21:15 +00:00
Eric Fiselier 882fdf68b7 Fix non-conformance it `std::tuple`.
Previously we implemented all one trillion tuple-like constructors using
a single generic overload. This worked fairly well, except that it
differed in behavior from the standard version because it didn't
consider both T&& and T const&. This was observable for certain
types.

This patch addresses that issue by splitting the generic constructor
in two. We now provide both T&& and T const& versions of the
tuple-like constructors (sort of).

llvm-svn: 365973
2019-07-12 23:01:48 +00:00
Eric Fiselier 128af31595 Add option to disable variant narrowing conversion changes.
The paper P0608R3 - "A sane variant converting constructor" disallows
narrowing conversions in variant. It was meant to address this
surprising problem:

  std::variant<std::string, bool> v = "abc";
  assert(v.index() == 1); // constructs a bool.

However, it also disables every potentially narrowing conversion. For
example:

  variant<unsigned> v = 0; // ill-formed
  variant<string, double> v2 = 42; // ill-formed (int -> double narrows)

These latter changes break code. A lot of code. Within Google it broke
on the order of a hundred thousand target with thousands of root causes
responsible for the breakages.

Of the breakages related to the narrowing restrictions, none of them
exposed outstanding bugs. However, the breakages caused by boolean
conversions (~13 root causes), all but one of them were bugs.

For this reasons, I am adding a flag to disable the narrowing conversion
changes but not the boolean conversions one.

One purpose of this flag is to allow users to opt-out of breaking changes
in variant until the offending code can be cleaned up. For non-trivial
variant usages the amount of cleanup may be significant.

This flag is also required to support automated tooling, such as
clang-tidy, that can automatically fix code broken by this change.
In order for clang-tidy to know the correct alternative to construct,
it must know what alternative was being constructed previously, which
means running it over the old version of std::variant.

Because this change breaks so much code, I will be implementing the
aforementioned clang-tidy check in the very near future.

Additionally I'm plan present this new information to the committee so they can
re-consider if this is a breaking change we want to make.

I think libc++ should very seriously consider pulling this change
before the 9.0 release branch is cut. But that's a separate discussion
that I will start on the lists.

For now this is the minimal first step.

llvm-svn: 365960
2019-07-12 21:32:11 +00:00
Louis Dionne 189639b1c3 [libc++] Add XFAILs for CTAD tests on older compilers
llvm-svn: 365923
2019-07-12 17:30:57 +00:00
Eric Fiselier d49103bd2f Mark destroying delete test as UNSUPPORTED with clang 7
llvm-svn: 365856
2019-07-12 01:16:08 +00:00