Commit Graph

1109 Commits

Author SHA1 Message Date
Ed Schouten e0cf3b9a3c Make support for thread-unsafe C functions optional.
One of the aspects of CloudABI is that it aims to help you write code
that is thread-safe out of the box. This is very important if you want
to write libraries that are easy to reuse. For CloudABI we decided to
not provide the thread-unsafe functions. So far this is working out
pretty well, as thread-unsafety issues are detected really early on.

The following patch adds a knob to libc++,
_LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS, that can be set to disable
thread-unsafe functions that can easily be avoided in practice. The
following functions are not thread-safe:

- <clocale>: locale handles should be preferred over setlocale().
- <cstdlib>: mbrlen(), mbrtowc() and wcrtomb() should be preferred over
  their non-restartable counterparts.
- <ctime>: asctime(), ctime(), gmtime() and localtime() are not
  thread-safe. The first two are also deprecated by POSIX.

Differential Revision:	http://reviews.llvm.org/D8703
Reviewed by:	marshall

llvm-svn: 240527
2015-06-24 08:44:38 +00:00
Marshall Clow 99f5fc937f Make seeking on an ostream that has eofbit set work correctly. Fixes PR#21361
llvm-svn: 240286
2015-06-22 15:01:21 +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
Jonathan Roelofs 6dec6d896f Delete dead code. NFCI
llvm-svn: 239974
2015-06-17 23:31:45 +00:00
Eric Fiselier b11df184ad Fix std::function allocator constructors in C++03.
The C++03 version of function tried to default construct the allocator
in the uses allocator constructors when no allocation was performed. These
constructors would fail to compile when used with allocators that had no
default constructor.

llvm-svn: 239708
2015-06-14 23:30:09 +00:00
Eric Fiselier d9ad0cbd70 Cleanup result_of tests and fix issues with the C++03 result_of.
The two main fixes this patch contains are:
- use __identity_t instead of common_type. common_type was used as an
  identity metafunction but the decay resulted in incorrect results.
- Pointers to free functions were not counted as functions. Remove the pointer
  before checking if a type is a function.

llvm-svn: 239668
2015-06-13 08:25:24 +00:00
Eric Fiselier de3f2b396c Fix PR12999 - unordered_set::insert calls operator new when no insert occurs
Summary:
when `unordered_set::insert(value_type&&)` was called it would be treated like `unordered_set::emplace(Args&&)` and it would allocate and construct a node before trying to insert it.
This caused unnecessary allocations when the value was already in the set. This patch adds an overload to `__hash_table::__insert_unique` that specifically handles `value_type&&` more link `value_type const &`. 

This patch also adds a single unified insert function for values into  `__hash_table` called `__insert_unique_value` that handles the cases for `__insert_unique(value_type&&)` and `__insert_unique(value_type const &)`. 

This patch fixes PR12999: http://llvm.org/bugs/show_bug.cgi?id=12999.




Reviewers: mclow.lists, titus, danalbert

Reviewed By: danalbert

Subscribers: cfe-commits

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

llvm-svn: 239666
2015-06-13 07:18:32 +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
Eric Fiselier f817754627 [libcxx] Use __decltype instead of __typeof__
Summary:
Both clang and GCC provide C++11 decltype semantics as __decltype in c++03 mode. We should use this instead of __typeof__ when availble. 

GCC added __decltype in 4.6.0, and AFAIK clang provided __decltype ever since 3.3. Unfortunately `__has_builtin(__decltype)` doesn't work for clang so we need to check the compiler version instead.


Reviewers: mclow.lists

Reviewed By: mclow.lists

Subscribers: cfe-commits

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

llvm-svn: 239662
2015-06-13 06:27:17 +00:00
Eric Fiselier fd1f5e66c1 Make __void_t unary and always provide it.
llvm-svn: 239655
2015-06-13 02:36:07 +00:00
Eric Fiselier 793f59e767 LWG2442: call_once() shouldn't DECAY_COPY(). Patch from K-Ballo.
This patch fixes LWG issue 2422 by removing the DECAY_COPY from call once.
The review can be found here: http://reviews.llvm.org/D10191

llvm-svn: 239654
2015-06-13 02:23:00 +00:00
Eric Fiselier 678ad2f9da Enable __is_trivially* intrinsics for GCC 5.1
Until GCC 5.1 the __is_trivially* intrinsics were not provided. Enable use of
the builtins for GCC 5.1.

Also enable Reference qualified member functions for GCC 4.9 and greater.

This patch also defines _GNUC_VER to 0 when __GNUC__ is not defined because
libc++ assumes _GNUC_VER is always defined.

llvm-svn: 239653
2015-06-13 02:18:44 +00:00
Eric Fiselier 8aba6a6db4 Refactor is_member_function_pointer to use is_function and not __member_function_traits.
Replacing the dependancy on __member_function_traits with is_function allows
is_member_function_pointer to work more often. In particular it allows it to
work when we don't have variadic templates but the function has an arity > 3.

llvm-svn: 239649
2015-06-13 00:33:13 +00:00
Eric Fiselier 776cc6e48f Prevent dependancy on libatomic when using GCC to provide <atomic>.
The __atomic_is_lock_free(...) function sometimes requires linkage to libatomic
if it cannot be evaluated at compile time. Remove __c11_atomic_is_lock_free
and use __atomic_is_lock_free(sizeof(Tp)) directly so that it can be evaluated
at compile time.

llvm-svn: 239648
2015-06-13 00:23:07 +00:00
Eric Fiselier b3ec43d78a Fix PR23293 - Do not unlock shared state before notifying consumers.
Within the shared state methods do not unlock the lock guards manually. This
could cause a race condition where the shared state is destroyed before the
method is complete.

llvm-svn: 239577
2015-06-12 00:41:34 +00:00
Marshall Clow b41e76bb0b Fix PR#23767. Add tests for iterator invalidation for deque::erase/pop_front/pop_back
llvm-svn: 239196
2015-06-05 22:34:19 +00:00
Marshall Clow 979550f221 While applying N4258, I forgot about LWG#2455, which modified the modifications. Correct those - h/t: Howard
llvm-svn: 239004
2015-06-04 02:05:41 +00:00
Marshall Clow a8ae392718 More N4258 changes. This time vector's constructors
llvm-svn: 238990
2015-06-04 00:10:20 +00:00
Marshall Clow cbf166a2b9 More of N4258 implementation. Mark all of our test_allocators as noexcept constructible. Make the constructors for basic_string noexcept all the time (under C++14). Update tests to reflect the new world order. More to come.
llvm-svn: 238957
2015-06-03 19:56:43 +00:00
Marshall Clow 2abfcd5606 Add 'is_always_equal' tests for scoped_allocator. Found that I had typed '||' where I meant '&&' in the code; fixed that, too
llvm-svn: 238931
2015-06-03 16:15:55 +00:00
Marshall Clow 3ca2099fdf Revert changes inadvertantly committed
llvm-svn: 238880
2015-06-02 22:26:29 +00:00
Marshall Clow ef96861df9 Move uncaught_exeption() definition inside the #ifdef block like uncaught_exceptions()
llvm-svn: 238879
2015-06-02 22:25:23 +00:00
Marshall Clow 8880c20892 Fix breakage that I introduced in r238848
llvm-svn: 238870
2015-06-02 21:40:58 +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 89102f0fa9 Implement uncaught_exceptions() using the newly added hooks in libc++abi, when available
llvm-svn: 238846
2015-06-02 15:33:38 +00:00
Marshall Clow 5b31205211 Fix some places where we could call memmove(null,xxx,0) - which is UB
llvm-svn: 238831
2015-06-02 13:52:16 +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
Eric Fiselier 03d5dd2825 Add missing return statements in C++03 std::function
llvm-svn: 238803
2015-06-02 01:31:33 +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
Eric Fiselier 1f294fd934 Fix building and testing libc++ with GCC.
The changes in src/exception.cpp and cmake/Modules/HandleLibCXXABI.cmake fix a
bug when building libc++ with GCC. Because GCC does not support __has_include
we need to explicitly tell it that we are building against libc++abi via the
preprocessor definition `LIBCXX_BUILDING_LIBCXXABI`.

The changes in include/ratio are to work around CWG defect
1712 (constexpr variable template declarations). GCC 4.8 and before has not
adopted the resolution to this defect.

The changes in include/exception work around an issue where is_final is used
without it being defined in type_traits.

llvm-svn: 237767
2015-05-20 03:15:01 +00:00
Eric Fiselier 35cb2b28ca Rename internal trait that used non-reserved name.
llvm-svn: 237737
2015-05-19 22:27:18 +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
Eric Fiselier c1a44c4a53 [libcxx] Rework sized delete.
Summary:
This patch does 2 main things:
1. Enable sized delete if the feature test macro `__cpp_sized_deallocation` is enabled.
2. Rework and cleanup all of the sized delete tests.

Test Plan:
The sized delete replacement tests are now split into 4 files:
1. sized_delete11.pass.cpp: Ensure overriding sized delete in C++11 has no effect.
2. sized_delete14.pass.cpp: Test overriding sized delete in C++14 and ensure it is called. This test fails on clang and GCC < 5.1. 
3. size_delete_calls_unsized_delete_.pass.cpp: Test that the default sized delete calls unsized delete.
4. sized_delete_fsizeddeallocation.pass.cpp: Test overriding sized delete when -fsized-deallocation is passed. This test should pass on clang and GCC >= 5.1

I have also removed a lot of cruft from the old tests. They no longer replace the new handler and tests that it is called for bad allocations.

Reviewers: mclow.lists

Reviewed By: mclow.lists

Subscribers: cfe-commits

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

llvm-svn: 237662
2015-05-19 02:03:22 +00:00
Marshall Clow cd6615fd71 Add support for N4389 - std::bool_constant
llvm-svn: 237636
2015-05-18 23:21:06 +00:00
Marshall Clow 0e166e5a9a Fix for LWG Issue 2458: N3778 and new library deallocation signatures.
llvm-svn: 237592
2015-05-18 17:48:45 +00:00
Evgeniy Stepanov 732e2681c7 Implement std::experimental::sample.
Following specification in "C++ Extensions for Library Fundamentals":
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html#alg.random.sample

llvm-svn: 237264
2015-05-13 16:55:41 +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 0b0671ae36 Fix for LWG Issue 2369: constexpr max(initializer_list) vs max_element
llvm-svn: 236952
2015-05-10 13:53:31 +00:00
Marshall Clow ec39296875 Fix for LWG Issue 2059: C++0x ambiguity problem with map::erase
llvm-svn: 236950
2015-05-10 13:35:00 +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 2764799450 Replace two naked references of 'std::' with the macro '_VSTD::'. No functionality change.
llvm-svn: 236593
2015-05-06 12:11:22 +00:00
Marshall Clow ccf5b32d21 Fixed an 'extra tokens at end of #endif directive' warning in experimental/ratio
llvm-svn: 235607
2015-04-23 16:45:08 +00:00
Eric Fiselier 445d718807 Remove constexpr support for std::apply because it introduces regressions.
llvm-svn: 235274
2015-04-19 15:32:52 +00:00
Marshall Clow 60d5e0e027 A few bits of N2994 didn't get fully implemented a long time ago. Thanks to STL@microsoft.com for the bug report
llvm-svn: 235134
2015-04-16 21:36:54 +00:00