diff options
Diffstat (limited to 'libcxx')
47 files changed, 485 insertions, 693 deletions
diff --git a/libcxx/docs/TestingLibcxx.rst b/libcxx/docs/TestingLibcxx.rst index 6171629..dbe6948 100644 --- a/libcxx/docs/TestingLibcxx.rst +++ b/libcxx/docs/TestingLibcxx.rst @@ -419,10 +419,10 @@ writing tests easier. See `libc++-specific Lit Directives`_ for more information - ``// FILE_DEPENDENCIES: file, directory, /path/to/file, ...`` - The paths given to the ``FILE_DEPENDENCIES`` directive can specify directories or specific files upon which a given test depend. For example, a test that requires some test input stored in a data file would use this libc++-specific Lit directive. When a test file contains the ``FILE_DEPENDENCIES`` directive, Lit will collect the named files and copy - them to the directory represented by the ``%T`` substitution before the test executes. The copy is performed from the directory represented by the ``%S`` substitution + them to the directory represented by the ``%{temp}`` substitution before the test executes. The copy is performed from the directory represented by the ``%S`` substitution (i.e. the source directory of the test being executed) which makes it possible to use relative paths to specify the location of dependency files. After Lit copies - all the dependent files to the directory specified by the ``%T`` substitution, that directory should contain *all* the necessary inputs to run. In other words, - it should be possible to copy the contents of the directory specified by the ``%T`` substitution to a remote host where the execution of the test will actually occur. + all the dependent files to the directory specified by the ``%{temp}`` substitution, that directory should contain *all* the necessary inputs to run. In other words, + it should be possible to copy the contents of the directory specified by the ``%{temp}`` substitution to a remote host where the execution of the test will actually occur. * - ``ADDITIONAL_COMPILE_FLAGS`` - ``// ADDITIONAL_COMPILE_FLAGS: flag1 flag2 ...`` - The additional compiler flags specified by a space-separated list to the ``ADDITIONAL_COMPILE_FLAGS`` libc++-specific Lit directive will be added to the end of the ``%{compile_flags}`` diff --git a/libcxx/include/__algorithm/find.h b/libcxx/include/__algorithm/find.h index 72e201a..10379d7 100644 --- a/libcxx/include/__algorithm/find.h +++ b/libcxx/include/__algorithm/find.h @@ -17,12 +17,14 @@ #include <__bit/countr.h> #include <__bit/invert_if.h> #include <__config> +#include <__cstddef/size_t.h> #include <__functional/identity.h> #include <__fwd/bit_reference.h> #include <__iterator/segmented_iterator.h> #include <__string/constexpr_c_functions.h> #include <__type_traits/enable_if.h> #include <__type_traits/invoke.h> +#include <__type_traits/is_constant_evaluated.h> #include <__type_traits/is_equality_comparable.h> #include <__type_traits/is_integral.h> #include <__type_traits/is_signed.h> diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table index 2b246f8..74923ddb 100644 --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -44,6 +44,7 @@ #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/pair.h> +#include <__utility/scope_guard.h> #include <__utility/swap.h> #include <__utility/try_key_extraction.h> #include <limits> @@ -1317,23 +1318,14 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u, max_load_factor() = __u.max_load_factor(); if (bucket_count() != 0) { __next_pointer __cache = __detach(); -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - const_iterator __i = __u.begin(); - while (__cache != nullptr && __u.size() != 0) { - __assign_value(__cache->__upcast()->__get_value(), std::move(__u.remove(__i++)->__get_value())); - __next_pointer __next = __cache->__next_; - __node_insert_multi(__cache->__upcast()); - __cache = __next; - } -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __deallocate_node(__cache); - throw; + auto __guard = std::__make_scope_guard([&] { __deallocate_node(__cache); }); + const_iterator __i = __u.begin(); + while (__cache != nullptr && __u.size() != 0) { + __assign_value(__cache->__upcast()->__get_value(), std::move(__u.remove(__i++)->__get_value())); + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); + __cache = __next; } -#endif // _LIBCPP_HAS_EXCEPTIONS - __deallocate_node(__cache); } const_iterator __i = __u.begin(); while (__u.size() != 0) @@ -1361,22 +1353,13 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __ if (bucket_count() != 0) { __next_pointer __cache = __detach(); -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - for (; __cache != nullptr && __first != __last; ++__first) { - __assign_value(__cache->__upcast()->__get_value(), *__first); - __next_pointer __next = __cache->__next_; - __node_insert_unique(__cache->__upcast()); - __cache = __next; - } -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __deallocate_node(__cache); - throw; + auto __guard = std::__make_scope_guard([&] { __deallocate_node(__cache); }); + for (; __cache != nullptr && __first != __last; ++__first) { + __assign_value(__cache->__upcast()->__get_value(), *__first); + __next_pointer __next = __cache->__next_; + __node_insert_unique(__cache->__upcast()); + __cache = __next; } -#endif // _LIBCPP_HAS_EXCEPTIONS - __deallocate_node(__cache); } for (; __first != __last; ++__first) __emplace_unique(*__first); @@ -1391,22 +1374,13 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f "__assign_multi may only be called with the containers value type or the nodes value type"); if (bucket_count() != 0) { __next_pointer __cache = __detach(); -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - for (; __cache != nullptr && __first != __last; ++__first) { - __assign_value(__cache->__upcast()->__get_value(), *__first); - __next_pointer __next = __cache->__next_; - __node_insert_multi(__cache->__upcast()); - __cache = __next; - } -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __deallocate_node(__cache); - throw; + auto __guard = std::__make_scope_guard([&] { __deallocate_node(__cache); }); + for (; __cache != nullptr && __first != __last; ++__first) { + __assign_value(__cache->__upcast()->__get_value(), *__first); + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); + __cache = __next; } -#endif // _LIBCPP_HAS_EXCEPTIONS - __deallocate_node(__cache); } for (; __first != __last; ++__first) __emplace_multi(*__first); diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h index 0cbd995..e90db58 100644 --- a/libcxx/include/__memory/shared_ptr.h +++ b/libcxx/include/__memory/shared_ptr.h @@ -54,6 +54,7 @@ #include <__type_traits/remove_extent.h> #include <__type_traits/remove_reference.h> #include <__utility/declval.h> +#include <__utility/exception_guard.h> #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/swap.h> @@ -352,23 +353,16 @@ public: template <class _Yp, class _Dp, __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d) : __ptr_(__p) { -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk; + auto __guard = std::__make_exception_guard([&] { __d(__p); }); + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk; #ifndef _LIBCPP_CXX03_LANG - __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT()); + __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT()); #else __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); #endif // not _LIBCPP_CXX03_LANG - __enable_weak_this(__p, __p); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __d(__p); - throw; - } -#endif // _LIBCPP_HAS_EXCEPTIONS + __enable_weak_this(__p, __p); + __guard.__complete(); } template <class _Yp, @@ -376,28 +370,21 @@ public: class _Alloc, __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) : __ptr_(__p) { -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; - _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new ((void*)std::addressof(*__hold2.get())) + auto __guard = std::__make_exception_guard([&] { __d(__p); }); + typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new ((void*)std::addressof(*__hold2.get())) #ifndef _LIBCPP_CXX03_LANG - _CntrlBlk(__p, std::move(__d), __a); + _CntrlBlk(__p, std::move(__d), __a); #else _CntrlBlk(__p, __d, __a); #endif // not _LIBCPP_CXX03_LANG - __cntrl_ = std::addressof(*__hold2.release()); - __enable_weak_this(__p, __p); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __d(__p); - throw; - } -#endif // _LIBCPP_HAS_EXCEPTIONS + __cntrl_ = std::addressof(*__hold2.release()); + __enable_weak_this(__p, __p); + __guard.__complete(); } template <class _Dp> @@ -406,22 +393,15 @@ public: _Dp __d, __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag()) : __ptr_(nullptr) { -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; - typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk; + auto __guard = std::__make_exception_guard([&] { __d(__p); }); + typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; + typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk; #ifndef _LIBCPP_CXX03_LANG - __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT()); + __cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT()); #else __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); #endif // not _LIBCPP_CXX03_LANG -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __d(__p); - throw; - } -#endif // _LIBCPP_HAS_EXCEPTIONS + __guard.__complete(); } template <class _Dp, class _Alloc> @@ -431,27 +411,20 @@ public: _Alloc __a, __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag()) : __ptr_(nullptr) { -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; - _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new ((void*)std::addressof(*__hold2.get())) + auto __guard = std::__make_exception_guard([&] { __d(__p); }); + typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; + typedef __allocator_destructor<_A2> _D2; + _A2 __a2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new ((void*)std::addressof(*__hold2.get())) #ifndef _LIBCPP_CXX03_LANG - _CntrlBlk(__p, std::move(__d), __a); + _CntrlBlk(__p, std::move(__d), __a); #else _CntrlBlk(__p, __d, __a); #endif // not _LIBCPP_CXX03_LANG - __cntrl_ = std::addressof(*__hold2.release()); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __d(__p); - throw; - } -#endif // _LIBCPP_HAS_EXCEPTIONS + __cntrl_ = std::addressof(*__hold2.release()); + __guard.__complete(); } template <class _Yp> diff --git a/libcxx/include/__memory/uninitialized_algorithms.h b/libcxx/include/__memory/uninitialized_algorithms.h index e802366..34d065d 100644 --- a/libcxx/include/__memory/uninitialized_algorithms.h +++ b/libcxx/include/__memory/uninitialized_algorithms.h @@ -61,17 +61,10 @@ template <class _ValueType, class _InputIterator, class _Sentinel1, class _Forwa inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_copy( _InputIterator __ifirst, _Sentinel1 __ilast, _ForwardIterator __ofirst, _EndPredicate __stop_copying) { _ForwardIterator __idx = __ofirst; -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif - for (; __ifirst != __ilast && !__stop_copying(__idx); ++__ifirst, (void)++__idx) - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__ofirst, __idx); - throw; - } -#endif + auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); }); + for (; __ifirst != __ilast && !__stop_copying(__idx); ++__ifirst, (void)++__idx) + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst); + __guard.__complete(); return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx)); } @@ -91,17 +84,10 @@ template <class _ValueType, class _InputIterator, class _Size, class _ForwardIte inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_copying) { _ForwardIterator __idx = __ofirst; -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif - for (; __n > 0 && !__stop_copying(__idx); ++__ifirst, (void)++__idx, (void)--__n) - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__ofirst, __idx); - throw; - } -#endif + auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); }); + for (; __n > 0 && !__stop_copying(__idx); ++__ifirst, (void)++__idx, (void)--__n) + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst); + __guard.__complete(); return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx)); } @@ -121,17 +107,10 @@ template <class _ValueType, class _ForwardIterator, class _Sentinel, class _Tp> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) { _ForwardIterator __idx = __first; -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif - for (; __idx != __last; ++__idx) - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__first, __idx); - throw; - } -#endif + auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); + for (; __idx != __last; ++__idx) + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x); + __guard.__complete(); return __idx; } @@ -149,17 +128,10 @@ template <class _ValueType, class _ForwardIterator, class _Size, class _Tp> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { _ForwardIterator __idx = __first; -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif - for (; __n > 0; ++__idx, (void)--__n) - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__first, __idx); - throw; - } -#endif + auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); + for (; __n > 0; ++__idx, (void)--__n) + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x); + __guard.__complete(); return __idx; } @@ -178,18 +150,11 @@ uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { template <class _ValueType, class _ForwardIterator, class _Sentinel> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) { - auto __idx = __first; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif - for (; __idx != __last; ++__idx) - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType; -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__first, __idx); - throw; - } -# endif + auto __idx = __first; + auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); + for (; __idx != __last; ++__idx) + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType; + __guard.__complete(); return __idx; } @@ -205,17 +170,10 @@ inline _LIBCPP_HIDE_FROM_ABI void uninitialized_default_construct(_ForwardIterat template <class _ValueType, class _ForwardIterator, class _Size> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { auto __idx = __first; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif - for (; __n > 0; ++__idx, (void)--__n) - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType; -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__first, __idx); - throw; - } -# endif + auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); + for (; __n > 0; ++__idx, (void)--__n) + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType; + __guard.__complete(); return __idx; } @@ -231,18 +189,11 @@ inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_default_construct_n( template <class _ValueType, class _ForwardIterator, class _Sentinel> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) { - auto __idx = __first; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif - for (; __idx != __last; ++__idx) - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__first, __idx); - throw; - } -# endif + auto __idx = __first; + auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); + for (; __idx != __last; ++__idx) + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(); + __guard.__complete(); return __idx; } @@ -258,17 +209,10 @@ inline _LIBCPP_HIDE_FROM_ABI void uninitialized_value_construct(_ForwardIterator template <class _ValueType, class _ForwardIterator, class _Size> inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { auto __idx = __first; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif - for (; __n > 0; ++__idx, (void)--__n) - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__first, __idx); - throw; - } -# endif + auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); }); + for (; __n > 0; ++__idx, (void)--__n) + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(); + __guard.__complete(); return __idx; } @@ -293,19 +237,12 @@ inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitiali _ForwardIterator __ofirst, _EndPredicate __stop_moving, _IterMove __iter_move) { - auto __idx = __ofirst; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif - for (; __ifirst != __ilast && !__stop_moving(__idx); ++__idx, (void)++__ifirst) { - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst)); - } -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__ofirst, __idx); - throw; + auto __idx = __ofirst; + auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); }); + for (; __ifirst != __ilast && !__stop_moving(__idx); ++__idx, (void)++__ifirst) { + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst)); } -# endif + __guard.__complete(); return {std::move(__ifirst), std::move(__idx)}; } @@ -331,18 +268,11 @@ template <class _ValueType, class _IterMove> inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_move_n( _InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_moving, _IterMove __iter_move) { - auto __idx = __ofirst; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif - for (; __n > 0 && !__stop_moving(__idx); ++__idx, (void)++__ifirst, --__n) - ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst)); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - std::__destroy(__ofirst, __idx); - throw; - } -# endif + auto __idx = __ofirst; + auto __guard = std::__make_exception_guard([&] { std::__destroy(__ofirst, __idx); }); + for (; __n > 0 && !__stop_moving(__idx); ++__idx, (void)++__ifirst, --__n) + ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst)); + __guard.__complete(); return {std::move(__ifirst), std::move(__idx)}; } diff --git a/libcxx/include/__utility/scope_guard.h b/libcxx/include/__utility/scope_guard.h index 3972102..db4f0e4 100644 --- a/libcxx/include/__utility/scope_guard.h +++ b/libcxx/include/__utility/scope_guard.h @@ -43,6 +43,8 @@ public: #endif }; +_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__scope_guard); + template <class _Func> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __scope_guard<_Func> __make_scope_guard(_Func __func) { return __scope_guard<_Func>(std::move(__func)); diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h index 7595427..6cb8f2a 100644 --- a/libcxx/include/__vector/vector_bool.h +++ b/libcxx/include/__vector/vector_bool.h @@ -963,21 +963,14 @@ vector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _Inp } vector __v(get_allocator()); if (__first != __last) { -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - __v.__assign_with_sentinel(std::move(__first), std::move(__last)); - difference_type __old_size = static_cast<difference_type>(__old_end - begin()); - difference_type __old_p = __p - begin(); - reserve(__recommend(size() + __v.size())); - __p = begin() + __old_p; - __old_end = begin() + __old_size; -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - erase(__old_end, end()); - throw; - } -#endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { erase(__old_end, end()); }); + __v.__assign_with_sentinel(std::move(__first), std::move(__last)); + difference_type __old_size = static_cast<difference_type>(__old_end - begin()); + difference_type __old_p = __p - begin(); + reserve(__recommend(size() + __v.size())); + __p = begin() + __old_p; + __old_end = begin() + __old_size; + __guard.__complete(); } __p = std::rotate(__p, __old_end, end()); insert(__p, __v.begin(), __v.end()); diff --git a/libcxx/include/deque b/libcxx/include/deque index c8e1025..3e7ee8d85 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -235,6 +235,7 @@ template <class T, class Allocator, class Predicate> # include <__type_traits/is_swappable.h> # include <__type_traits/is_trivially_relocatable.h> # include <__type_traits/type_identity.h> +# include <__utility/exception_guard.h> # include <__utility/forward.h> # include <__utility/move.h> # include <__utility/pair.h> @@ -2135,22 +2136,17 @@ void deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) { size_type __ds = (__nb + __back_capacity) * __block_size - __map_.empty(); __split_buffer<pointer, __pointer_allocator&> __buf( std::max<size_type>(2 * __map_.capacity(), __nb + __map_.size()), 0, __map_.__get_allocator()); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (; __nb > 0; --__nb) { - __buf.emplace_back(__alloc_traits::allocate(__a, __block_size)); - // ASan: this is empty container, we have to poison whole block - __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size)); - } -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { + auto __guard = std::__make_exception_guard([&] { __annotate_delete(); for (__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i) __alloc_traits::deallocate(__a, *__i, __block_size); - throw; + }); + for (; __nb > 0; --__nb) { + __buf.emplace_back(__alloc_traits::allocate(__a, __block_size)); + // ASan: this is empty container, we have to poison whole block + __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size)); } -# endif // _LIBCPP_HAS_EXCEPTIONS + __guard.__complete(); for (; __back_capacity > 0; --__back_capacity) { __buf.emplace_back(__map_.back()); __map_.pop_back(); @@ -2254,22 +2250,17 @@ void deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) { std::max<size_type>(2 * __map_.capacity(), __nb + __map_.size()), __map_.size() - __front_capacity, __map_.__get_allocator()); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (; __nb > 0; --__nb) { - __buf.emplace_back(__alloc_traits::allocate(__a, __block_size)); - // ASan: this is an empty container, we have to poison the whole block - __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size)); - } -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { + auto __guard = std::__make_exception_guard([&] { __annotate_delete(); for (__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i) __alloc_traits::deallocate(__a, *__i, __block_size); - throw; + }); + for (; __nb > 0; --__nb) { + __buf.emplace_back(__alloc_traits::allocate(__a, __block_size)); + // ASan: this is an empty container, we have to poison the whole block + __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size)); } -# endif // _LIBCPP_HAS_EXCEPTIONS + __guard.__complete(); for (; __front_capacity > 0; --__front_capacity) { __buf.emplace_back(__map_.front()); __map_.pop_front(); diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list index 05f22e3..df7da20 100644 --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -235,6 +235,7 @@ template <class T, class Allocator, class Predicate> # include <__type_traits/is_swappable.h> # include <__type_traits/remove_cv.h> # include <__type_traits/type_identity.h> +# include <__utility/exception_guard.h> # include <__utility/forward.h> # include <__utility/move.h> # include <__utility/swap.h> @@ -1180,22 +1181,17 @@ forward_list<_Tp, _Alloc>::__insert_after(const_iterator __p, size_type __n, _Ar if (__n > 0) { __node_pointer __first = this->__create_node(/* next = */ nullptr, std::forward<_Args>(__args)...); __node_pointer __last = __first; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (--__n; __n != 0; --__n, __last = __last->__next_) { - __last->__next_ = this->__create_node(/* next = */ nullptr, std::forward<_Args>(__args)...); - } -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { + auto __guard = std::__make_exception_guard([&] { while (__first != nullptr) { __node_pointer __next = __first->__next_; this->__delete_node(__first); __first = __next; } - throw; + }); + for (--__n; __n != 0; --__n, __last = __last->__next_) { + __last->__next_ = this->__create_node(/* next = */ nullptr, std::forward<_Args>(__args)...); } -# endif // _LIBCPP_HAS_EXCEPTIONS + __guard.__complete(); __last->__next_ = __r->__next_; __r->__next_ = __first; __r = std::__static_fancy_pointer_cast<__begin_node_pointer>(__last); @@ -1220,22 +1216,17 @@ forward_list<_Tp, _Alloc>::__insert_after_with_sentinel(const_iterator __p, _Inp __node_pointer __first = this->__create_node(/* next = */ nullptr, *__f); __node_pointer __last = __first; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_))) { - __last->__next_ = this->__create_node(/* next = */ nullptr, *__f); - } -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { + auto __guard = std::__make_exception_guard([&] { while (__first != nullptr) { __node_pointer __next = __first->__next_; this->__delete_node(__first); __first = __next; } - throw; + }); + for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_))) { + __last->__next_ = this->__create_node(/* next = */ nullptr, *__f); } -# endif // _LIBCPP_HAS_EXCEPTIONS + __guard.__complete(); __last->__next_ = __r->__next_; __r->__next_ = __first; diff --git a/libcxx/include/future b/libcxx/include/future index 3df9dc9..4b7c098 100644 --- a/libcxx/include/future +++ b/libcxx/include/future @@ -403,6 +403,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>; # include <__type_traits/strip_signature.h> # include <__type_traits/underlying_type.h> # include <__utility/auto_cast.h> +# include <__utility/exception_guard.h> # include <__utility/forward.h> # include <__utility/move.h> # include <__utility/swap.h> @@ -1815,16 +1816,9 @@ template <class _Rp, class _Fp> _LIBCPP_HIDE_FROM_ABI future<_Rp> __make_async_assoc_state(_Fp&& __f) { unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count> __h( new __async_assoc_state<_Rp, _Fp>(std::forward<_Fp>(__f))); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif - std::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach(); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __h->__make_ready(); - throw; - } -# endif + auto __guard = std::__make_exception_guard([&] { __h->__make_ready(); }); + std::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach(); + __guard.__complete(); return future<_Rp>(__h.get()); } diff --git a/libcxx/include/list b/libcxx/include/list index 996dbfd..c5c2a85 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -237,6 +237,7 @@ template <class T, class Allocator, class Predicate> # include <__type_traits/is_pointer.h> # include <__type_traits/is_same.h> # include <__type_traits/type_identity.h> +# include <__utility/exception_guard.h> # include <__utility/forward.h> # include <__utility/move.h> # include <__utility/swap.h> @@ -1233,14 +1234,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _ ++__ds; __r = iterator(__node->__as_link()); iterator __e = __r; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (--__n; __n != 0; --__n, (void)++__e, ++__ds) { - __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link(); - } -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { + auto __guard = std::__make_exception_guard([&] { while (true) { __base_pointer __prev = __e.__ptr_->__prev_; __node_pointer __current = __e.__ptr_->__as_node(); @@ -1249,9 +1243,11 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _ break; __e = iterator(__prev); } - throw; + }); + for (--__n; __n != 0; --__n, (void)++__e, ++__ds) { + __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link(); } -# endif // _LIBCPP_HAS_EXCEPTIONS + __guard.__complete(); __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); this->__size_ += __ds; } @@ -1276,14 +1272,7 @@ list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Se ++__ds; __r = iterator(__node->__as_link()); iterator __e = __r; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (++__f; __f != __l; ++__f, (void)++__e, ++__ds) { - __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, *__f)->__as_link(); - } -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { + auto __guard = std::__make_exception_guard([&] { while (true) { __base_pointer __prev = __e.__ptr_->__prev_; __node_pointer __current = __e.__ptr_->__as_node(); @@ -1292,9 +1281,11 @@ list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Se break; __e = iterator(__prev); } - throw; + }); + for (++__f; __f != __l; ++__f, (void)++__e, ++__ds) { + __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, *__f)->__as_link(); } -# endif // _LIBCPP_HAS_EXCEPTIONS + __guard.__complete(); __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); this->__size_ += __ds; } @@ -1452,14 +1443,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n) { ++__ds; iterator __r = iterator(__node->__as_link()); iterator __e = __r; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (--__n; __n != 0; --__n, (void)++__e, ++__ds) { - __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr)->__as_link(); - } -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { + auto __guard = std::__make_exception_guard([&] { while (true) { __base_pointer __prev = __e.__ptr_->__prev_; __node_pointer __current = __e.__ptr_->__as_node(); @@ -1468,9 +1452,11 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n) { break; __e = iterator(__prev); } - throw; + }); + for (--__n; __n != 0; --__n, (void)++__e, ++__ds) { + __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr)->__as_link(); } -# endif // _LIBCPP_HAS_EXCEPTIONS + __guard.__complete(); __link_nodes_at_back(__r.__ptr_, __e.__ptr_); this->__size_ += __ds; } @@ -1488,14 +1474,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n, cons __base_pointer __nl = __node->__as_link(); iterator __r = iterator(__nl); iterator __e = __r; -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (--__n; __n != 0; --__n, (void)++__e, ++__ds) { - __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link(); - } -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { + auto __guard = std::__make_exception_guard([&] { while (true) { __base_pointer __prev = __e.__ptr_->__prev_; __node_pointer __current = __e.__ptr_->__as_node(); @@ -1504,9 +1483,11 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n, cons break; __e = iterator(__prev); } - throw; + }); + for (--__n; __n != 0; --__n, (void)++__e, ++__ds) { + __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link(); } -# endif // _LIBCPP_HAS_EXCEPTIONS + __guard.__complete(); __link_nodes(__base::__end_as_link(), __r.__ptr_, __e.__ptr_); this->__size_ += __ds; } diff --git a/libcxx/include/string b/libcxx/include/string index 363f27a..8f80afbc 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -640,6 +640,7 @@ basic_string<char32_t> operator""s( const char32_t *str, size_t len ); # include <__type_traits/is_trivially_relocatable.h> # include <__type_traits/remove_cvref.h> # include <__utility/default_three_way_comparator.h> +# include <__utility/exception_guard.h> # include <__utility/forward.h> # include <__utility/is_pointer_in_range.h> # include <__utility/move.h> @@ -1311,6 +1312,8 @@ public: # if _LIBCPP_STD_VER >= 23 template <class _Op> _LIBCPP_HIDE_FROM_ABI constexpr void resize_and_overwrite(size_type __n, _Op __op) { + using __result_type = decltype(std::move(__op)(data(), auto(__n))); + static_assert(__integer_like<__result_type>, "Operation return type must be integer-like"); size_type __sz = size(); size_type __cap = capacity(); if (__n > __cap) @@ -2652,17 +2655,10 @@ basic_string<_CharT, _Traits, _Allocator>::__init_with_sentinel(_InputIterator _ __rep_ = __rep(); __annotate_new(0); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (; __first != __last; ++__first) - push_back(*__first); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __reset_internal_buffer(); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([this] { __reset_internal_buffer(); }); + for (; __first != __last; ++__first) + push_back(*__first); + __guard.__complete(); } template <class _CharT, class _Traits, class _Allocator> @@ -2679,17 +2675,10 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init_with_size(_InputIterator __first, _Sentinel __last, size_type __sz) { pointer __p = __init_internal_buffer(__sz); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - auto __end = __copy_non_overlapping_range(std::move(__first), std::move(__last), std::__to_address(__p)); - traits_type::assign(*__end, value_type()); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __reset_internal_buffer(); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([this] { __reset_internal_buffer(); }); + auto __end = __copy_non_overlapping_range(std::move(__first), std::move(__last), std::__to_address(__p)); + traits_type::assign(*__end, value_type()); + __guard.__complete(); } template <class _CharT, class _Traits, class _Allocator> diff --git a/libcxx/include/valarray b/libcxx/include/valarray index 96501ca..215811d 100644 --- a/libcxx/include/valarray +++ b/libcxx/include/valarray @@ -362,6 +362,7 @@ template <class T> unspecified2 end(const valarray<T>& v); # include <__memory/uninitialized_algorithms.h> # include <__type_traits/decay.h> # include <__type_traits/remove_reference.h> +# include <__utility/exception_guard.h> # include <__utility/move.h> # include <__utility/swap.h> # include <cmath> @@ -1992,17 +1993,10 @@ template <class _Tp> inline valarray<_Tp>::valarray(size_t __n) : __begin_(nullptr), __end_(nullptr) { if (__n) { __begin_ = __end_ = allocator<value_type>().allocate(__n); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) - ::new ((void*)__end_) value_type(); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __clear(__n); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { __clear(__n); }); + for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) + ::new ((void*)__end_) value_type(); + __guard.__complete(); } } @@ -2015,17 +2009,10 @@ template <class _Tp> valarray<_Tp>::valarray(const value_type* __p, size_t __n) : __begin_(nullptr), __end_(nullptr) { if (__n) { __begin_ = __end_ = allocator<value_type>().allocate(__n); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left) - ::new ((void*)__end_) value_type(*__p); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __clear(__n); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { __clear(__n); }); + for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left) + ::new ((void*)__end_) value_type(*__p); + __guard.__complete(); } } @@ -2033,17 +2020,10 @@ template <class _Tp> valarray<_Tp>::valarray(const valarray& __v) : __begin_(nullptr), __end_(nullptr) { if (__v.size()) { __begin_ = __end_ = allocator<value_type>().allocate(__v.size()); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p) - ::new ((void*)__end_) value_type(*__p); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __clear(__v.size()); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { __clear(__v.size()); }); + for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p) + ::new ((void*)__end_) value_type(*__p); + __guard.__complete(); } } @@ -2059,18 +2039,11 @@ valarray<_Tp>::valarray(initializer_list<value_type> __il) : __begin_(nullptr), const size_t __n = __il.size(); if (__n) { __begin_ = __end_ = allocator<value_type>().allocate(__n); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - size_t __n_left = __n; - for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left) - ::new ((void*)__end_) value_type(*__p); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __clear(__n); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { __clear(__n); }); + size_t __n_left = __n; + for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left) + ::new ((void*)__end_) value_type(*__p); + __guard.__complete(); } } @@ -2081,18 +2054,11 @@ valarray<_Tp>::valarray(const slice_array<value_type>& __sa) : __begin_(nullptr) const size_t __n = __sa.__size_; if (__n) { __begin_ = __end_ = allocator<value_type>().allocate(__n); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - size_t __n_left = __n; - for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left) - ::new ((void*)__end_) value_type(*__p); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __clear(__n); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { __clear(__n); }); + size_t __n_left = __n; + for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left) + ::new ((void*)__end_) value_type(*__p); + __guard.__complete(); } } @@ -2101,19 +2067,12 @@ valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) : __begin_(nullptr const size_t __n = __ga.__1d_.size(); if (__n) { __begin_ = __end_ = allocator<value_type>().allocate(__n); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - typedef const size_t* _Ip; - const value_type* __s = __ga.__vp_; - for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_) - ::new ((void*)__end_) value_type(__s[*__i]); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __clear(__n); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { __clear(__n); }); + typedef const size_t* _Ip; + const value_type* __s = __ga.__vp_; + for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_) + ::new ((void*)__end_) value_type(__s[*__i]); + __guard.__complete(); } } @@ -2122,19 +2081,12 @@ valarray<_Tp>::valarray(const mask_array<value_type>& __ma) : __begin_(nullptr), const size_t __n = __ma.__1d_.size(); if (__n) { __begin_ = __end_ = allocator<value_type>().allocate(__n); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - typedef const size_t* _Ip; - const value_type* __s = __ma.__vp_; - for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_) - ::new ((void*)__end_) value_type(__s[*__i]); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __clear(__n); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { __clear(__n); }); + typedef const size_t* _Ip; + const value_type* __s = __ma.__vp_; + for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_) + ::new ((void*)__end_) value_type(__s[*__i]); + __guard.__complete(); } } @@ -2143,19 +2095,12 @@ valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) : __begin_(nullp const size_t __n = __ia.__1d_.size(); if (__n) { __begin_ = __end_ = allocator<value_type>().allocate(__n); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - typedef const size_t* _Ip; - const value_type* __s = __ia.__vp_; - for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_) - ::new ((void*)__end_) value_type(__s[*__i]); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __clear(__n); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { __clear(__n); }); + typedef const size_t* _Ip; + const value_type* __s = __ia.__vp_; + for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_) + ::new ((void*)__end_) value_type(__s[*__i]); + __guard.__complete(); } } @@ -2644,17 +2589,10 @@ void valarray<_Tp>::resize(size_t __n, value_type __x) { __clear(size()); if (__n) { __begin_ = __end_ = allocator<value_type>().allocate(__n); -# if _LIBCPP_HAS_EXCEPTIONS - try { -# endif // _LIBCPP_HAS_EXCEPTIONS - for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) - ::new ((void*)__end_) value_type(__x); -# if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - __clear(__n); - throw; - } -# endif // _LIBCPP_HAS_EXCEPTIONS + auto __guard = std::__make_exception_guard([&] { __clear(__n); }); + for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) + ::new ((void*)__end_) value_type(__x); + __guard.__complete(); } } diff --git a/libcxx/src/filesystem/error.h b/libcxx/src/filesystem/error.h index 52a18b2..db5d1ae 100644 --- a/libcxx/src/filesystem/error.h +++ b/libcxx/src/filesystem/error.h @@ -128,17 +128,8 @@ struct ErrorHandler { T report(const error_code& ec, const char* msg, ...) const { va_list ap; va_start(ap, msg); -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - report_impl(ec, msg, ap); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - va_end(ap); - throw; - } -#endif // _LIBCPP_HAS_EXCEPTIONS - va_end(ap); + __scope_guard guard([&] { va_end(ap); }); + report_impl(ec, msg, ap); return error_value<T>(); } @@ -148,17 +139,8 @@ struct ErrorHandler { T report(errc const& err, const char* msg, ...) const { va_list ap; va_start(ap, msg); -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - report_impl(make_error_code(err), msg, ap); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - va_end(ap); - throw; - } -#endif // _LIBCPP_HAS_EXCEPTIONS - va_end(ap); + __scope_guard guard([&] { va_end(ap); }); + report_impl(make_error_code(err), msg, ap); return error_value<T>(); } diff --git a/libcxx/src/filesystem/format_string.h b/libcxx/src/filesystem/format_string.h index e91475e..8d17b02 100644 --- a/libcxx/src/filesystem/format_string.h +++ b/libcxx/src/filesystem/format_string.h @@ -11,6 +11,7 @@ #include <__assert> #include <__config> +#include <__utility/scope_guard.h> #include <array> #include <cstdarg> #include <cstddef> @@ -55,17 +56,8 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) string format_string(const cha string ret; va_list ap; va_start(ap, msg); -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - ret = detail::vformat_string(msg, ap); -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - va_end(ap); - throw; - } -#endif // _LIBCPP_HAS_EXCEPTIONS - va_end(ap); + __scope_guard guard([&] { va_end(ap); }); + ret = detail::vformat_string(msg, ap); return ret; } diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp index da73586..0f695d4 100644 --- a/libcxx/src/locale.cpp +++ b/libcxx/src/locale.cpp @@ -215,63 +215,58 @@ locale::__imp::__imp(size_t refs) : facet(refs), facets_(N), name_("C") { } locale::__imp::__imp(const string& name, size_t refs) : facet(refs), facets_(N), name_(name) { -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - facets_ = locale::classic().__locale_->facets_; + __exception_guard guard([&] { for (unsigned i = 0; i < facets_.size(); ++i) if (facets_[i]) - facets_[i]->__add_shared(); - install(new collate_byname<char>(name_)); + facets_[i]->__release_shared(); + }); + facets_ = locale::classic().__locale_->facets_; + for (unsigned i = 0; i < facets_.size(); ++i) + if (facets_[i]) + facets_[i]->__add_shared(); + install(new collate_byname<char>(name_)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new collate_byname<wchar_t>(name_)); + install(new collate_byname<wchar_t>(name_)); #endif - install(new ctype_byname<char>(name_)); + install(new ctype_byname<char>(name_)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new ctype_byname<wchar_t>(name_)); + install(new ctype_byname<wchar_t>(name_)); #endif - install(new codecvt_byname<char, char, mbstate_t>(name_)); + install(new codecvt_byname<char, char, mbstate_t>(name_)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new codecvt_byname<wchar_t, char, mbstate_t>(name_)); + install(new codecvt_byname<wchar_t, char, mbstate_t>(name_)); #endif - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - install(new codecvt_byname<char16_t, char, mbstate_t>(name_)); - install(new codecvt_byname<char32_t, char, mbstate_t>(name_)); - _LIBCPP_SUPPRESS_DEPRECATED_POP + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + install(new codecvt_byname<char16_t, char, mbstate_t>(name_)); + install(new codecvt_byname<char32_t, char, mbstate_t>(name_)); + _LIBCPP_SUPPRESS_DEPRECATED_POP #if _LIBCPP_HAS_CHAR8_T - install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name_)); - install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name_)); + install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name_)); + install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name_)); #endif - install(new numpunct_byname<char>(name_)); + install(new numpunct_byname<char>(name_)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new numpunct_byname<wchar_t>(name_)); + install(new numpunct_byname<wchar_t>(name_)); #endif - install(new moneypunct_byname<char, false>(name_)); - install(new moneypunct_byname<char, true>(name_)); + install(new moneypunct_byname<char, false>(name_)); + install(new moneypunct_byname<char, true>(name_)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new moneypunct_byname<wchar_t, false>(name_)); - install(new moneypunct_byname<wchar_t, true>(name_)); + install(new moneypunct_byname<wchar_t, false>(name_)); + install(new moneypunct_byname<wchar_t, true>(name_)); #endif - install(new time_get_byname<char>(name_)); + install(new time_get_byname<char>(name_)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new time_get_byname<wchar_t>(name_)); + install(new time_get_byname<wchar_t>(name_)); #endif - install(new time_put_byname<char>(name_)); + install(new time_put_byname<char>(name_)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new time_put_byname<wchar_t>(name_)); + install(new time_put_byname<wchar_t>(name_)); #endif - install(new messages_byname<char>(name_)); + install(new messages_byname<char>(name_)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new messages_byname<wchar_t>(name_)); + install(new messages_byname<wchar_t>(name_)); #endif -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - for (unsigned i = 0; i < facets_.size(); ++i) - if (facets_[i]) - facets_[i]->__release_shared(); - throw; - } -#endif // _LIBCPP_HAS_EXCEPTIONS + guard.__complete(); } locale::__imp::__imp(const __imp& other) : facets_(max<size_t>(N, other.facets_.size())), name_(other.name_) { @@ -287,71 +282,66 @@ locale::__imp::__imp(const __imp& other, const string& name, locale::category c) for (unsigned i = 0; i < facets_.size(); ++i) if (facets_[i]) facets_[i]->__add_shared(); -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - if (c & locale::collate) { - install(new collate_byname<char>(name)); + __exception_guard guard([&] { + for (unsigned i = 0; i < facets_.size(); ++i) + if (facets_[i]) + facets_[i]->__release_shared(); + }); + if (c & locale::collate) { + install(new collate_byname<char>(name)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new collate_byname<wchar_t>(name)); + install(new collate_byname<wchar_t>(name)); #endif - } - if (c & locale::ctype) { - install(new ctype_byname<char>(name)); + } + if (c & locale::ctype) { + install(new ctype_byname<char>(name)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new ctype_byname<wchar_t>(name)); + install(new ctype_byname<wchar_t>(name)); #endif - install(new codecvt_byname<char, char, mbstate_t>(name)); + install(new codecvt_byname<char, char, mbstate_t>(name)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new codecvt_byname<wchar_t, char, mbstate_t>(name)); + install(new codecvt_byname<wchar_t, char, mbstate_t>(name)); #endif - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - install(new codecvt_byname<char16_t, char, mbstate_t>(name)); - install(new codecvt_byname<char32_t, char, mbstate_t>(name)); - _LIBCPP_SUPPRESS_DEPRECATED_POP + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + install(new codecvt_byname<char16_t, char, mbstate_t>(name)); + install(new codecvt_byname<char32_t, char, mbstate_t>(name)); + _LIBCPP_SUPPRESS_DEPRECATED_POP #if _LIBCPP_HAS_CHAR8_T - install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name)); - install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name)); + install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name)); + install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name)); #endif - } - if (c & locale::monetary) { - install(new moneypunct_byname<char, false>(name)); - install(new moneypunct_byname<char, true>(name)); + } + if (c & locale::monetary) { + install(new moneypunct_byname<char, false>(name)); + install(new moneypunct_byname<char, true>(name)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new moneypunct_byname<wchar_t, false>(name)); - install(new moneypunct_byname<wchar_t, true>(name)); + install(new moneypunct_byname<wchar_t, false>(name)); + install(new moneypunct_byname<wchar_t, true>(name)); #endif - } - if (c & locale::numeric) { - install(new numpunct_byname<char>(name)); + } + if (c & locale::numeric) { + install(new numpunct_byname<char>(name)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new numpunct_byname<wchar_t>(name)); + install(new numpunct_byname<wchar_t>(name)); #endif - } - if (c & locale::time) { - install(new time_get_byname<char>(name)); + } + if (c & locale::time) { + install(new time_get_byname<char>(name)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new time_get_byname<wchar_t>(name)); + install(new time_get_byname<wchar_t>(name)); #endif - install(new time_put_byname<char>(name)); + install(new time_put_byname<char>(name)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new time_put_byname<wchar_t>(name)); + install(new time_put_byname<wchar_t>(name)); #endif - } - if (c & locale::messages) { - install(new messages_byname<char>(name)); + } + if (c & locale::messages) { + install(new messages_byname<char>(name)); #if _LIBCPP_HAS_WIDE_CHARACTERS - install(new messages_byname<wchar_t>(name)); + install(new messages_byname<wchar_t>(name)); #endif - } -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - for (unsigned i = 0; i < facets_.size(); ++i) - if (facets_[i]) - facets_[i]->__release_shared(); - throw; } -#endif // _LIBCPP_HAS_EXCEPTIONS + guard.__complete(); } template <class F> @@ -366,87 +356,83 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c) for (unsigned i = 0; i < facets_.size(); ++i) if (facets_[i]) facets_[i]->__add_shared(); -#if _LIBCPP_HAS_EXCEPTIONS - try { -#endif // _LIBCPP_HAS_EXCEPTIONS - if (c & locale::collate) { - install_from<std::collate<char> >(one); + __exception_guard guard([&] { + for (unsigned i = 0; i < facets_.size(); ++i) + if (facets_[i]) + facets_[i]->__release_shared(); + }); + + if (c & locale::collate) { + install_from<std::collate<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<std::collate<wchar_t> >(one); + install_from<std::collate<wchar_t> >(one); #endif - } - if (c & locale::ctype) { - install_from<std::ctype<char> >(one); + } + if (c & locale::ctype) { + install_from<std::ctype<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<std::ctype<wchar_t> >(one); + install_from<std::ctype<wchar_t> >(one); #endif - install_from<std::codecvt<char, char, mbstate_t> >(one); - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - install_from<std::codecvt<char16_t, char, mbstate_t> >(one); - install_from<std::codecvt<char32_t, char, mbstate_t> >(one); - _LIBCPP_SUPPRESS_DEPRECATED_POP + install_from<std::codecvt<char, char, mbstate_t> >(one); + _LIBCPP_SUPPRESS_DEPRECATED_PUSH + install_from<std::codecvt<char16_t, char, mbstate_t> >(one); + install_from<std::codecvt<char32_t, char, mbstate_t> >(one); + _LIBCPP_SUPPRESS_DEPRECATED_POP #if _LIBCPP_HAS_CHAR8_T - install_from<std::codecvt<char16_t, char8_t, mbstate_t> >(one); - install_from<std::codecvt<char32_t, char8_t, mbstate_t> >(one); + install_from<std::codecvt<char16_t, char8_t, mbstate_t> >(one); + install_from<std::codecvt<char32_t, char8_t, mbstate_t> >(one); #endif #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<std::codecvt<wchar_t, char, mbstate_t> >(one); + install_from<std::codecvt<wchar_t, char, mbstate_t> >(one); #endif - } - if (c & locale::monetary) { - install_from<moneypunct<char, false> >(one); - install_from<moneypunct<char, true> >(one); + } + if (c & locale::monetary) { + install_from<moneypunct<char, false> >(one); + install_from<moneypunct<char, true> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<moneypunct<wchar_t, false> >(one); - install_from<moneypunct<wchar_t, true> >(one); + install_from<moneypunct<wchar_t, false> >(one); + install_from<moneypunct<wchar_t, true> >(one); #endif - install_from<money_get<char> >(one); + install_from<money_get<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<money_get<wchar_t> >(one); + install_from<money_get<wchar_t> >(one); #endif - install_from<money_put<char> >(one); + install_from<money_put<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<money_put<wchar_t> >(one); + install_from<money_put<wchar_t> >(one); #endif - } - if (c & locale::numeric) { - install_from<numpunct<char> >(one); + } + if (c & locale::numeric) { + install_from<numpunct<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<numpunct<wchar_t> >(one); + install_from<numpunct<wchar_t> >(one); #endif - install_from<num_get<char> >(one); + install_from<num_get<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<num_get<wchar_t> >(one); + install_from<num_get<wchar_t> >(one); #endif - install_from<num_put<char> >(one); + install_from<num_put<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<num_put<wchar_t> >(one); + install_from<num_put<wchar_t> >(one); #endif - } - if (c & locale::time) { - install_from<time_get<char> >(one); + } + if (c & locale::time) { + install_from<time_get<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<time_get<wchar_t> >(one); + install_from<time_get<wchar_t> >(one); #endif - install_from<time_put<char> >(one); + install_from<time_put<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<time_put<wchar_t> >(one); + install_from<time_put<wchar_t> >(one); #endif - } - if (c & locale::messages) { - install_from<std::messages<char> >(one); + } + if (c & locale::messages) { + install_from<std::messages<char> >(one); #if _LIBCPP_HAS_WIDE_CHARACTERS - install_from<std::messages<wchar_t> >(one); + install_from<std::messages<wchar_t> >(one); #endif - } -#if _LIBCPP_HAS_EXCEPTIONS - } catch (...) { - for (unsigned i = 0; i < facets_.size(); ++i) - if (facets_[i]) - facets_[i]->__release_shared(); - throw; } -#endif // _LIBCPP_HAS_EXCEPTIONS + guard.__complete(); } locale::__imp::__imp(const __imp& other, facet* f, long id) diff --git a/libcxx/test/benchmarks/spec.gen.py b/libcxx/test/benchmarks/spec.gen.py index c36dd0a..f355b2c 100644 --- a/libcxx/test/benchmarks/spec.gen.py +++ b/libcxx/test/benchmarks/spec.gen.py @@ -8,13 +8,13 @@ # REQUIRES: enable-spec-benchmarks -# RUN: mkdir -p %T -# RUN: echo "%{cxx}" > %T/cxx.subs -# RUN: echo "%{compile_flags}" > %T/compile_flags.subs -# RUN: echo "%{flags}" > %T/flags.subs -# RUN: echo "%{link_flags}" > %T/link_flags.subs -# RUN: echo "%{spec_dir}" > %T/spec_dir.subs -# RUN: %{python} %s %T +# RUN: mkdir -p %{temp} +# RUN: echo "%{cxx}" > %{temp}/cxx.subs +# RUN: echo "%{compile_flags}" > %{temp}/compile_flags.subs +# RUN: echo "%{flags}" > %{temp}/flags.subs +# RUN: echo "%{link_flags}" > %{temp}/link_flags.subs +# RUN: echo "%{spec_dir}" > %{temp}/spec_dir.subs +# RUN: %{python} %s %{temp} # END. import json @@ -66,18 +66,18 @@ spec_benchmarks &= no_fortran for benchmark in spec_benchmarks: print(f'#--- {benchmark}.sh.test') - print(f'RUN: rm -rf %T') # clean up any previous (potentially incomplete) run - print(f'RUN: mkdir %T') - print(f'RUN: cp {spec_config} %T/spec-config.cfg') - print(f'RUN: %{{spec_dir}}/bin/runcpu --config %T/spec-config.cfg --size train --output-root %T --rebuild {benchmark}') - print(f'RUN: rm -rf %T/benchspec') # remove the temporary directory, which can become quite large + print(f'RUN: rm -rf %{{temp}}') # clean up any previous (potentially incomplete) run + print(f'RUN: mkdir %{{temp}}') + print(f'RUN: cp {spec_config} %{{temp}}/spec-config.cfg') + print(f'RUN: %{{spec_dir}}/bin/runcpu --config %{{temp}}/spec-config.cfg --size train --output-root %{{temp}} --rebuild {benchmark}') + print(f'RUN: rm -rf %{{temp}}/benchspec') # remove the temporary directory, which can become quite large # The `runcpu` command above doesn't fail even if the benchmark fails to run. To determine failure, parse the CSV # results and ensure there are no compilation errors or runtime errors in the status row. Also print the logs and # fail if there are no CSV files at all, which implies a SPEC error. - print(f'RUN: %{{libcxx-dir}}/utils/parse-spec-results --extract "Base Status" --keep-failed %T/result/*.train.csv > %T/status || ! cat %T/result/*.log') - print(f'RUN: ! grep -E "CE|RE" %T/status || ! cat %T/result/*.log') + print(f'RUN: %{{libcxx-dir}}/utils/parse-spec-results --extract "Base Status" --keep-failed %{{temp}}/result/*.train.csv > %{{temp}}/status || ! cat %{{temp}}/result/*.log') + print(f'RUN: ! grep -E "CE|RE" %{{temp}}/status || ! cat %{{temp}}/result/*.log') # If there were no errors, parse the results into LNT-compatible format and print them. - print(f'RUN: %{{libcxx-dir}}/utils/parse-spec-results %T/result/*.train.csv --output-format=lnt > %T/results.lnt') - print(f'RUN: cat %T/results.lnt') + print(f'RUN: %{{libcxx-dir}}/utils/parse-spec-results %{{temp}}/result/*.train.csv --output-format=lnt > %{{temp}}/results.lnt') + print(f'RUN: cat %{{temp}}/results.lnt') diff --git a/libcxx/test/configs/apple-libc++-shared.cfg.in b/libcxx/test/configs/apple-libc++-shared.cfg.in index 5504bfd..a361b2b 100644 --- a/libcxx/test/configs/apple-libc++-shared.cfg.in +++ b/libcxx/test/configs/apple-libc++-shared.cfg.in @@ -38,7 +38,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib++ -L %{lib-dir} -lc++ %{apple-system-shims}' )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T --env DYLD_LIBRARY_PATH=%{lib-dir} -- ' + '%{executor} --execdir %{temp} --env DYLD_LIBRARY_PATH=%{lib-dir} -- ' )) config.stdlib = 'apple-libc++' diff --git a/libcxx/test/configs/apple-libc++-system.cfg.in b/libcxx/test/configs/apple-libc++-system.cfg.in index b59506f..e87f920 100644 --- a/libcxx/test/configs/apple-libc++-system.cfg.in +++ b/libcxx/test/configs/apple-libc++-system.cfg.in @@ -19,7 +19,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib++ -L %{lib-dir} -lc++' )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T -- ' + '%{executor} --execdir %{temp} -- ' )) config.stdlib = 'apple-libc++' diff --git a/libcxx/test/configs/armv7m-picolibc-libc++.cfg.in b/libcxx/test/configs/armv7m-picolibc-libc++.cfg.in index b2669a7..f0782c2 100644 --- a/libcxx/test/configs/armv7m-picolibc-libc++.cfg.in +++ b/libcxx/test/configs/armv7m-picolibc-libc++.cfg.in @@ -30,7 +30,7 @@ config.executor = ( ' --cpu cortex-m3') config.substitutions.append(('%{exec}', '%{executor}' - ' --execdir %T' + ' --execdir %{temp}' )) import os, site diff --git a/libcxx/test/configs/ibm-libc++-shared.cfg.in b/libcxx/test/configs/ibm-libc++-shared.cfg.in index 0f86e74..c24c729 100644 --- a/libcxx/test/configs/ibm-libc++-shared.cfg.in +++ b/libcxx/test/configs/ibm-libc++-shared.cfg.in @@ -18,7 +18,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib++ -L %{lib-dir} -lc++ -lc++abi -latomic -Wl,-bbigtoc' )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T --env LIBPATH=%{lib-dir} -- ' + '%{executor} --execdir %{temp} --env LIBPATH=%{lib-dir} -- ' )) # LIBCXX-AIX-FIXME is the feature name used to XFAIL the diff --git a/libcxx/test/configs/llvm-libc++-android.cfg.in b/libcxx/test/configs/llvm-libc++-android.cfg.in index 9362c68..96c952d 100644 --- a/libcxx/test/configs/llvm-libc++-android.cfg.in +++ b/libcxx/test/configs/llvm-libc++-android.cfg.in @@ -36,7 +36,7 @@ config.substitutions.append(('%{link_flags}', config.substitutions.append(('%{exec}', '%{executor}' + ' --job-limit-socket ' + libcxx.test.android.adb_job_limit_socket() + - ' --prepend-path-env LD_LIBRARY_PATH /data/local/tmp/libc++ --execdir %T -- ' + ' --prepend-path-env LD_LIBRARY_PATH /data/local/tmp/libc++ --execdir %{temp} -- ' )) libcxx.test.config.configure( diff --git a/libcxx/test/configs/llvm-libc++-mingw.cfg.in b/libcxx/test/configs/llvm-libc++-mingw.cfg.in index 01c4d58..4473171 100644 --- a/libcxx/test/configs/llvm-libc++-mingw.cfg.in +++ b/libcxx/test/configs/llvm-libc++-mingw.cfg.in @@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib++ -L %{lib-dir} -lc++' )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T --prepend_env PATH=%{install-prefix}/bin -- ' + '%{executor} --execdir %{temp} --prepend_env PATH=%{install-prefix}/bin -- ' )) import os, site diff --git a/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in index 5fa99bc..e6186a7 100644 --- a/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in +++ b/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in @@ -25,7 +25,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib -L %{lib-dir} -lc++ -l' + cxx_lib )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T --prepend_env PATH=%{install-prefix}/bin -- ' + '%{executor} --execdir %{temp} --prepend_env PATH=%{install-prefix}/bin -- ' )) import os, site diff --git a/libcxx/test/configs/llvm-libc++-shared-gcc.cfg.in b/libcxx/test/configs/llvm-libc++-shared-gcc.cfg.in index 649bd31..1b4ddc2 100644 --- a/libcxx/test/configs/llvm-libc++-shared-gcc.cfg.in +++ b/libcxx/test/configs/llvm-libc++-shared-gcc.cfg.in @@ -12,7 +12,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib++ -L %{lib-dir} -Wl,-rpath,%{lib-dir} -lc++ -lm' )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T -- ' + '%{executor} --execdir %{temp} -- ' )) import os, site diff --git a/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in index e95999d..476c5ca 100644 --- a/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in +++ b/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in @@ -26,7 +26,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib -L %{lib-dir} -lc++ -l' + cxx_lib )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T --prepend_env PATH=%{install-prefix}/bin -- ' + '%{executor} --execdir %{temp} --prepend_env PATH=%{install-prefix}/bin -- ' )) import os, site diff --git a/libcxx/test/configs/llvm-libc++-shared.cfg.in b/libcxx/test/configs/llvm-libc++-shared.cfg.in index 0c059f0..6d4a383 100644 --- a/libcxx/test/configs/llvm-libc++-shared.cfg.in +++ b/libcxx/test/configs/llvm-libc++-shared.cfg.in @@ -13,7 +13,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib++ -L %{lib-dir} -Wl,-rpath,%{lib-dir} -lc++' )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T -- ' + '%{executor} --execdir %{temp} -- ' )) import os, site diff --git a/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in index 4b6b3fc..2f2b420 100644 --- a/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in +++ b/libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in @@ -25,7 +25,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib -L %{lib-dir} -llibc++ -l' + cxx_lib )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T -- ' + '%{executor} --execdir %{temp} -- ' )) import os, site diff --git a/libcxx/test/configs/llvm-libc++-static.cfg.in b/libcxx/test/configs/llvm-libc++-static.cfg.in index 097cc4d..45a44c1 100644 --- a/libcxx/test/configs/llvm-libc++-static.cfg.in +++ b/libcxx/test/configs/llvm-libc++-static.cfg.in @@ -13,7 +13,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib++ -L %{lib-dir} -lc++ -lc++abi' )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T -- ' + '%{executor} --execdir %{temp} -- ' )) import os, site diff --git a/libcxx/test/configs/stdlib-libstdc++.cfg.in b/libcxx/test/configs/stdlib-libstdc++.cfg.in index 3ff0c54..1a4b47c 100644 --- a/libcxx/test/configs/stdlib-libstdc++.cfg.in +++ b/libcxx/test/configs/stdlib-libstdc++.cfg.in @@ -51,7 +51,7 @@ config.substitutions.append(('%{link_flags}', '-nostdlib++ -L %{libstdcxx-install-prefix}/lib/gcc/%{libstdcxx-version} -Wl,-rpath,%{libstdcxx-install-prefix}/lib/gcc/%{libstdcxx-version} -lstdc++' )) config.substitutions.append(('%{exec}', - '%{executor} --execdir %T -- ' + '%{executor} --execdir %{temp} -- ' )) import os, site diff --git a/libcxx/test/configs/stdlib-native.cfg.in b/libcxx/test/configs/stdlib-native.cfg.in index 3e25c1e..b827155f 100644 --- a/libcxx/test/configs/stdlib-native.cfg.in +++ b/libcxx/test/configs/stdlib-native.cfg.in @@ -11,7 +11,7 @@ config.substitutions.append(('%{flags}', )) config.substitutions.append(('%{compile_flags}', '-I %{libcxx-dir}/test/support')) config.substitutions.append(('%{link_flags}', '')) -config.substitutions.append(('%{exec}', '%{executor} --execdir %T -- ')) +config.substitutions.append(('%{exec}', '%{executor} --execdir %{temp} -- ')) import os, site site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils')) diff --git a/libcxx/test/selftest/dsl/dsl.sh.py b/libcxx/test/selftest/dsl/dsl.sh.py index 6d4406b..93f351f 100644 --- a/libcxx/test/selftest/dsl/dsl.sh.py +++ b/libcxx/test/selftest/dsl/dsl.sh.py @@ -12,7 +12,7 @@ # Note: We prepend arguments with 'x' to avoid thinking there are too few # arguments in case an argument is an empty string. -# RUN: %{python} %s x%S x%T x%{substitutions} +# RUN: %{python} %s x%S x%{temp} x%{substitutions} import base64 import copy diff --git a/libcxx/test/selftest/dsl/lit.local.cfg b/libcxx/test/selftest/dsl/lit.local.cfg index 352719b..dc6887a 100644 --- a/libcxx/test/selftest/dsl/lit.local.cfg +++ b/libcxx/test/selftest/dsl/lit.local.cfg @@ -1,8 +1,8 @@ # Since we try to pass substitutions as-is to some tests, we must "escape" # them in case they contain other substitutions. Otherwise, the substitutions # will be fully expanded when passed to the tests. For example, we want an -# %{exec} substitution that contains `--execdir %T` to be passed as-is, without -# substituting the directory. This way, the test itself can populate %T as it +# %{exec} substitution that contains `--execdir %{temp}` to be passed as-is, without +# substituting the directory. This way, the test itself can populate %{temp} as it # sees fit, and %{exec} will respect it. # # To solve this problem, we pickle the substitutions and base64 encode that diff --git a/libcxx/test/selftest/file_dependencies/absolute-and-relative-paths.sh.cpp b/libcxx/test/selftest/file_dependencies/absolute-and-relative-paths.sh.cpp index ac52f67..68283f6 100644 --- a/libcxx/test/selftest/file_dependencies/absolute-and-relative-paths.sh.cpp +++ b/libcxx/test/selftest/file_dependencies/absolute-and-relative-paths.sh.cpp @@ -9,7 +9,7 @@ // Make sure that FILE_DEPENDENCIES work with relative AND absolute paths. // FILE_DEPENDENCIES: %S/a.txt -// RUN: test -e %T/a.txt +// RUN: test -e %{temp}/a.txt // FILE_DEPENDENCIES: dir/b.txt -// RUN: test -e %T/b.txt +// RUN: test -e %{temp}/b.txt diff --git a/libcxx/test/selftest/file_dependencies/substitute-in-dependencies.sh.cpp b/libcxx/test/selftest/file_dependencies/substitute-in-dependencies.sh.cpp index c63684c..59de718 100644 --- a/libcxx/test/selftest/file_dependencies/substitute-in-dependencies.sh.cpp +++ b/libcxx/test/selftest/file_dependencies/substitute-in-dependencies.sh.cpp @@ -9,4 +9,4 @@ // Make sure that lit substitutions are expanded inside FILE_DEPENDENCIES lines. // FILE_DEPENDENCIES: %s -// RUN: test -e %T/substitute-in-dependencies.sh.cpp +// RUN: test -e %{temp}/substitute-in-dependencies.sh.cpp diff --git a/libcxx/test/selftest/tmpdir-exists.sh.cpp b/libcxx/test/selftest/tmpdir-exists.sh.cpp index 7f9e69d..4edd165 100644 --- a/libcxx/test/selftest/tmpdir-exists.sh.cpp +++ b/libcxx/test/selftest/tmpdir-exists.sh.cpp @@ -6,6 +6,6 @@ // //===----------------------------------------------------------------------===// -// Make sure that the directory represented by %T exists when we run the test. +// Make sure that the directory represented by %{temp} exists when we run the test. -// RUN: test -d %T +// RUN: test -d %{temp} diff --git a/libcxx/test/std/localization/codecvt_unicode.pass.cpp b/libcxx/test/std/localization/codecvt_unicode.pass.cpp index fc5625d..523c316 100644 --- a/libcxx/test/std/localization/codecvt_unicode.pass.cpp +++ b/libcxx/test/std/localization/codecvt_unicode.pass.cpp @@ -2222,10 +2222,11 @@ void test_utf16_ucs2_codecvts() { #endif } -int main() { +int main(int, char**) { test_utf8_utf32_codecvts(); test_utf8_utf16_codecvts(); test_utf8_ucs2_codecvts(); test_utf16_utf32_codecvts(); test_utf16_ucs2_codecvts(); + return 0; } diff --git a/libcxx/test/std/ranges/range.access/include.iterator.pass.cpp b/libcxx/test/std/ranges/range.access/include.iterator.pass.cpp index bb2cda0..947eb17 100644 --- a/libcxx/test/std/ranges/range.access/include.iterator.pass.cpp +++ b/libcxx/test/std/ranges/range.access/include.iterator.pass.cpp @@ -62,7 +62,8 @@ constexpr bool test() { return true; } -int main() { +int main(int, char**) { test(); static_assert(test()); + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp index abd2848..e5c1963 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp @@ -21,6 +21,7 @@ #include "make_string.h" #include "test_macros.h" #include "asan_testing.h" +#include "type_algorithms.h" template <class S> constexpr void test_appending(std::size_t k, size_t N, size_t new_capacity) { @@ -77,17 +78,30 @@ constexpr bool test() { return true; } -void test_value_categories() { +constexpr bool test_value_categories() { std::string s; s.resize_and_overwrite(10, [](char*&&, std::size_t&&) { return 0; }); LIBCPP_ASSERT(is_string_asan_correct(s)); s.resize_and_overwrite(10, [](char* const&, const std::size_t&) { return 0; }); LIBCPP_ASSERT(is_string_asan_correct(s)); struct RefQualified { - int operator()(char*, std::size_t) && { return 0; } + constexpr int operator()(char*, std::size_t) && { return 0; } }; s.resize_and_overwrite(10, RefQualified{}); LIBCPP_ASSERT(is_string_asan_correct(s)); + return true; +} + +constexpr bool test_integer_like_return_types() { + types::for_each(types::integer_types(), []<typename IntegerType> { + std::string s; + s.resize_and_overwrite(10, [](char* p, std::size_t n) -> IntegerType { + std::fill(p, p + n, 'f'); + return n; + }); + assert(s.size() == 10); + }); + return true; } int main(int, char**) { @@ -105,5 +119,12 @@ int main(int, char**) { test<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>>(); static_assert(test<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>>()); #endif + + test_value_categories(); + test_integer_like_return_types(); + + static_assert(test_value_categories()); + static_assert(test_integer_like_return_types()); + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.verify.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.verify.cpp new file mode 100644 index 0000000..323f49b --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.verify.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: std-at-least-c++23 + +// <string> + +// template<class Operation> +// void resize_and_overwrite(size_type n, Operation op) + +// Verify that the operation's return type must be integer-like + +#include <string> + +void test_bool_return_type() { + std::string s; + s.resize_and_overwrite(10, [](char*, std::size_t) { + return true; // expected-error-re@*:* {{{{(static_assertion|static assertion)}}{{.*}}integer-like}} + }); +} + +void test_pointer_return_type() { + std::string s; + s.resize_and_overwrite(10, [](char* p, std::size_t) { + return p; // expected-error-re@*:* {{{{(static_assertion|static assertion)}}{{.*}}integer-like}} + // expected-error@*:* {{cannot initialize}} + }); +} + +void test_float_return_type() { + std::string s; + s.resize_and_overwrite(10, [](char*, std::size_t) { + return 5.0f; // expected-error-re@*:* {{{{(static_assertion|static assertion)}}{{.*}}integer-like}} + }); +} diff --git a/libcxx/utils/ci/BOT_OWNERS.txt b/libcxx/utils/ci/BOT_OWNERS.txt index 90f8272..3a92ba2 100644 --- a/libcxx/utils/ci/BOT_OWNERS.txt +++ b/libcxx/utils/ci/BOT_OWNERS.txt @@ -21,3 +21,8 @@ N: Android libc++ E: pirama@google.com, sharjeelkhan@google.com G: pirama-arumuga-nainar, Sharjeel-Khan D: Emulator-based x86[-64] libc++ CI testing + +N: FreeBSD libc++ +E: emaste@freebsd.org +G: emaste +D: FreeBSD x86-64 libc++ CI testing diff --git a/libcxx/utils/ci/buildkite-pipeline.yml b/libcxx/utils/ci/buildkite-pipeline.yml index 3f3e6b4..e7fda65 100644 --- a/libcxx/utils/ci/buildkite-pipeline.yml +++ b/libcxx/utils/ci/buildkite-pipeline.yml @@ -103,6 +103,7 @@ steps: queue: libcxx-builders os: aix <<: *common + skip: "Until https://github.com/llvm/llvm-project/issues/162516 has been resolved" - label: AIX (64-bit) command: libcxx/utils/ci/run-buildbot aix @@ -114,6 +115,7 @@ steps: queue: libcxx-builders os: aix <<: *common + skip: "Until https://github.com/llvm/llvm-project/issues/162516 has been resolved" - group: ':freebsd: FreeBSD' steps: diff --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py index 9a97e61..3fb30d8 100644 --- a/libcxx/utils/libcxx/test/dsl.py +++ b/libcxx/utils/libcxx/test/dsl.py @@ -111,8 +111,8 @@ def _makeConfigTest(config): os.makedirs(supportDir) # Create a dummy test suite and single dummy test inside it. As part of - # the Lit configuration, automatically do the equivalent of 'mkdir %T' - # and 'rm -r %T' to avoid cluttering the build directory. + # the Lit configuration, automatically do the equivalent of 'mkdir %{temp}' + # and 'rm -r %{temp}' to avoid cluttering the build directory. suite = lit.Test.TestSuite("__config__", sourceRoot, execRoot, config) tmp = tempfile.NamedTemporaryFile(dir=sourceRoot, delete=False, suffix=".cpp") tmp.close() @@ -296,7 +296,7 @@ def hasAnyLocale(config, locales): + name_string_literals + """, nullptr, }; - int main() { + int main(int, char**) { for (size_t i = 0; test_locale_names[i]; i++) { if (::setlocale(LC_ALL, test_locale_names[i]) != NULL) { return 0; diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py index 0070b76..7d6e78d 100644 --- a/libcxx/utils/libcxx/test/features.py +++ b/libcxx/utils/libcxx/test/features.py @@ -30,7 +30,7 @@ def _getAndroidDeviceApi(cfg): r""" #include <android/api-level.h> #include <stdio.h> - int main() { + int main(int, char**) { printf("%d\n", android_get_device_api_level()); return 0; } @@ -66,7 +66,7 @@ def _mingwSupportsModules(cfg): #else // __MINGW64_VERSION_MAJOR > 12 should be ok. #endif - int main() { return 0; } + int main(int, char**) { return 0; } """, ) @@ -474,7 +474,7 @@ def _getLocaleFlagsAction(cfg, locale, alts, members): #include <wchar.h> // Print each requested locale conversion member on separate lines. - int main() { + int main(int, char**) { const char* locales[] = { %s }; for (int loc_i = 0; loc_i < %d; ++loc_i) { if (!setlocale(LC_ALL, locales[loc_i])) { @@ -629,7 +629,7 @@ DEFAULT_FEATURES += [ """ #include <stdio.h> #include <windows.h> - int main() { + int main(int, char**) { CHAR tempDirPath[MAX_PATH]; DWORD tempPathRet = GetTempPathA(MAX_PATH, tempDirPath); if (tempPathRet == 0 || tempPathRet > MAX_PATH) { diff --git a/libcxx/utils/libcxx/test/format.py b/libcxx/utils/libcxx/test/format.py index c9dffd1..3fcd250 100644 --- a/libcxx/utils/libcxx/test/format.py +++ b/libcxx/utils/libcxx/test/format.py @@ -17,10 +17,10 @@ LIBCXX_UTILS = os.path.dirname(os.path.dirname(os.path.dirname(THIS_FILE))) def _getTempPaths(test): """ - Return the values to use for the %T and %t substitutions, respectively. + Return the values to use for the %{temp} and %t substitutions, respectively. The difference between this and Lit's default behavior is that we guarantee - that %T is a path unique to the test being run. + that %{temp} is a path unique to the test being run. """ tmpDir, _ = lit.TestRunner.getTempPaths(test) _, testName = os.path.split(test.getExecPath()) @@ -92,7 +92,7 @@ def parseScript(test, preamble): # errors, which doesn't make sense for clang-verify tests because we may want to check # for specific warning diagnostics. _checkBaseSubstitutions(substitutions) - substitutions.append(("%T", tmpDir)) + substitutions.append(("%{temp}", tmpDir)) substitutions.append( ("%{build}", "%{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe") ) @@ -150,7 +150,7 @@ def parseScript(test, preamble): # that file to the execution directory. Execute the copy from %S to allow # relative paths from the test directory. for dep in fileDependencies: - script += ["%dbg(SETUP) cd %S && cp {} %T".format(dep)] + script += ["%dbg(SETUP) cd %S && cp {} %{{temp}}".format(dep)] script += preamble script += scriptInTest @@ -178,11 +178,11 @@ def parseScript(test, preamble): "%dbg(MODULE std.compat) %{cxx} %{flags} " f"{compileFlags} " "-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal " - "-fmodule-file=std=%T/std.pcm " # The std.compat module imports std. - "--precompile -o %T/std.compat.pcm -c %{module-dir}/std.compat.cppm", + "-fmodule-file=std=%{temp}/std.pcm " # The std.compat module imports std. + "--precompile -o %{temp}/std.compat.pcm -c %{module-dir}/std.compat.cppm", ) moduleCompileFlags.extend( - ["-fmodule-file=std.compat=%T/std.compat.pcm", "%T/std.compat.pcm"] + ["-fmodule-file=std.compat=%{temp}/std.compat.pcm", "%{temp}/std.compat.pcm"] ) # Make sure the std module is built before std.compat. Libc++'s @@ -195,9 +195,9 @@ def parseScript(test, preamble): "%dbg(MODULE std) %{cxx} %{flags} " f"{compileFlags} " "-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal " - "--precompile -o %T/std.pcm -c %{module-dir}/std.cppm", + "--precompile -o %{temp}/std.pcm -c %{module-dir}/std.cppm", ) - moduleCompileFlags.extend(["-fmodule-file=std=%T/std.pcm", "%T/std.pcm"]) + moduleCompileFlags.extend(["-fmodule-file=std=%{temp}/std.pcm", "%{temp}/std.pcm"]) # Add compile flags required for the modules. substitutions = config._appendToSubstitution( @@ -261,6 +261,10 @@ class CxxStandardLibraryTest(lit.formats.FileBasedTest): %{run} Equivalent to `%{exec} %t.exe`. This is intended to be used in conjunction with the %{build} substitution. + + %{temp} + This substitution expands to a non-existent temporary path unique to the test. + It is typically used to create a temporary directory. """ def getTestsForPath(self, testSuite, pathInSuite, litConfig, localConfig): @@ -355,9 +359,9 @@ class CxxStandardLibraryTest(lit.formats.FileBasedTest): "%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} %{benchmark_flags} %{link_flags} -o %t.exe", ] if "enable-benchmarks=run" in test.config.available_features: - steps += ["%dbg(EXECUTED AS) %{exec} %t.exe --benchmark_out=%T/benchmark-result.json --benchmark_out_format=json"] + steps += ["%dbg(EXECUTED AS) %{exec} %t.exe --benchmark_out=%{temp}/benchmark-result.json --benchmark_out_format=json"] parse_results = os.path.join(LIBCXX_UTILS, 'parse-google-benchmark-results') - steps += [f"{parse_results} %T/benchmark-result.json --output-format=lnt > %T/results.lnt"] + steps += [f"{parse_results} %{temp}/benchmark-result.json --output-format=lnt > %{temp}/results.lnt"] return self._executeShTest(test, litConfig, steps) elif re.search('[.]gen[.][^.]+$', filename): # This only happens when a generator test is not supported return self._executeShTest(test, litConfig, []) diff --git a/libcxx/utils/ssh.py b/libcxx/utils/ssh.py index ec16efc..77e79ce 100755 --- a/libcxx/utils/ssh.py +++ b/libcxx/utils/ssh.py @@ -57,7 +57,7 @@ def main(): return subprocess.run(command, *args_, **kwargs) # Create a temporary directory where the test will be run. - # That is effectively the value of %T on the remote host. + # That is effectively the value of %{temp} on the remote host. tmp = runCommand( ssh("mktemp -d {}/libcxx.XXXXXXXXXX".format(args.tempdir)), universal_newlines=True, diff --git a/libcxx/utils/test-at-commit b/libcxx/utils/test-at-commit index d62643d..f20bf5f 100755 --- a/libcxx/utils/test-at-commit +++ b/libcxx/utils/test-at-commit @@ -22,7 +22,7 @@ config.substitutions.append(('%{{flags}}', )) config.substitutions.append(('%{{compile_flags}}', '-nostdinc++ -I {INSTALL_ROOT}/include/c++/v1 -I %{{libcxx-dir}}/test/support')) config.substitutions.append(('%{{link_flags}}', '-nostdlib++ -L {INSTALL_ROOT}/lib -Wl,-rpath,{INSTALL_ROOT}/lib -lc++')) -config.substitutions.append(('%{{exec}}', '%{{executor}} --execdir %T -- ')) +config.substitutions.append(('%{{exec}}', '%{{executor}} --execdir %{{temp}} -- ')) import os, site site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils')) |