Commit Graph

2454 Commits

Author SHA1 Message Date
Marshall Clow 5bcca9ffd1 Mark vector::operator[] and front/back as noexcept. We already do this for string and string_view. This should give better codegen inside of noexcept functions. Add tests for op[]/front/back/at, because apparently we had none.
llvm-svn: 356224
2019-03-15 00:29:35 +00:00
Marshall Clow 5f6a5ac19c Add noexcept to operator[] for array and deque. This is an extension. We already do this for string and string_view. This should give better codegen inside of noexcept functions.
llvm-svn: 356209
2019-03-14 21:56:57 +00:00
Marshall Clow 330ab33f7c Add std::midpoint for integral and poiner types. Described in P0811, reviewed as D59099.
llvm-svn: 356162
2019-03-14 16:25:55 +00:00
Eric Fiselier dfce2dd21e Properly constrain basic_string(Iter, Iter, Alloc = A())
llvm-svn: 356140
2019-03-14 12:31:10 +00:00
Louis Dionne a470a13a70 [libc++] Enable deprecation warnings by default
Summary:
In r342843, I added deprecation warnings to some facilities that were
deprectated in C++14 and C++17. However, those deprecation warnings
were not enabled by default.

After discussing this on IRC, we had finally gotten consensus to enable
those warnings by default, and I'm getting around to doing that only
now.

Reviewers: mclow.lists, EricWF

Subscribers: christof, jkorous, dexonsmith, jdoerfert, libcxx-commits

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

llvm-svn: 355961
2019-03-12 20:10:06 +00:00
Eric Fiselier 86af6f5088 Allow optional to tolerate being used with a nested class.
When Clang tries to complete a type containing `std::optional` it
considers the `in_place_t` constructor with no arguments which checks
if the value type is default constructible. If the value type is a
nested class type, then this check occurs too early and poisons the
is_default_constructible trait.

This patch makes optional deduce `in_place_t` so we can prevent
this early SFINAE evaluation. Technically this could break people
doing weird things with the in_place_t tag, but that seems less
important than making the nested class case work.

llvm-svn: 355877
2019-03-11 22:55:21 +00:00
Louis Dionne 3836a49039 [libc++] Remove empty header xlocale/xlocale.h
Summary:
I can't think of a reason for shipping this empty header. If there is
a reason to do so, then hopefully this review can uncover it.

Reviewers: mclow.lists, EricWF

Subscribers: mgorny, christof, jkorous, dexonsmith, libcxx-commits

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

llvm-svn: 355829
2019-03-11 15:41:51 +00:00
Eric Fiselier 411210838d Work around dllimport bug with exclude_from_explicit_instantiation.
When dllimport is specified on a class, and
exclude_from_explicit_instatiation is specified on a member, clang-cl
will still expect a definition to be available externally. But this is
not correct.

Surprisingly one one symbol seems to be consistently affected by this
bug. So this patch simply works around it there.

llvm-svn: 355760
2019-03-08 23:59:29 +00:00
Eric Fiselier 3e3d6c9038 Fix C++03 build failure
llvm-svn: 355758
2019-03-08 23:30:26 +00:00
Eric Fiselier 0e1586c4fb Unbork `std::memory_order` ABI.
Summary:
We need to pin the underlying type of C++20' `std::memory_order` to match the C++17 version. Anything less is an ABI break.

At the moment it's `unsigned` before C++20 and `int` after. Or if you're using `-fshort-enums` it's `unsigned char` before C++20 and `int` after.

This patch explicitly specifies the underlying type of the  C++20 `memory_order` to be w/e type the compiler would have chosen for the C++17 version.

Reviewers: mclow.lists, ldionne

Reviewed By: ldionne

Subscribers: jfb, jdoerfert, #libc, zoecarver

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

llvm-svn: 355755
2019-03-08 23:15:54 +00:00
Eric Fiselier 6e4ec6022f Fix PR41017 - Build failure with _LIBCPP_DEBUG=0 and non-const-ref
comparator for std::sort()

Our debug comparator assumed that the comparator it wraps would always
accepts the values by const ref. This isn't required by the standard.

This patch makes our __debug_less comparator forward the constness.

llvm-svn: 355752
2019-03-08 22:58:59 +00:00
Thomas Anderson 516d07de07 [libc++] Fix use-after-free when building with _LIBCPP_DEBUG=1
The issue is the following code:

    __cn1->__add(*__ip);
    (*__ip)->__c_ = __cn1;

`__ip` points into the array of iterators for container `__cn2`.  This code adds
the iterator to the array of iterators for `__cn1`, and updates the iterator to
point to the new container.

This code works fine, except when `__cn1` and `__cn2` are the same container.
`__cn1->__add()` might need to grow the array of iterators, and when it does,
`__ip` becomes invalid, so the second line becomes a use-after-free error.

Simply swapping the order of the above two lines is not sufficient, because of
the memmove() below.  The easiest and most performant solution is just to skip
touching any iterators if the containers are the same.

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

llvm-svn: 355550
2019-03-06 21:10:08 +00:00
Eric Fiselier 2710d8e105 Fix ABI compatibility of `<stdexcept>` with VCRuntime.
Summary:
Currently, libc++'s `<stdexcept>` doesn't play nice with `vcruntime`. Specifically:

* `logic_error` and `runtime_error` have a different layout.
* libc++'s `logic_error` and `runtime_error` override `what()` but `vcruntime` does not.
*  `vcruntime` uses weak vtables for `<stdexcept>` types.
* libc++'s `<stdexcept>` constructors and assignment operators may have different manglings than `vcruntimes`.

This patch makes libc++'s declarations in `<stdexcept>` match those provided by MSVC's STL as closely as possible.
If MSVC doesn't declare a special member, then neither do we. This ensures that the implicit definitions have the same linkage, visibility, triviality, and noexcept-ness.







Reviewers: thomasanderson, ldionne, smeenai

Reviewed By: thomasanderson

Subscribers: jdoerfert, libcxx-commits

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

llvm-svn: 355546
2019-03-06 20:31:57 +00:00
Louis Dionne 930007ba76 [libc++] Do not specify the underlying type of memory_order
Summary:
This breaks ABI for folks using -fshort-enums, and does not really buy
us anything.

http://llvm.org/PR40977

Reviewers: mclow.lists, EricWF

Subscribers: christof, jkorous, dexonsmith, libcxx-commits, zoecarver

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

llvm-svn: 355521
2019-03-06 17:07:24 +00:00
Marshall Clow 8eda3ad29d Eradicate all the ptrdiff_ts in span left over from applying P1227. A couple of other minor cleanups. NFC
llvm-svn: 355481
2019-03-06 03:59:44 +00:00
Davide Italiano 6de760ac4e Reinstate libc++ patches now that the lldb formatter has been updated.
"[libc++] Fix <atomic> failures on GCC"
"[libc++] Change memory_order to an enum class"
"[libc++] decoupling Freestanding atomic<T> from libatomic.a"

llvm-svn: 355427
2019-03-05 18:40:49 +00:00
Davide Italiano 1061cb6a93 [libcxx] Revert set of atomic patches that broke lldb.
Revert "[libc++] Fix <atomic> failures on GCC"
Revert "[libc++] Change memory_order to an enum class"
Revert "[libc++] decoupling Freestanding atomic<T> from libatomic.a"

The lldb formatter nededs to be updated. Shafik and Louis will
coordinate to do so.

llvm-svn: 355417
2019-03-05 17:38:33 +00:00
Louis Dionne 130322e7cc [libc++] Fix <atomic> failures on GCC
Summary:
In https://reviews.llvm.org/D58201, we turned memory_order into an enum
class in C++20 mode. However, we were not casting memory_order to its
underlying type correctly for the GCC implementation, which broke the
build bots. I also fixed a test that was failing in C++17 mode on GCC 5.

Reviewers: EricWF, jfb, mclow.lists

Subscribers: zoecarver

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

llvm-svn: 355409
2019-03-05 15:49:58 +00:00
Louis Dionne b55803283b [libc++] Change memory_order to an enum class
This implements P0439R0.

Thanks to Zoe Carver for the patch.
Differential Revision: https://reviews.llvm.org/D58201

llvm-svn: 355403
2019-03-05 14:50:25 +00:00
Eric Fiselier 1c014d75b4 Fix -fsanitize=vptr badness in <__debug>
Summary:

This patch fixes a lifetime bug when inserting a new container into the debug database. It is
diagnosed by UBSAN when debug mode is enabled. This patch corrects how nodes are constructed
during insertion.

The fix requires unconditionally breaking the debug mode ABI. Users should not expect ABI
stability from debug mode.

Reviewers: ldionne, serge-sans-paille, EricWF

Reviewed By: EricWF

Subscribers: mclow.lists, christof, libcxx-commits

Tags: #libc

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

llvm-svn: 355367
2019-03-05 02:10:31 +00:00
Eric Fiselier e69290dc7f Make VCRuntime ABI configuration a first-class option.
Summary:
On Windows we currently provide two separate ABI configurations. One which defers to `vcruntime` to provide the C++ runtime and another which doesn't.
Using `vcruntime` allows interoperability which programs compiled against the MSVC STL, and should be preferred whenever possible.

When deferring to `vcruntime` much of the ABI we provide changes. Including the layout of `<stdexcept>` types, their vtables, and how the linkage of their members.

This patch introduces the `_LIBCPP_ABI_VCRUNTIME` macro to denote this configuration. It also cleans up the existing configuration for using `vcruntime`.

This cleanup lays the groundwork for fixing a number of ABI and interoperability bugs in  `<stdexcept>`.


Reviewers: thomasanderson, ldionne, smeenai

Reviewed By: smeenai

Subscribers: jdoerfert, libcxx-commits, #libc

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

llvm-svn: 355366
2019-03-05 01:57:01 +00:00
Louis Dionne 21450545d1 [libc++] decoupling Freestanding atomic<T> from libatomic.a
This patch introduces non-lockfree atomics that do not require using
an external libatomic. This work is done with the long-term goal of
allowing the use of <atomic> in freestanding environments.

Thanks to Olivier Giroux for the patch.
Differential Revision: https://reviews.llvm.org/D56913

llvm-svn: 355318
2019-03-04 15:26:27 +00:00
Louis Dionne ab19068b7f [libc++] Add is_nothrow_convertible from P0758R1
Reviewed as https://reviews.llvm.org/D58019.
Thanks to Zoe Carver for the patch.

llvm-svn: 355010
2019-02-27 17:57:38 +00:00
Louis Dionne 1be935f418 [libc++] Remove visibility-related warnings with Clang 8
The attributes were placed incorrectly -- they need to be after the
"struct" keyword, not before.

llvm-svn: 355006
2019-02-27 17:33:25 +00:00
Marshall Clow 5c814099c7 I changed a 'enable_if<...>::type to' 'enable_if_t<...>' but forgot to remove the preceding 'typename'
llvm-svn: 354995
2019-02-27 16:09:35 +00:00
Marshall Clow 02e1651c1f Implment the last part of P1024: tuple-like interface to span. Reviewed as https://reviews.llvm.org/D58706.
llvm-svn: 354988
2019-02-27 15:41:37 +00:00
Marshall Clow 2ffa170515 In the review of D58642, Louis asked: 'Is there a reason for making this inline? Templates are already inline by default'. I told him that I didn't want to change the one call (ssize) that I was adding, but would come back later and clean them all (data/empty/begin/end/cbegin/cend/rbegin/rend/crbegin/crend/size/ssize) up later. Now it is later. Remove the unnecessary 'inline' modifiers from all these calls.
llvm-svn: 354952
2019-02-27 03:25:43 +00:00
Marshall Clow 7d3986ea30 Implement the second part of P1227R2 - Signed ssize() functions. Reviewed as https://reviews.llvm.org/D58642
llvm-svn: 354950
2019-02-27 02:58:56 +00:00
Marshall Clow 7ad06a9319 First part of P1227R2 - change span over to use 'size_t' instead of 'ptrdiff_t'. Reviewed as https://reviews.llvm.org/D58639.
llvm-svn: 354936
2019-02-27 00:32:16 +00:00
Marshall Clow 46c719ddcd Implement P1357: Traits for [Un]bounded Arrays; adopted in Kona
llvm-svn: 354891
2019-02-26 16:07:03 +00:00
Louis Dionne 5d79eaa82f [libc++] Rename _NOALIAS macro to _LIBCPP_NOALIAS
Summary:
For consistency, libc++ macros always start with _LIBCPP. This should
have no functionality change.

Reviewers: EricWF, mclow.lists

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

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

llvm-svn: 354848
2019-02-26 06:34:42 +00:00
Marshall Clow 310b75e519 LWG3101 - span's Container constructors need another constraint. Reviewed as https://reviews.llvm.org/D57058.
llvm-svn: 354805
2019-02-25 18:32:57 +00:00
Marshall Clow 4fd0395477 Commit LWG3144 - span does not have a const_pointer typedef. Reviewed as D57039.
llvm-svn: 354802
2019-02-25 17:58:03 +00:00
Marshall Clow 9ab85a69dc First part of P1024: Usability Enhancements for std::span. Remove operator() for indexing, and add 'front' and 'back' calls.
llvm-svn: 354801
2019-02-25 17:54:08 +00:00
Dimitry Andric d95da99b91 Fix the build with gcc when `-Wredundant-decls` is passed
Summary:
gcc warns that `__throw_runtime_error` is declared both in `<__locale>`
and `<stdexcept>`, if `-Wredundant-decls` is passed on the command
line; this is the case with FreeBSD when ${WARNS} == 6.

Since `<__locale>` gets its first declaration via a transitive include
of `<stdexcept>`, and the second declaration is after the first
invocation of `__throw_runtime_error`, delete that second declaration.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>

Reviewers: kristina, MaskRay, EricWF, ldionne, ngie

Reviewed By: EricWF

Subscribers: krytarowski, brooks, emaste, dim, christof, jdoerfert, libcxx-commits

Tags: #libc

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

llvm-svn: 354515
2019-02-20 21:01:31 +00:00
Louis Dionne 7232a84e68 [libc++] Avoid UB in the no-exceptions mode in a few places
Summary:
A few places in the library seem to behave unexpectedly when the library
is compiled or used with exceptions disabled. For example, not throwing
an exception when a pointer is NULL can lead us to dereference the pointer
later on, which is UB. This patch fixes such occurences.

It's hard to tell whether there are other places where the no-exceptions
mode misbehaves like this, because the replacement for throwing an
exception does not always seem to be abort()ing, but at least this
patch will improve the situation somewhat.

See http://lists.llvm.org/pipermail/libcxx-dev/2019-January/000172.html

Reviewers: mclow.lists, EricWF

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

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

llvm-svn: 353850
2019-02-12 16:06:02 +00:00
Eric Fiselier 9ebc9dbd3c Don't declare fenv.h functions when they're a macro.
libc still provides function declarations, and these declarations
conflict with libc++'s

llvm-svn: 353774
2019-02-12 00:05:14 +00:00
Eric Fiselier cf39dd44b8 Add fenv.h header
Summary:
Some implementations of fenv.h use macros to define the functions they provide. This can cause problems when `std::fegetround()` is spelled in source.

This patch adds a `fenv.h` header to libc++ for the sole purpose of turning those macros into real functions.

Reviewers: rsmith, mclow.lists, ldionne

Reviewed By: rsmith

Subscribers: mgorny, christof, libcxx-commits

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

llvm-svn: 353767
2019-02-11 23:47:19 +00:00
Eric Fiselier e8adbae00a fix -Wextra-semi warnings
llvm-svn: 353650
2019-02-10 18:29:00 +00:00
Marshall Clow aa09911aef Add static_asserts to tuple's comparison operators to enforce the requirement that the tuples be the same size. See PR39183 for an example where we give unexpected results for this bad input case. With this change, we will reject it at compile-time
llvm-svn: 353450
2019-02-07 19:03:48 +00:00
Marshall Clow 954966c1af Add UBSAN annotation to __hash_table::rehash; we don't do anything wrong, but UBSAN's checker flags it as suspicious. See PR38606. NFC
llvm-svn: 353448
2019-02-07 18:53:58 +00:00
Marshall Clow c8879ab2fd Add a specialization for '__unwrap_iter' to handle const interators. This enables the 'memmove' optimization for std::copy, etc.
llvm-svn: 353311
2019-02-06 16:10:25 +00:00
Louis Dionne b3b8968117 [NFC][libc++] Reindent function
llvm-svn: 353180
2019-02-05 15:46:52 +00:00
Marshall Clow 2e719bc428 add a test and a couple minor bug fixes for the implicit-signed-integer-truncation sanitizer. This is PR#40566
llvm-svn: 352926
2019-02-01 21:59:27 +00:00
Louis Dionne 6b653fc70f [libc++] Disentangle the 3 implementations of type_info
Summary:
We currently have effectively 3 implementations of type_info: one for
the Microsoft ABI, one that does not assume that there's a unique copy
of each RTTI in a progran, and one that assumes a unique copy.

Those 3 implementations are entangled into the same class with nested
ifdefs, which makes it very difficult to understand. Furthermore, the
benefit of doing this is rather small since the code that is duplicated
across implementations is just a couple of trivial lines.

This patch stamps out the 3 versions of type_info explicitly to increase
readability. It also explains what's going on with short comments, because
it's far from obvious.

Reviewers: EricWF, mclow.lists

Subscribers: christof, jkorous, dexonsmith

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

llvm-svn: 352905
2019-02-01 20:00:13 +00:00
Thomas Anderson 13447450bc [libc++] Don't define operator new/delete when using vcruntime
Fixes build errors on Windows without libc++abi of the form:

    new(173,36):  error: redeclaration of 'operator delete' cannot add 'dllexport' attribute
    _LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p) _NOEXCEPT;
    vcruntime_new.h(87,16):  note: previous declaration is here
    void __CRTDECL operator delete(
    new(205,70):  error: redefinition of 'operator new'
    _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new  (std::size_t, void* __p) _NOEXCEPT {return __p;}
    vcruntime_new.h(184,28):  note: previous definition is here
        inline void* __CRTDECL operator new(size_t _Size, _Writable_bytes_(_Size) void* _Where) noexcept
    new(206,70):  error: redefinition of 'operator new[]'
    _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
    vcruntime_new.h(199,28):  note: previous definition is here
        inline void* __CRTDECL operator new[](size_t _Size,
    new(207,40):  error: redefinition of 'operator delete'
    inline _LIBCPP_INLINE_VISIBILITY void  operator delete  (void*, void*) _NOEXCEPT {}
    vcruntime_new.h(190,27):  note: previous definition is here
        inline void __CRTDECL operator delete(void*, void*) noexcept
    new(208,40):  error: redefinition of 'operator delete[]'
    inline _LIBCPP_INLINE_VISIBILITY void  operator delete[](void*, void*) _NOEXCEPT {}
    vcruntime_new.h(206,27):  note: previous definition is here
        inline void __CRTDECL operator delete[](void*, void*) noexcept

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

llvm-svn: 352647
2019-01-30 19:08:32 +00:00
Thomas Anderson 7f50dfa6fc [libc++] Fix Windows build error in <functional>
On my Windows system, __allocator is defined to nothing.  This change fixes build errors of the below form:

    In file included from algorithm:644:
    functional(1492,31):  error: expected member name or ';' after declaration specifiers
        const _Alloc& __allocator() const { return __f_.second(); }

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

llvm-svn: 352561
2019-01-29 23:19:45 +00:00
Thomas Anderson db9152c248 [libc++] Fix Windows build error in include/filesystem
_LIBCPP_FUNC_VIS is redundant since the class is already annotated with
_LIBCPP_EXCEPTION_ABI.

Fixes this build error:

    In file included from fstream:188:
    filesystem(1350,3):  error: attribute 'dllimport' cannot be applied to member of 'dllimport' class
      _LIBCPP_FUNC_VIS
    __config(674,37):  note: expanded from macro '_LIBCPP_FUNC_VIS'
    #define _LIBCPP_FUNC_VIS            _LIBCPP_DLL_VIS
    __config(666,38):  note: expanded from macro '_LIBCPP_DLL_VIS'
    #  define _LIBCPP_DLL_VIS __declspec(dllimport)
    filesystem(1313,7):  note: previous attribute is here
    class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
    __config(675,37):  note: expanded from macro '_LIBCPP_EXCEPTION_ABI'
    #define _LIBCPP_EXCEPTION_ABI       _LIBCPP_DLL_VIS
    __config(666,38):  note: expanded from macro '_LIBCPP_DLL_VIS'
    #  define _LIBCPP_DLL_VIS __declspec(dllimport)

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

llvm-svn: 352525
2019-01-29 18:48:35 +00:00
Eric Fiselier 011943a6e8 Fix PR40495 - is_invokable_v<void> does not compile
The meta-programming that attempted to form the invoke call expression
was not in a SFINAE context. This made it a hard error to provide
non-referencable types like 'void' or 'void (...) const'.

This patch fixes the error by checking the validity of the call
expression within a SFINAE context.

llvm-svn: 352522
2019-01-29 18:01:14 +00:00
Marshall Clow 5a8525e0b6 D14686: 'Protect against overloaded comma in random_shuffle and improve tests' I had to cut back on the tests with this, because they were not C++03 friendly. Thanks to gribozavr for the patch
llvm-svn: 352087
2019-01-24 19:20:19 +00:00