Commit Graph

114 Commits

Author SHA1 Message Date
Eric Fiselier
bb2f28e15d 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.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@245806 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-23 02:56:05 +00:00
Eric Fiselier
d686dda62e Revert r245802. It violates the incomplete type requirements.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@245805 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-23 02:39:20 +00:00
Eric Fiselier
a276cb01be 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. 

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@245802 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-23 02:34:18 +00:00
Eric Fiselier
00f4a49b0b [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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@245463 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-19 17:21:46 +00:00
Marshall Clow
d434e2a535 Broke C++03 compatibility in 245330. Fix that.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@245336 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-18 19:51:37 +00:00
Marshall Clow
af961ed8cf implement more of N4258 - Cleaning up noexcept in the standard library. Specifically add new noexcept stuff to vector and string's move-assignment operations
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@245330 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-18 18:57:00 +00:00
Eric Fiselier
692177d022 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.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@242623 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-18 20:40:46 +00:00
Marshall Clow
cd6ed54fed Make sure that __libcpp_compressed_pair_imp default-constructs its' members, rather than value-initializing them. Fixes PR#24137
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@242377 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-16 03:05:06 +00:00
Marshall Clow
7d914d1bff 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.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@242056 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-13 20:04:56 +00:00
Eric Fiselier
c6e466911f [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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@241532 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-07 00:27:16 +00:00
Marshall Clow
b81d6f5b8d Noticed that std::allocator<const T> was missing the definition for is_always_equal. Fixed this, and added a test for it.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@241190 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-01 21:23:40 +00:00
Marshall Clow
46d06b90c1 Fix illegal chars that snuck into <memory>
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@240163 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-19 19:32:06 +00:00
Marshall Clow
cb126215aa Fix ASAN bot; missing bookkeeping in r240136.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@240139 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-19 17:13:59 +00:00
Marshall Clow
c41133728d Fix PR#18843. Thanks to Howard for the fix
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@240136 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-19 15:54:13 +00:00
Eric Fiselier
3a0e430cd4 [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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@239664 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-13 07:08:02 +00:00
Marshall Clow
f0324bcaa1 Implement the first part of N4258 - allocator_traits<X>::is_always_equal. Also fixes PR#23723
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@238848 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-02 16:34:03 +00:00
Marshall Clow
56523ff60e In the case where we are copying/moving zero elements, do less work
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@238828 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-02 13:04:18 +00:00
Marshall Clow
ebc31694e8 Remove debugging code
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@238674 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-31 14:01:54 +00:00
Marshall Clow
bf0460e0a0 Don't try to memcpy zero bytes; sometimes the source pointer is NULL, and that's UB. Thanks to Nuno Lopes for the catch.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@238666 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-31 03:13:31 +00:00
Marshall Clow
60784f62de Fix PR#23647 - make_shared<volatile bool> - second try
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@238370 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-27 22:44:47 +00:00
Marshall Clow
fc3a3ffc69 Revert 238354 while I figure out what broke in weak_ptr
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@238355 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-27 20:36:14 +00:00
Marshall Clow
83f8153b22 Fix PR#23647 - make_shared<volatile bool>
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@238354 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-27 20:15:33 +00:00
Marshall Clow
5dce73dd6e Implement LWG2433: uninitialized_copy()/etc. should tolerate overloaded operator&
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@237699 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-19 15:01:48 +00:00
Marshall Clow
0ad232a882 Fix for LWG Issue 2415: Inconsistency between unique_ptr and shared_ptr
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@236953 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-10 13:59:45 +00:00
Marshall Clow
dbaf7a0d31 Fix for LWG2454: Add raw_storage_iterator::base() member
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@236948 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-10 13:14:08 +00:00
Marshall Clow
66302c650b 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.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@234296 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-07 05:21:38 +00:00
Eric Fiselier
088ed9fe94 [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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@233711 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-31 16:54:19 +00:00
Saleem Abdulrasool
f1b30c41ad 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.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@229162 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-13 22:15:32 +00:00
Eric Fiselier
8492cd84ff Remove use of _[A-Z] identifiers and poison them to detect usage
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@228353 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-05 23:01:40 +00:00
Marshall Clow
4b3ca8c249 Implement LWG2400 - 'shared_ptr's get_deleter() should use addressof()', and add tests. Mark LWG2400 and LWG2404 as complete
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@222161 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-17 19:05:50 +00:00
Marshall Clow
3f5579f0b2 Fix typo in allocator_traits::construct. This fixes PR14175, which shows up if an allocator has a no-args construct method
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@221697 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-11 19:22:33 +00:00
Eric Fiselier
4e7d53664d 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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@220469 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-23 04:12:28 +00:00
Jonathan Roelofs
8d86b2e686 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


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@217271 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-05 19:45:05 +00:00
Marshall Clow
394451db81 Fix a typo in the noexcept calculation for __compressed_pair::swap. Thanks to EricWF for the bug report and the fix.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@212046 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-30 15:35:09 +00:00
Marshall Clow
ba6dbf4866 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.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@211563 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-24 00:46:19 +00:00
Richard Smith
73c1fce21c Use __builtin_operator_new/__builtin_operator_delete when available. This
allows allocations and deallocations to be optimized out.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@210211 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-04 19:54:15 +00:00
Marshall Clow
5f64a2b3c3 Fix bug #18350. Add tests for tuples of all the smart pointers (except auto_ptr)
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@207307 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-26 05:19:48 +00:00
Marshall Clow
23ef151614 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.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@202931 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-05 03:12:04 +00:00
Logan Chien
e1678a18d9 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.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@200523 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-31 09:30:46 +00:00
Howard Hinnant
3f81e9eeba 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.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@194536 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-13 00:39:22 +00:00
Howard Hinnant
8127758024 David Chisnall: macro protect 'test' in __has_pointer_type_imp.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@191126 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-21 01:45:05 +00:00
Howard Hinnant
37c4acfe5e G M: Make shared_ptr a little more gentle for some compilers. No impact on clang.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@190732 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-13 23:56:00 +00:00
Marshall Clow
1b5f3adcef Updated the synopsis for weak_ptr<T>::owner_before to match the code. No code changes.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@189812 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-03 14:37:50 +00:00
Marshall Clow
08b4f3f99b LWG Issue 2162: mark allocator_traits::maxsize as noexcept
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@189399 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-27 20:22:15 +00:00
Howard Hinnant
0f678bd69e 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>.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@188192 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-12 18:38:34 +00:00
Howard Hinnant
a4e87abbb9 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.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@187997 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-08 18:38:55 +00:00
Arnold Schwaighofer
a709c823f7 Revert r187927.
Zhihao Yuan: Replace operator& with addressof in reference_wrapper constructor.

It breaks a clang bootstrap.



git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@187959 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-08 03:06:24 +00:00
Howard Hinnant
d8bfe7ba56 Zhihao Yuan: Replace operator& with addressof in reference_wrapper constructor.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@187927 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-07 23:02:42 +00:00
Howard Hinnant
24ae8f8e5b 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.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185558 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-03 17:39:28 +00:00
Marshall Clow
fb5511027b Adorn make_unique with visibility and inline attributes
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185468 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-02 20:06:09 +00:00