Commit Graph

134 Commits

Author SHA1 Message Date
Eric Fiselier e4d9c316d2 Implement P0040r3: Extending memory management tools
llvm-svn: 276544
2016-07-24 03:51:39 +00:00
Marshall Clow dc3eb83d08 Always use the allocator to construct/destruct elements of a deque/vector. Fixes PR#28412. Thanks to Jonathan Wakely for the report.
llvm-svn: 275105
2016-07-11 21:38:08 +00:00
Eric Fiselier 68436a9b48 Implement P0163r0. Add shared_ptr::weak_type.
This patch adds the weak_type typedef in shared_ptr. It is available in
C++17 and newer.

This patch also updates the _LIBCPP_STD_VER and TEST_STD_VER macros to
have the value of 16, since 2016 is the current year.

llvm-svn: 273839
2016-06-27 01:02:43 +00:00
Eric Fiselier 39005d3019 Fix PR27115 - enable_shared_from_this does not work as a virtual base class.
See https://llvm.org/bugs/show_bug.cgi?id=27115

The problem was that the conversion from
'const enable_shared_from_this<T>*' to 'const T*' didn't work if
T inherited enable_shared_from_this as a virtual base class. The fix
is to take the original pointer passed to shared_ptr's constructor in the
__enable_weak_this method and perform an upcast to 'const T*' instead of
performing a downcast from the enable_shared_from_this base.

llvm-svn: 273835
2016-06-26 23:56:32 +00:00
Eric Fiselier df93bad1fe Enable building and using atomic shared_ptr for GCC.
Summary:
Currently the  implementation of [util.smartptr.shared.atomic] is provided only when using Clang, and not with GCC. This is a relic of not having a GCC implementation of <atomic>, even though <atomic> isn't actually used in the implementation. This patch enables support for atomic shared_ptr functions when using GCC.

Note that this is not a header only change. Previously only Clang builds of libc++.so would provide the required symbols. There is no reason  for this restriction.
After this change both Clang and GCC builds should be binary compatible with each other WRT these symbols.


Reviewers: mclow.lists, rmaprath, EricWF

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D21407

llvm-svn: 273076
2016-06-18 02:12:53 +00:00
Eric Fiselier 7cf29e3468 Fix leak in __enable_weak_this(). Thanks to Arthur O'Dwyer for finding it.
llvm-svn: 271487
2016-06-02 04:57:00 +00:00
Eric Fiselier 88f5bfdc5b Implement P0033R1 - Re-enabling shared_from_this
Summary: See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0033r1.html

Reviewers: mclow.lists

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19254

llvm-svn: 271449
2016-06-02 00:15:35 +00:00
Marshall Clow 3379baeb99 Change the control flow in atomic_compare_exchange_strong to avoid a potential deadlock.
When you assign a shared_ptr, the deleter gets called and assigned. In this routine, the assignment happens inside a critical section, which could (potentially) lead to a deadlock, if the deleter did something wonky. Now we swap the old value with an (empty) temporary shared_ptr, and then let the temporary delete the old value when it goes out of scope (after the lock has been released).  This should fix PR#27724. Thanks to Hans Boehm for the bug report and the suggested fix.

llvm-svn: 269965
2016-05-18 17:50:13 +00:00
Eric Fiselier 4524d6e739 Change allocator<T>::allocate to throw length_error, not bad_alloc
llvm-svn: 268842
2016-05-07 03:12:24 +00:00
Eric Fiselier f07dd8d0a9 Add is_swappable/is_nothrow_swappable traits
llvm-svn: 267079
2016-04-21 23:38:59 +00:00
Eric Fiselier 89dd1dd278 Fix most GCC attribute ignored warnings
llvm-svn: 267074
2016-04-21 22:54:21 +00:00
Marshall Clow 4cec709ed6 Fix for PR26812: possible overflow issue in std::allocator::allocate
llvm-svn: 262610
2016-03-03 12:04:39 +00:00
Marshall Clow 026b805687 Another chunk of N4089
llvm-svn: 261894
2016-02-25 16:50:51 +00:00
Marshall Clow ec880422df Preemptively disable unsigned integer sanitization in 32 and 64 bit versions of __murmur2_or_cityhash. This lets people use the unsigned integer overflow checker in UBSAN w/o getting hits from libc++'s hash code (where the unsigned integer overflow is legal and deliberate)> Patch by @danielaustin. Reviewed as: http://reviews.llvm.org/D15973
llvm-svn: 257368
2016-01-11 19:27:10 +00:00
Evgeniy Stepanov 02b8e94943 Add 3 more missing inline/visibility attributes.
These are the cases when an out-of-class definition of a method is
marked _LIBCPP_INLINE_VISIBILITY, but the in-class declaration is
not. This will start failing when (or if) we switch to
attribute((internal_linkage)).

llvm-svn: 255166
2015-12-09 22:32:36 +00:00
Marshall Clow 183c010c9a Implement P0074: Making owner_less more flexible
llvm-svn: 252905
2015-11-12 15:56:44 +00:00
Evgeniy Stepanov 906c872db9 Cleanup: move visibility/linkage attributes to the first declaration.
This change moves visibility attributes from out-of-class method
definitions to in-class declaration. This is needed for a switch to
attribute((internal_linkage)) (see http://reviews.llvm.org/D13925)
which can only appear on the first declaration.

This change does not touch istream/ostream/streambuf. They are
handled separately in http://reviews.llvm.org/D14409.

llvm-svn: 252385
2015-11-07 01:22:13 +00:00
Marshall Clow b631c24359 Add a test for LWG#2466: allocator_traits::max_size() default behavior is incorrect
llvm-svn: 251252
2015-10-25 19:34:04 +00:00
Marshall Clow 2603b0758d Fix LWG#2127: Move-construction with raw_storage_iterator.
llvm-svn: 251247
2015-10-25 18:58:07 +00:00
Eric Fiselier d48306e704 [libcxx] Constrain unique_ptr::operator=(unique_ptr<Tp, Dp>) in C++03 mode
Summary:
This patch properly constrains the converting assignment operator in C++03. It also fixes a bug where std::forward was given the wrong type.
The following two tests begin passing in C++03:

* `unique_ptr.single.asgn/move_convert.pass.cpp`
* `unique_ptr.single.asgn/move_convert13.fail.cpp`

Reviewers: mclow.lists

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D12173

llvm-svn: 246272
2015-08-28 05:07:06 +00:00
Eric Fiselier 1c81340797 Recommit rL245802: Cleanup fancy pointer rebinding in list using __rebind_pointer.
Currently we need an #ifdef branch every time we use pointer traits to rebind a pointer because
it is done differently in C++11 and C++03. This patch introduces the __rebind_pointer utility to
clean this up.

Also add a test that list and it's iterators can be instantiated with incomplete element types.

llvm-svn: 245806
2015-08-23 02:56:05 +00:00
Eric Fiselier 236f405b1d Revert r245802. It violates the incomplete type requirements.
llvm-svn: 245805
2015-08-23 02:39:20 +00:00
Eric Fiselier 24e817d223 Cleanup fancy pointer rebinding in list using __rebind_pointer.
Currently we need an #ifdef branch every time we use pointer traits to rebind a pointer because
it is done differently in C++11 and C++03. This patch introduces the __rebind_pointer utility to
clean this up. 

llvm-svn: 245802
2015-08-23 02:34:18 +00:00
Eric Fiselier 749adeba3d [libcxx] Allow use of <atomic> in C++03. Try 3.
Summary:
After putting this question up on cfe-dev I have decided that it would be best to allow the use of `<atomic>` in C++03. Although static initialization is a concern the syntax required to get it is C++11 only. Meaning that C++11 constant static initialization cannot silently break in C++03, it will always cause a syntax error. Furthermore `ATOMIC_VAR_INIT` and `ATOMIC_FLAG_INIT` remain defined in C++03 even though they cannot be used because C++03 usages will cause better error messages.

The main change in this patch is to replace `__has_feature(cxx_atomic)`, which only returns true when C++ >= 11, to `__has_extension(c_atomic)` which returns true whenever clang supports the required atomic builtins.


This patch adds the following macros:
* `_LIBCPP_HAS_C_ATOMIC_IMP`      - Defined on clang versions which provide the C `_Atomic` keyword.
* `_LIBCPP_HAS_GCC_ATOMIC_IMP` - Defined on GCC > 4.7. We must use the fallback atomic implementation.
* `_LIBCPP_HAS_NO_ATOMIC_HEADER` - Defined when it is not safe to include `<atomic>`.

`_LIBCPP_HAS_C_ATOMIC_IMP` and `_LIBCPP_HAS_GCC_ATOMIC_IMP` are mutually exclusive, only one should be defined. If neither is defined then `<atomic>` is not implemented and including `<atomic>` will issue an error.

Reviewers: chandlerc, jroelofs, mclow.lists

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D11555

llvm-svn: 245463
2015-08-19 17:21:46 +00:00
Marshall Clow 29f11b381f Broke C++03 compatibility in 245330. Fix that.
llvm-svn: 245336
2015-08-18 19:51:37 +00:00
Marshall Clow 1378a5aec3 implement more of N4258 - Cleaning up noexcept in the standard library. Specifically add new noexcept stuff to vector and string's move-assignment operations
llvm-svn: 245330
2015-08-18 18:57:00 +00:00
Eric Fiselier 87a82490fc Enable and fix warnings during the build.
Although CMake adds warning flags, they are ignored in the libc++ headers
because the headers '#pragma system header' themselves.

This patch disables the system header pragma when building libc++ and fixes
the warnings that arose.

The warnings fixed were:
1. <memory> - anonymous structs are a GNU extension
2. <functional> - anonymous structs are a GNU extension.
3. <__hash_table> - Embedded preprocessor directives have undefined behavior.
4. <string> - Definition is missing noexcept from declaration.
5. <__std_stream> - Unused variable.

llvm-svn: 242623
2015-07-18 20:40:46 +00:00
Marshall Clow 05fc0f25d6 Make sure that __libcpp_compressed_pair_imp default-constructs its' members, rather than value-initializing them. Fixes PR#24137
llvm-svn: 242377
2015-07-16 03:05:06 +00:00
Marshall Clow e3fbe1433b Implement the first part of N4258: 'Cleaning up noexcept in the Library'. This patch deals with swapping containers, and implements a more strict noexcept specification (a conforming extension) than the standard mandates.
llvm-svn: 242056
2015-07-13 20:04:56 +00:00
Eric Fiselier 1faf289e27 [libcxx] Add atomic_support.h header to src that handles needed atomic operations.
Summary:
In some places in libc++ we need to use the `__atomic_*` builtins. This patch adds a header that provides access to those builtins in a uniform way from within the dylib source.

If the compiler building the dylib does not support these builtins then a warning is issued.

Only relaxed loads are needed within the headers. A singe function to do these relaxed loads has been added to `<memory>`.

This patch applies the new atomic builtins to `__shared_count` and `call_once`.

Reviewers: mclow.lists

Subscribers: majnemer, jroelofs, cfe-commits

Differential Revision: http://reviews.llvm.org/D10406

llvm-svn: 241532
2015-07-07 00:27:16 +00:00
Marshall Clow f43a42d53e Noticed that std::allocator<const T> was missing the definition for is_always_equal. Fixed this, and added a test for it.
llvm-svn: 241190
2015-07-01 21:23:40 +00:00
Marshall Clow 5b0f04a589 Fix illegal chars that snuck into <memory>
llvm-svn: 240163
2015-06-19 19:32:06 +00:00
Marshall Clow 79336aa3a4 Fix ASAN bot; missing bookkeeping in r240136.
llvm-svn: 240139
2015-06-19 17:13:59 +00:00
Marshall Clow 55112defb0 Fix PR#18843. Thanks to Howard for the fix
llvm-svn: 240136
2015-06-19 15:54:13 +00:00
Eric Fiselier ee187e247b [libcxx] Fix detection of __is_final.
Summary: Currently we only enable the use of __is_final(...) with Clang. GCC also provides __is_final(...) since 4.7 in all standard modes. This patch creates the macro _LIBCPP_HAS_IS_FINAL to note the availability of `__is_final`.

Reviewers: danalbert, mclow.lists

Reviewed By: mclow.lists

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D8795

llvm-svn: 239664
2015-06-13 07:08:02 +00:00
Marshall Clow 31a4731370 Implement the first part of N4258 - allocator_traits<X>::is_always_equal. Also fixes PR#23723
llvm-svn: 238848
2015-06-02 16:34:03 +00:00
Marshall Clow e623074210 In the case where we are copying/moving zero elements, do less work
llvm-svn: 238828
2015-06-02 13:04:18 +00:00
Marshall Clow b74d15e507 Remove debugging code
llvm-svn: 238674
2015-05-31 14:01:54 +00:00
Marshall Clow 87601bef58 Don't try to memcpy zero bytes; sometimes the source pointer is NULL, and that's UB. Thanks to Nuno Lopes for the catch.
llvm-svn: 238666
2015-05-31 03:13:31 +00:00
Marshall Clow a7fb9a041d Fix PR#23647 - make_shared<volatile bool> - second try
llvm-svn: 238370
2015-05-27 22:44:47 +00:00
Marshall Clow 188b98b505 Revert 238354 while I figure out what broke in weak_ptr
llvm-svn: 238355
2015-05-27 20:36:14 +00:00
Marshall Clow 263a0f7681 Fix PR#23647 - make_shared<volatile bool>
llvm-svn: 238354
2015-05-27 20:15:33 +00:00
Marshall Clow a00932bddb Implement LWG2433: uninitialized_copy()/etc. should tolerate overloaded operator&
llvm-svn: 237699
2015-05-19 15:01:48 +00:00
Marshall Clow c34f847b80 Fix for LWG Issue 2415: Inconsistency between unique_ptr and shared_ptr
llvm-svn: 236953
2015-05-10 13:59:45 +00:00
Marshall Clow 783b372a58 Fix for LWG2454: Add raw_storage_iterator::base() member
llvm-svn: 236948
2015-05-10 13:14:08 +00:00
Marshall Clow 1f508014df In many places, there was an #ifdef/#else block that selected one of two implmentations of rebind_alloc based on whether or not we had template aliases. Create a helper struct to encapsulate that bit of logic, and replace all the ifdefs with uses of that struct. No functionality change intented.
llvm-svn: 234296
2015-04-07 05:21:38 +00:00
Eric Fiselier e782178e9c [libcxx] Optimize vectors uninitialized construction of trivial types from an iterator range.
Summary:
In certain cases vector can use memcpy to construct a range of elements at the back of the vector. We currently don't do this resulting in terrible code gen in non-optimized mode and a
very large slowdown compared to libstdc++. 

This patch adds a `__construct_forward_range(Allocator, Iter, Iter, _Ptr&)` and `__construct_forward_range(Allocator, Tp*, Tp*, Tp*&)` functions to `allocator_traits` which act similarly to the existing `__construct_forward(...)` functions.

This patch also changes vectors `__construct_at_end(Iter, Iter)` to be `__construct_at_end(Iter, Iter, SizeType)` where SizeType is the size of the range. `__construct_at_end(Iter, Iter, SizeType)` now calls `allocator_traits<Tp>::__construct_forward_range(...)`. 

This patch is based off the design of `__swap_out_circular_buffer(...)` which uses `allocator_traits<Tp>::__construct_forward(...)`.

On my machine this code performs 4x better than the current implementation when tested against `std::vector<int>`. 



Reviewers: howard.hinnant, titus, kcc, mclow.lists

Reviewed By: mclow.lists

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D8109

llvm-svn: 233711
2015-03-31 16:54:19 +00:00
Saleem Abdulrasool 8e5ce33193 Handle function name conflicts in _LIBCPP_MSVCRT mode
Visual Studio's SAL extension uses a macro named __deallocate. This macro is
used pervasively, and gets included through various different ways. This
conflicts with the similarly named interfaces in libc++. Introduce a undef
header similar to __undef_min_max to handle this. This fixes a number of errors
due to the macro replacing the function name.

llvm-svn: 229162
2015-02-13 22:15:32 +00:00
Eric Fiselier 6fe361c1ef Remove use of _[A-Z] identifiers and poison them to detect usage
llvm-svn: 228353
2015-02-05 23:01:40 +00:00
Marshall Clow 278ddec22c Implement LWG2400 - 'shared_ptr's get_deleter() should use addressof()', and add tests. Mark LWG2400 and LWG2404 as complete
llvm-svn: 222161
2014-11-17 19:05:50 +00:00