Commit Graph

89 Commits

Author SHA1 Message Date
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
Marshall Clow 981f31ac51 Fix typo in allocator_traits::construct. This fixes PR14175, which shows up if an allocator has a no-args construct method
llvm-svn: 221697
2014-11-11 19:22:33 +00:00
Eric Fiselier 319be72220 Add support for "fancy" pointers to shared_ptr. Fixes PR20616
Summary:
This patch add support for "fancy pointers/allocators" as well as fixing support for shared_pointer and "minimal" allocators.

Fancy pointers are class types that meet the NullablePointer requirements. In our case they are created by fancy allocators. `support/min_allocator.h` is an archetype for these types.

There are three types of changes made in this patch:
1. `_Alloc::template rebind<T>::other` -> `__allocator_traits_rebind<_Alloc, T>::type`. This change was made because allocators don't need a rebind template. `__allocator_traits_rebind` is used instead of `allocator_traits::rebind` because use of `allocator_traits::rebind` requires a workaround for when template aliases are unavailable.
2. `a.deallocate(this, 1)` -> `a.deallocate(pointer_traits<self>::pointer_to(*this), 1)`. This change change is made because fancy pointers aren't always constructible from raw pointers. 
3. `p.get()` -> `addressof(*p.get())`. Fancy pointers aren't actually a pointer. When we need a "real" pointer we take the address of dereferencing the fancy pointer. This should give us the actual raw pointer.

Test Plan: Tests were added using `support/min_allocator.h` to each affected shared_ptr overload and creation function. These tests can only be executed in C++11 or greater since min_allocator is only available then. A extra test was added for the non-variadic versions of allocate_shared. 

Reviewers: danalbert, mclow.lists

Reviewed By: mclow.lists

Subscribers: cfe-commits

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

llvm-svn: 220469
2014-10-23 04:12:28 +00:00
Jonathan Roelofs b3fcc67f8f Allow libc++ to be built on systems without POSIX threads
If you're crazy enough to want this sort of thing, then add
-D_LIBCPP_HAS_NO_THREADS to your CXXFLAGS and
--param=additiona_features=libcpp-has-no-threads to your lit commnad line.

http://reviews.llvm.org/D3969

llvm-svn: 217271
2014-09-05 19:45:05 +00:00
Marshall Clow afa72ed47c Fix a typo in the noexcept calculation for __compressed_pair::swap. Thanks to EricWF for the bug report and the fix.
llvm-svn: 212046
2014-06-30 15:35:09 +00:00
Marshall Clow f9af6140ff Some calls to get<>() were qualified. Some were not. Qualify them all. Fixes bug #20092. Thanks to Agustín Bergé for the bug report and the fix.
llvm-svn: 211563
2014-06-24 00:46:19 +00:00
Richard Smith ff0aff3caf Use __builtin_operator_new/__builtin_operator_delete when available. This
allows allocations and deallocations to be optimized out.

llvm-svn: 210211
2014-06-04 19:54:15 +00:00
Marshall Clow 85d3e7a729 Fix bug #18350. Add tests for tuples of all the smart pointers (except auto_ptr)
llvm-svn: 207307
2014-04-26 05:19:48 +00:00
Marshall Clow 4703f76376 Update synposis in <memory> to show move semantics for weak_ptr; add tests for already existing move semantics. Mark LWG issues #2315 (no changes needed), 2316 (move semantics for weak_ptr), 2252 (previous commit) and 2271 (previous commit) as complete.
llvm-svn: 202931
2014-03-05 03:12:04 +00:00
Logan Chien 22747e621e Remove default function template argument from the header.
GCC will treat the default function template arguments as a
compilation error if C++0x is not enabled.

This commit workaround the compilation error by moving the
SFINAE check to function argument instead of the template
argument.

llvm-svn: 200523
2014-01-31 09:30:46 +00:00
Howard Hinnant ccad8c32e0 This fixes a very subtle ABI problem concerning the copy constructor of
pair, and a couple of pair-like implementation detail types.  The
C++98/03 and 11 standards all specify that the copy constructor of
pair<int, int> is trivial. However as libc++ tracked the draft C++11
standard over the years, this copy constructor became non-trivial, and
then just recently was corrected back to trivial for C++11.

Unfortunately (for libc++1) the Itanium ABI specifies different calling
conventions for trivial and non-trivial copy constructors.  Therefore
currently the C++03 libc++ copy constructor for pair<int, int> is ABI
incompatible with the C++11 libc++ copy constructor for pair<int, int>.
This is Bad(tm).   This patch corrects the situation by making this copy
constructor trivial in C++03 mode as well.

Just in case it is needed for an incomplete C++11 compiler, libc++
retains the ability to support pair with rvalue references, but without
defaulted special members.  However the pair needs non-trivial special
members to implement this special case, (as it did when clang was in
this place a couple of years ago).

During this work a bug was also found and fixed in
is_trivially_constructible.

And there is a minor drive-by fix in <__config> regarding
__type_visibility__.

A test is updated to ensure that the copy constructor of pair<int, int>
is trivial in both C++03 and C++11.  This test will necessarily fail for
a compiler that implements rvalue references but not defaulted special
members.

llvm-svn: 194536
2013-11-13 00:39:22 +00:00
Howard Hinnant b1c82cd090 David Chisnall: macro protect 'test' in __has_pointer_type_imp.
llvm-svn: 191126
2013-09-21 01:45:05 +00:00
Howard Hinnant 84f996fb2e G M: Make shared_ptr a little more gentle for some compilers. No impact on clang.
llvm-svn: 190732
2013-09-13 23:56:00 +00:00
Marshall Clow 710a902cac Updated the synopsis for weak_ptr<T>::owner_before to match the code. No code changes.
llvm-svn: 189812
2013-09-03 14:37:50 +00:00
Marshall Clow 06fbed03fc LWG Issue 2162: mark allocator_traits::maxsize as noexcept
llvm-svn: 189399
2013-08-27 20:22:15 +00:00
Howard Hinnant f0544c2086 Nico Rieck: this patch series fixes visibility issues on Windows as explained in <http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-August/031214.html>.
llvm-svn: 188192
2013-08-12 18:38:34 +00:00
Howard Hinnant 8c9742051d My previous reorganization of addressof broke -std=c++03. Thanks much to Arnold Schwaighofer for catching this. This patch also catches a few more missing addressof in <future>, thanks go to Zhihao Yuan for catching these.
llvm-svn: 187997
2013-08-08 18:38:55 +00:00
Arnold Schwaighofer 5331e3a481 Revert r187927.
Zhihao Yuan: Replace operator& with addressof in reference_wrapper constructor.

It breaks a clang bootstrap.

llvm-svn: 187959
2013-08-08 03:06:24 +00:00
Howard Hinnant 9027f5e3de Zhihao Yuan: Replace operator& with addressof in reference_wrapper constructor.
llvm-svn: 187927
2013-08-07 23:02:42 +00:00
Howard Hinnant 84b569d5cf Matthew Dempsky: Attached patch replaces the type punning with memcpy(), which on
x86/x86-64 clang optimizes to direct word accesses anyway.  This fixes an unaligned word access in murmurhash/cityhash.

llvm-svn: 185558
2013-07-03 17:39:28 +00:00
Marshall Clow 95ddb53049 Adorn make_unique with visibility and inline attributes
llvm-svn: 185468
2013-07-02 20:06:09 +00:00
Marshall Clow 28d8ba5f79 Implement n3656 - make_unique. Thanks to Howard for the review and suggestions.
llvm-svn: 185352
2013-07-01 18:16:03 +00:00
Howard Hinnant 30444adc70 Minor bug fix for allowing an extension of const-qualified types in containers.
llvm-svn: 183481
2013-06-07 01:56:37 +00:00
Howard Hinnant eedfabd96e Expose accidentally removed __compressed_pair constructor taking piecewise_construct_t. This fixes http://llvm.org/bugs/show_bug.cgi?id=15918 .
llvm-svn: 181217
2013-05-06 16:58:36 +00:00
Howard Hinnant 03ec04f9b5 default_delete needs a static_assert against void types. I had previously thought that sizeof(void) would take care of this. I was wrong.
llvm-svn: 180213
2013-04-24 19:44:26 +00:00
Howard Hinnant c76d2bda6f addressof misbehaving for type with an implicit conversion operator to char&. This fixes http://llvm.org/bugs/show_bug.cgi?id=15754
llvm-svn: 179608
2013-04-16 17:27:56 +00:00
Howard Hinnant 6e41256f68 No functionality change at this time. I've split _LIBCPP_VISIBLE up into two flags: _LIBCPP_TYPE_VIS and _LIBCPP_FUNC_VIS. This is in preparation for taking advantage of clang's new __type_visibility__ attribute.
llvm-svn: 176593
2013-03-06 23:30:19 +00:00
Howard Hinnant a9f698009f Alexey Samsonov: #ifdefs out undefined function in static build of libc++ w/o RTTI.
llvm-svn: 176026
2013-02-25 15:50:36 +00:00
Howard Hinnant 8d9aec8802 Fix exception safety bug in vector::push_back
llvm-svn: 172250
2013-01-11 20:36:59 +00:00
Howard Hinnant 54d333a601 Rename uses of _ and __ because these are getting stepped on by macros from other system code.
llvm-svn: 167038
2012-10-30 19:06:59 +00:00
Howard Hinnant aeb85680fb Dimitry Andric: many visibility fixes. Howard: Much appreciated. Can you send me a patch to CREDITS.TXT?
llvm-svn: 163862
2012-09-14 00:39:16 +00:00
Howard Hinnant d77851e837 Implement [util.smartptr.shared.atomic]. This is the last unimplemented
section in libc++.  This requires a recompiled dylib.  Failure to rebuild
the dylib will result in a link-time error if and only if the functions from
[util.smartptr.shared.atomic] are used.

The implementation is not lock free.  After considerable thought, I know of no
way to make the implementation lock free.  Ideas welcome along that front.  But
changing the ABI of shared_ptr is not on the table at this point.

The mutex used to lock these function is encapsulated by std::__sp_mut.  The
only thing the client knows about std::__sp_mut is that it has a void* data
member, can't be constructed, and has lock and unlock members.  Within the
binary __sp_mut is currently implemented as a pointer to a std::mutex.  That can
change in the future without disturbing the ABI (as long as sizeof(__sp_mut)
remains constant.

I specifically did not make __sp_mut a spin lock as I have a pathological
distrust of spin locks.  Testing on OS X reveals that the use of std::mutex in
this role is not a large performance penalty as long as the contention for the
mutex is low (more likely to get the lock than to have to wait).  In the future
we can still make __sp_mut a spin lock if that is what is desired (without ABI
damage).

The dylib contains 16 __sp_mut's to be chosen based on the hash of the address
of the shared_ptr.  The constant 16 is a ball-park reasonable space/time
tradeoff.

std::hash<T*> was changed to call __murmur2_or_cityhash, instead of the identity
function.  I had thought we had already done this, but I was mistaken.

All of this is under #if __has_feature(cxx_atomic) even though the
implementation is not lock free, because the signatures require access to
std::memory_order, which is currently available only under
__has_feature(cxx_atomic).

llvm-svn: 160940
2012-07-30 01:40:57 +00:00
Howard Hinnant c0937e8add Appy constexpr to <memory>. Picked up a few missing noexcepts as well.
llvm-svn: 159902
2012-07-07 20:56:04 +00:00
Howard Hinnant ed81e910bd Revert fix to http://llvm.org/bugs/show_bug.cgi?id=12867 for the reason now included in the code comment.
llvm-svn: 157128
2012-05-19 20:20:49 +00:00
Howard Hinnant 9042d623bf Protect __shared_weak_count::__get_deleter declaration with _LIBCPP_NO_RTTI. Fixes http://llvm.org/bugs/show_bug.cgi?id=12867
llvm-svn: 157049
2012-05-18 13:06:21 +00:00
Howard Hinnant bff1bfc6be Greatly scale back ambitions of emulating move semantics in C++03 mode. It was causing more problems than it solved. This fixes http://llvm.org/bugs/show_bug.cgi?id=12704.
llvm-svn: 155918
2012-05-01 15:37:54 +00:00
Howard Hinnant f2f2d8b98d Modernize conversion to bool to the explicit bool conversion operator (library wide). This fixes http://llvm.org/bugs/show_bug.cgi?id=12058.
llvm-svn: 151088
2012-02-21 21:46:43 +00:00
Howard Hinnant 67f3964766 Modernize relational operators for shared_ptr and unique_ptr. This includes adding support for nullptr, and using less<T*>. Fixes http://llvm.org/bugs/show_bug.cgi?id=12056.
llvm-svn: 151084
2012-02-21 21:02:58 +00:00
Howard Hinnant 9741d6c96e Implement a few optimizations for vector push_back and insert. Fixes r10828365.
llvm-svn: 150542
2012-02-15 00:41:34 +00:00
Howard Hinnant 21fa1887e0 Enable full functionality of shared_ptr<const void> by adding allocator<const void>. Credit to John Hurley for discovering this bug.
llvm-svn: 148508
2012-01-19 23:15:22 +00:00
Howard Hinnant 8e25104b10 1. Fix make_shared<const T>. 2. Allow allocator<const T> as an extension. 3. Refactor work which fixed unique_ptr<const T[]>. 4. Remove no-longer-needed private declarations from unique_ptr. 5. Add constraints to some shared_ptr and weak_ptr constructors and assignment operators so that is_constructible/is_assignable give the correct answers for shared_ptr and weak_ptr. 6. Make defensive preparations in the shared_ptr free functions for the introduction of shared_ptr<T[]> in the future. 7. As an optimization, add move constructor and move assignment to weak_ptr.
llvm-svn: 147437
2012-01-02 17:56:02 +00:00
Howard Hinnant b34b48196c The exception recovery mechanism for the uninitialized_* algorithms did not work for iterators into discontiguous memory.
llvm-svn: 147343
2011-12-29 17:45:35 +00:00
Howard Hinnant a87b5e3446 Fix http://llvm.org/bugs/show_bug.cgi?id=11616
llvm-svn: 146881
2011-12-19 17:58:44 +00:00
Howard Hinnant e4097ad7e6 Allow unique_ptr<T const []> to be constructed and assigned from a unique_ptr<T[]>
llvm-svn: 146853
2011-12-18 21:19:44 +00:00
Howard Hinnant d6f44b6601 Allow unique_ptr<T const []> to be constructed with a T* (in addition to a const T*)
llvm-svn: 146736
2011-12-16 15:37:23 +00:00
Howard Hinnant 42b8bb5033 Fix http://llvm.org/bugs/show_bug.cgi?id=11461. Credit Alberto Ganesh Barbati.
llvm-svn: 146345
2011-12-11 20:31:33 +00:00