Commit Graph

5974 Commits

Author SHA1 Message Date
Sergej Jaskiewicz 41f4dfd63e [libcxx] Force-cache LIBCXX_CXX_ABI_LIBRARY_PATH
Summary:
The `LIBCXX_CXX_ABI_LIBRARY_PATH` CMake variable is cached once in
libcxx/cmake/Modules/HandleLibCXXABI.cmake in the `setup_abi_lib` macro,
and then cached again in libcxx/test/CMakeLists.txt. There, if it is
not set to a value, it is by default set to `LIBCXX_LIBRARY_DIR`.

However, this new value is not actually cached, because the old (empty)
value has been already cached. Use the `FORCE` CMake flag so that it
is saved to the cache.

This should not break anything, because the code changed here previously
had no effect, when it should have.

Reviewers: jroelofs, bcraig, ldionne, EricWF, mclow.lists, vvereschaka, eastig

Reviewed By: vvereschaka

Subscribers: mgorny, christof, dexonsmith, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D69169
2020-01-10 12:56:43 +03:00
Eric Fiselier 61bd19206f [libc++] Explicitly enumerate std::string external instantiations.
The external instantiation of std::string is a problem for libc++.
    Additions and removals of inline functions in string can cause ABI
    breakages, including introducing new symbols.

    This patch aims to:
      (1) Make clear which functions are explicitly instatiated.
      (2) Prevent new functions from being accidentally instantiated.
      (3) Allow a migration path for adding or removing functions from the
      explicit instantiation over time.

    Although this new formulation is uglier, it is preferable from a
    maintainability and readability standpoint because it explicitly
    enumerates the functions we've chosen to expose in our ABI. Changing
    this list is non-trivial and requires thought and planning.

    (3) is achieved by making it possible to control the extern template declaration
    separately from it's definition. Meaning we could add a new definition to
    the dylib, wait for it to roll out, then add the extern template
    declaration to the header. Similarly, we could remove existing extern
    template declarations while still keeping the definition to prevent ABI
    breakages.
2020-01-09 15:51:02 -05:00
Billy Robert O'Neal III 85ee4ff4e4 [libcxx] [test] Disable refwrap/weak_result.pass.cpp in C++20 mode (broken by P0357R3) 2020-01-08 16:46:55 -08:00
Stephan T. Lavavej a1857e2ce3 [libcxx][test] Fix span tests.
span.cons/container.pass.cpp
N4842 22.7.3.2 [span.cons]/13 constrains span's range constructor
for ranges::contiguous_range (among other criteria).

24.4.5 [range.refinements]/2 says that contiguous_range requires data(),
and (via contiguous_range, random_access_range, bidirectional_range,
forward_range, input_range, range) it also requires begin() and end()
(see 24.4.2 [range.range]/1).

Therefore, IsAContainer needs to provide begin() and end().

(Detected by MSVC's concept-constrained implementation.)

span.cons/stdarray.pass.cpp
This test uses std::array, so it must include <array>.
<span> isn't guaranteed to drag in <array>.

(Detected by MSVC's implementation which uses a forward declaration to
avoid dragging in <array>, for increased compiler throughput.)

span.objectrep/as_bytes.pass.cpp
span.objectrep/as_writable_bytes.pass.cpp
Testing `sp.extent == std::dynamic_extent` triggers MSVC warning
C4127 "conditional expression is constant". Using `if constexpr` is a
simple way to avoid this without disrupting anyone else (as span
requires C++20 mode).

span.tuple/get.pass.cpp
22.7.3.2 [span.cons]/4.3: "Preconditions: If extent is not equal to
dynamic_extent, then count is equal to extent."

These lines were triggering undefined behavior (detected by assertions
in MSVC's implementation).

I changed the count arguments in the first two chunks, followed by
changing the span extents, in order to preserve the test's coverage
and follow the existing pattern.

span.cons/span.pass.cpp
22.7.3.2 [span.cons]/18.1 constrains span's converting constructor with
"Extent == dynamic_extent || Extent == OtherExtent is true".

This means that converting from dynamic extent to static extent is
not allowed. (Other constructors tested elsewhere, like
span(It first, size_type count), can be used to write such code.)

As this is the test for the converting constructor, I have:

* Removed the "dynamic -> static" case from checkCV(), which is
comprehensive.

* Changed the initialization of std::span<T, 0> s1{}; in
testConstexprSpan() and testRuntimeSpan(), because s1 is used below.

* Removed ASSERT_NOEXCEPT(std::span<T, 0>{s0}); from those functions,
as they are otherwise comprehensive.

* Deleted testConversionSpan() entirely. Note that this could never
compile (it had a bool return type, but forgot to say `return`). And it
couldn't have provided useful coverage, as the /18.2 constraint
"OtherElementType(*)[] is convertible to ElementType(*)[]"
permits only cv-qualifications, which are already tested by checkCV().
2020-01-08 00:28:15 -08:00
Kazuaki Ishizaki 9de6a39872 [libcxx] fix incorrect attribute property
Summary:
`__has_attribute(fallthough)` -> `__has_attribute(fallthrough)`
This is a follow-up of https://reviews.llvm.org/D72287

Reviewers: EricWF, mclow.lists, Jim

Reviewed By: Jim

Subscribers: christof, ldionne, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D72314
2020-01-08 09:35:26 +08:00
Eric Fiselier 0c5102bd93 [libc++] Add additional benchmark functions to libcxx/benchmarks/string.bench
This change adds the following benchmarks:

- StringAssignStr
Assign a const basic::string& value

- StringAssignAsciiz
Assign a const char* asciiz value

StringAssignAsciizMix
Assign mixed long/short const char* asciiz values

- StringResizeDefaultInit
Resize default init benchmark

Patch by Martijn Vels (mvels@google.com)
Reviewed as D72343
2020-01-07 16:31:40 -05:00
Sergej Jaskiewicz e308a0ca15 [libcxx] Fix a typo in config.py
Reviewers: ldionne, jroelofs, EricWF

Subscribers: christof, dexonsmith, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D71890
2019-12-26 18:51:09 +03:00
Ruslan Baratov 6e8659c351 [libc++] Fix typo in std::midpoint
Reviewed By: mclow.lists

Differential Revision: https://reviews.llvm.org/D71525
2019-12-21 01:26:24 -08:00
Michał Górny e1882af9f6 [libc++] Update feature list for NetBSD
Add NetBSD to the same feature list as Fuchsia since it matches
in available features, effectively enabling aligned_alloc(),
timespec_get() and C11 features.  Remove now-duplicate declaration
of quick_exit() support.

Differential Revision: https://reviews.llvm.org/D71511
2019-12-20 17:50:47 +01:00
Mikhail Maltsev 67ce7f51a5 [libcxx] Fix include paths in fuzzing/partial_sort.pass.cpp
Summary:
When testing an installed (out-of-tree) version of libc++, the
"libcxx/fuzzing/partial_sort.pass.cpp" test fails because of missing
include files "../fuzzing/fuzzing.{h,cpp}". This happens because in
the source tree "../fuzzing" can be accessed as
"libcxx/include/../fuzzing", but with the installed library this does
not work.

This patch fixes the issue by changing the path to be relative from
the `libcxx/test/fuzzing" directory.

Reviewers: mclow.lists, EricWF, christof, michaelplatings

Reviewed By: michaelplatings

Subscribers: merge_guards_bot, ldionne, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D71459
2019-12-17 11:48:19 +00:00
Eric Fiselier a53534a9f6 [libc++] Add __default_init_tag to basic_string constructors
This removes unneeded zero initialization of string data.

For example, given the below code:

void Init(void *mem) {
    new (mem) std::string("Hello World");
}

Assembly before:

Init(void*):
        xorps   xmm0, xmm0
        movups  xmmword ptr [rdi], xmm0
        mov     qword ptr [rdi + 16], 0
        mov     byte ptr [rdi], 22
        movabs  rax, 8022916924116329800
        mov     qword ptr [rdi + 1], rax
        mov     dword ptr [rdi + 8], 1684828783
        mov     byte ptr [rdi + 12], 0
        ret

Assembly after:

Init():
        mov     byte ptr [rdi], 22
        movabs  rax, 8022916924116329800
        mov     qword ptr [rdi + 1], rax
        mov     dword ptr [rdi + 8], 1684828783
        mov     byte ptr [rdi + 12], 0
        ret

Patch by Martijn Vels (mvels@google.com)
Reviewed as https://reviews.llvm.org/D70621
2019-12-16 19:04:09 -05:00
Eric Fiselier 549545b64a [libc++] Rework compressed pair constructors.
This patch de-duplicates most compressed pair constructors
to use the same code in C++11 and C++03.

Part of doing that is deleting the "__second_tag()" and replacing
it with a "__value_init_tag()" which has the same effect, but
allows for the removal of the special "one-arg" first element
constructor.

This patch is intended to have no semantic change.
2019-12-16 18:38:58 -05:00
Eric Fiselier 0fa118a9da Add default initialization to compressed_pair.
This change introduces the __default_init_tag to memory, and a corresponding
element constructor to allow for default initialization of either of the pair
values. This is useful for classes such as std::string where most (all)
constructors explicitly initialize the values in the constructor.

Patch by Martijn Vels (mvels@google.com)
Reviewed as https://reviews.llvm.org/D70617
2019-12-16 17:14:02 -05:00
Stephan T. Lavavej 5688f16852 [libcxx] [test] Include missing headers. (NFC)
libcxx/test/std/containers/sequences/array/at.pass.cpp
Need to include <stdexcept> for std::out_of_range.

libcxx/test/std/localization/locale.categories/category.time/*
Need to include <ios> for std::ios.
2019-12-13 18:24:18 -08:00
Eric Fiselier fda3825c7a [libc++] Ensure __config always defines certain configuration macros. 2019-12-13 15:42:07 -05:00
Stephan T. Lavavej bf7dc572f1 [libcxx] [test] Fix valarray UB and MSVC warnings.
[libcxx] [test] Calling min and max on an empty valarray is UB.

libcxx/test/std/numerics/numarray/template.valarray/valarray.members/min.pass.cpp
libcxx/test/std/numerics/numarray/template.valarray/valarray.members/max.pass.cpp

The calls `v1.min();` and `v1.max();` were emitting nodiscard warnings
with MSVC's STL. Upon closer inspection, these calls were triggering
undefined behavior. N4842 [valarray.members] says:

"T min() const;
8 Preconditions: size() > 0 is true.
T max() const;
10 Preconditions: size() > 0 is true."

As these tests already provide coverage for non-empty valarrays
(immediately above), I've simply deleted the code for empty valarrays.

[libcxx] [test] Add macros to msvc_stdlib_force_include.h (NFC).

libcxx/test/support/msvc_stdlib_force_include.h

These macros are being used by:
libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp
Defining them to nothing allows that test to pass.

[libcxx] [test] Silence MSVC warning C5063 for is_constant_evaluated (NFC).

libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp

This test is intentionally writing code that MSVC intentionally warns
about, so the warning should be silenced.

Additionally, comment an endif for clarity.

[libcxx] [test] Silence MSVC warning C4127 (NFC).

libcxx/test/support/charconv_test_helpers.h

MSVC avoids emitting this warning when it sees a single constexpr value
being tested, but this condition is a mix of compile-time and run-time.
Using push-disable-pop is the least intrusive way to silence this.

[libcxx] [test] Silence MSVC truncation warning (NFC).

libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp

This test is intentionally truncating float to int, which MSVC
intentionally warns about, so push-disable-pop is necessary.

[libcxx] [test] Avoid truncation warnings in erase_if tests (NFC).

libcxx/test/std/containers/associative/map/map.erasure/erase_if.pass.cpp
libcxx/test/std/containers/associative/multimap/multimap.erasure/erase_if.pass.cpp
libcxx/test/std/containers/unord/unord.map/erase_if.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/erase_if.pass.cpp

These tests use maps with `short` keys and values, emitting MSVC
truncation warnings from `int`. Adding `static_cast` to `key_type`
and `mapped_type` avoids these warnings.

As these tests require C++20 mode (or newer), for brevity I've changed
the multimap tests to use emplace to initialize the test data.
This has no effect on the erase_if testing.
2019-12-12 18:35:27 -08:00
Eric Fiselier 9b540192b6 [libc++] Mark all fuzzing tests as unsupported in C++03 2019-12-12 21:12:27 -05:00
Eric Fiselier f97936fabd [libc++] Cleanup and enable multiple warnings.
Too many warnings are being disabled too quickly. Warnings are
important to keeping libc++ correct. This patch re-enables two
warnings: -Wconstant-evaluated and -Wdeprecated-copy.

In future, all warnings disabled for the test suite should require
an attached bug. The bug should state the plan for re-enabling that
warning, or a strong case why it should remain disabled.
2019-12-12 21:09:08 -05:00
Fangrui Song b7eb30d481 __bit_reference: fix -Wdeprecated-copy warnings
Since C++11, [depr.impldec]:

The implicit definition of a copy constructor as defaulted is deprecated
if the class has a user-declared copy assignment operator or a
user-declared destructor.

At clang HEAD, -Wdeprecated-copy (included by -Wextra) will warn on such instances.

Reviewed By: EricWF

Differential Revision: https://reviews.llvm.org/D71096
2019-12-12 16:31:36 -08:00
Eric Fiselier c6b8c3d5d9 [libc++] Tolerate NaN returning random distributions for now 2019-12-12 17:11:13 -05:00
Eric Fiselier 27ec4abeac [libc++] Add check to ensure oss-fuzz properly targets libc++. 2019-12-12 15:37:06 -05:00
Eric Christopher fa0fc04a4f Temporarily Revert "[libc++] Fix -Wdeprecated-copy warnings in __bit_reference"
as it's causing test failures due to mismatched visibility.

This reverts commit 02bb20223b.
2019-12-12 00:22:37 -08:00
Eric Christopher 02bb20223b [libc++] Fix -Wdeprecated-copy warnings in __bit_reference
Add a couple of default copy constructors to fix the warning.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D71395
2019-12-11 23:50:28 -08:00
Eric Fiselier 72b41e6e2d [libc++] Require C++14 in all cases.
LLVM has moved to C++14, and the libc++ build should too.
C++14 is needed to provide constant initialization for certain global
objects.

I suspect this change may break some older GCC buildbots, and I'll clean
those up as they fall.
2019-12-11 20:26:30 -05:00
Eric Fiselier 5c9816b84e [libc++] Fix fuzzing tests with older GCC compilers.
GCC 5 doesn't support `if constexpr`, so we need to do old-style tag
dispatching.
2019-12-11 16:36:54 -05:00
Eric Fiselier 29b2f64ddb [libc++] Fix fuzzing unit tests with exceptions disabled.
We simply turn off the parts of the tests that require exceptions.
2019-12-11 16:22:11 -05:00
Eric Fiselier daacf57032 [libc++] Add fuzzing tests for parts of <random>.
This patch also re-names the existing fuzzing unit tests so they
actually run.
2019-12-11 15:47:06 -05:00
Louis Dionne dd37e24ae6 [libc++] Hide some functions and types in <future> and <thread> as hidden
Otherwise, weak symbols leak into user programs when using `async` with
non-internal types.
2019-12-10 19:19:45 -05:00
Sergej Jaskiewicz 44c167ace9 [libcxx] Replace func_name with __name__ for compatibility with Python 3
Summary:
The __name__ attribute is the correct way to get a function name in
Python 3. This also works with Python 2.

Reviewers: jroelofs, EricWF

Subscribers: christof, ldionne, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D71136
2019-12-11 02:37:13 +03:00
Louis Dionne 8bd9d0bff2 [libcxx] [test] Query the target platform, not the host one
target_info is inferred to WindowsLocalTI on Windows hosts unless
specified otherwise. In the latter case, it doesn't make sense to use
Windows-specific settings if the target is not Windows.

This change should not break anything, because target_info is inferred
based on what platform.system() returns. self.is_windows was set based
on the same platform.system() call.

Thanks to Sergej Jaskiewicz for the patch.

Differential Revision: https://reviews.llvm.org/D68275
2019-12-10 16:36:07 -05:00
Petr Hosek 1aa1702381 [libcxx{,abi}] Don't link libpthread and libdl on Fuchsia
These are a part of the libc so linking these explicitly isn't necessary
and embedding these as deplibs causes link time error.

This issues was introduced in a9b5fff which changed how we emit deplibs.

Differential Revision: https://reviews.llvm.org/D71135
2019-12-06 11:15:15 -08:00
Michał Górny a9b5fff591 [libcxx{,abi}] Emit deplibs only when detected by CMake
This is a followup to 35bc5276ca.  It fixes the dependent libs usage
in libcxx and libcxxabi to link pthread and rt libraries only if CMake
detects them, rather than based on explicit platform blacklist.

Differential Revision: https://reviews.llvm.org/D70888
2019-12-02 22:19:20 +01:00
David Zarzycki 06e5ebf8db
[libcxx] Add -Wno-deprecated-copy to the test config 2019-11-29 09:57:51 +02:00
marshall 703c26f03b Optimize and fix basic_string move assignment operator. Reviewed as https://reviews.llvm.org/D68623. Thanks to mvels for the patch. 2019-11-27 07:13:32 -08:00
Shoaib Meenai d018b556c7 [libcxx] Omit unneeded locale fallbacks on Android 21+
Android API level 21 and above have all these functions available, so we
don't need to include our fallback definitions.

Differential Revision: https://reviews.llvm.org/D69983
2019-11-25 11:06:08 -08:00
Sergej Jaskiewicz 0313075793 [libcxx] Add Sergej Jaskiewicz to CREDITS.txt
Summary: Also, test commit access

Reviewers: EricWF

Subscribers: christof, ldionne, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D70526
2019-11-21 12:06:10 +03:00
Louis Dionne 9918312682 [libc++] Separate -include and path to the site config file
This apparently breaks weird use cases where the build directory is on
a separate drive. Someone reported that failure to me privately.

I can't remember of a reason for collating the two arguments in the
first place, so I don't think this should break anything.
2019-11-18 16:28:53 -05:00
Dan Albert 19fd9039ca Fix _LIBCPP_HAS_ definitions for Android.
Summary:
Android added quick_exit()/at_quick_exit() in API level 21,
aligned_alloc() in API level 28, and timespec_get() in API level 29,
but has the other C11 features at all API levels (since they're basically
just coming from clang directly).

_LIBCPP_HAS_QUICK_EXIT and _LIBCPP_HAS_TIMESPEC_GET already existed,
so we can reuse them. (And use _LIBCPP_HAS_TIMESPEC_GET in a few more
places where _LIBCPP_HAS_C11_FEATURES has been used as a proxy. This
isn't correct for Android.)

_LIBCPP_HAS_ALIGNED_ALLOC is added, to cover aligned_alloc() (obviously).

Add a missing std:: before aligned_alloc in a cstdlib test, and remove a
couple of !defined(_WIN32)s now that we're explicitly testing
TEST_HAS_ALIGNED_ALLOC rather than TEST_HAS_C11_FEATURES.

Reviewers: danalbert, EricWF, mclow.lists

Reviewed By: danalbert

Subscribers: srhines, christof, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D69929
2019-11-18 12:19:58 -08:00
Dan Albert 626260cfe3 Update the docs for building libc++.
Summary:
Rewrite the in-tree build to be a clearer tl;dr like we have for the
out-of-tree build.

Reviewers: EricWF, mclow.lists, ldionne

Reviewed By: ldionne

Subscribers: dexonsmith, christof, ldionne, enh, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D69917
2019-11-18 12:14:13 -08:00
Eric Fiselier f82dba0192 Rename __is_foo_iterator traits to reflect their Cpp17 nature.
With the upcoming introduction of iterator concepts in ranges,
the meaning of "__is_contiguous_iterator" changes drastically.

Currently we intend it to mean "does it have this iterator category",
but it could now also mean "does it meet the requirements of this
concept", and these can be different.
2019-11-18 01:49:32 -05:00
Eric Fiselier 6624fcba43 [libc++] Add _ITER_CONCEPT and _ITER_TRAITS implementations from C++20
These traits are currently unused because we don't implement ranges.
However, their addition is part of ongoing work to allow libc++
to optimize on user-provided contiguous iterators.
2019-11-16 20:26:35 -05:00
Eric Fiselier 45d048c204 [libc++] Add C++20 contiguous_iterator_tag.
This work is part of an ongoing effort to allow libc++ to
optimize user provided contiguous iterators.
2019-11-16 20:14:44 -05:00
Eric Fiselier 0068c59139 [libc++] Rename __to_raw_pointer to __to_address.
This function has the same behavior as the now-standand std::to_address.
Re-using the name makes the behavior more clear, and in the future it
will allow us to correctly get the raw pointer for user provided pointer
types.
2019-11-16 17:16:09 -05:00
Marek Kurdej 8e34be2f25 [libc++] [chrono] Fix year_month_weekday::ok() implementation.
Reviewers: ldionne, EricWF, mclow.lists

Reviewed By: mclow.lists

Subscribers: christof, dexonsmith, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D70282
2019-11-15 18:48:45 +01:00
Ilya Tokar 767eadd782 [libcxx] use __builtin_isnan in std::isnan.
Summary: This allows std::isnan to be fully inlined, instead of generating calls.

Reviewers: EricWF

Reviewed By: EricWF

Subscribers: christof, ldionne

Differential Revision: https://reviews.llvm.org/D69806
2019-11-15 12:29:18 -05:00
Marek Kurdej 76ac1660f7 [libc++] [P0920] [P1661] Update status page. 2019-11-15 00:12:34 +01:00
Louis Dionne 1466335cf4 [libc++][P1872] span should have size_type, not index_type.
Thanks to Marek Kurdej for the patch.

Differential Revision: https://reviews.llvm.org/D70206
2019-11-14 09:07:05 -05:00
Louis Dionne 8b77a3a0f4 [libc++] [P1612] Add missing feature-test macro __cpp_lib_endian.
Thanks to Marek Kurdej for the patch.

Differential Revision: https://reviews.llvm.org/D70221
2019-11-14 08:55:19 -05:00
Marek Kurdej d94f63758a libc++ status page: Fix HTML. 2019-11-13 22:51:29 +01:00
David Zarzycki 1d55c9e59e [libcxx testing] Fix -Wtautological-overlap-compare bug 2019-11-13 10:55:19 +02:00