Skip to content

Commit

Permalink
[libc++] Add a few more debug wrapper functions
Browse files Browse the repository at this point in the history
Reviewed By: ldionne, #libc, jloser

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D125176
  • Loading branch information
philnik777 committed May 11, 2022
1 parent edbf390 commit 08f68df
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 92 deletions.
31 changes: 31 additions & 0 deletions libcxx/include/__debug
Expand Up @@ -226,6 +226,37 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_inser
#endif
}

template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_erase_c(_Tp* __c) {
#if _LIBCPP_DEBUG_LEVEL == 2
if (!__libcpp_is_constant_evaluated())
__get_db()->__erase_c(__c);
#else
(void)(__c);
#endif
}

template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_swap(_Tp* __lhs, _Tp* __rhs) {
#if _LIBCPP_DEBUG_LEVEL == 2
if (!__libcpp_is_constant_evaluated())
__get_db()->swap(__lhs, __rhs);
#else
(void)(__lhs);
(void)(__rhs);
#endif
}

template <class _Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_invalidate_all(_Tp* __c) {
#if _LIBCPP_DEBUG_LEVEL == 2
if (!__libcpp_is_constant_evaluated())
__get_db()->__invalidate_all(__c);
#else
(void)(__c);
#endif
}

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___DEBUG
16 changes: 4 additions & 12 deletions libcxx/include/__hash_table
Expand Up @@ -1512,9 +1512,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
#endif

__deallocate_node(__p1_.first().__next_);
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__erase_c(this);
#endif
std::__debug_db_erase_c(this);
}

template <class _Tp, class _Hash, class _Equal, class _Alloc>
Expand Down Expand Up @@ -1617,9 +1615,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
__u.__p1_.first().__next_ = nullptr;
__u.size() = 0;
}
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Tp, class _Hash, class _Equal, class _Alloc>
Expand Down Expand Up @@ -2321,9 +2317,7 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
{
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__invalidate_all(this);
#endif
std::__debug_db_invalidate_all(this);
__pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
__bucket_list_.reset(__nbc > 0 ?
__pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
Expand Down Expand Up @@ -2729,9 +2723,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
if (__u.size() > 0)
__u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
__u.__p1_.first().__ptr();
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Tp, class _Hash, class _Equal, class _Alloc>
Expand Down
16 changes: 4 additions & 12 deletions libcxx/include/list
Expand Up @@ -682,9 +682,7 @@ private:

_LIBCPP_INLINE_VISIBILITY
void __invalidate_all_iterators() {
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__invalidate_all(this);
#endif
std::__debug_db_invalidate_all(this);
}
};

Expand Down Expand Up @@ -727,9 +725,7 @@ inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
template <class _Tp, class _Alloc>
__list_imp<_Tp, _Alloc>::~__list_imp() {
clear();
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__erase_c(this);
#endif
std::__debug_db_erase_c(this);
}

template <class _Tp, class _Alloc>
Expand Down Expand Up @@ -1373,9 +1369,7 @@ list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
insert(__e, __f, __l);
else
erase(__i, __e);
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__invalidate_all(this);
#endif
std::__debug_db_invalidate_all(this);
}

template <class _Tp, class _Alloc>
Expand All @@ -1390,9 +1384,7 @@ list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
insert(__e, __n, __x);
else
erase(__i, __e);
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__invalidate_all(this);
#endif
std::__debug_db_invalidate_all(this);
}

template <class _Tp, class _Alloc>
Expand Down
37 changes: 12 additions & 25 deletions libcxx/include/string
Expand Up @@ -1865,10 +1865,7 @@ inline _LIBCPP_CONSTEXPR_AFTER_CXX17
void
basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
{
#if _LIBCPP_DEBUG_LEVEL == 2
if (!__libcpp_is_constant_evaluated())
__get_db()->__invalidate_all(this);
#endif
std::__debug_db_invalidate_all(this);
}

template <class _CharT, class _Traits, class _Allocator>
Expand Down Expand Up @@ -2077,10 +2074,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
{
__str.__default_init();
std::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
if (!__libcpp_is_constant_evaluated() && __is_long())
__get_db()->swap(this, &__str);
#endif
if (__is_long())
std::__debug_db_swap(this, &__str);
}

template <class _CharT, class _Traits, class _Allocator>
Expand All @@ -2101,10 +2096,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co
__str.__default_init();
}
std::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
if (!__libcpp_is_constant_evaluated() && __is_long())
__get_db()->swap(this, &__str);
#endif
if (__is_long())
std::__debug_db_swap(this, &__str);
}

#endif // _LIBCPP_CXX03_LANG
Expand Down Expand Up @@ -2342,10 +2335,7 @@ template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_CONSTEXPR_AFTER_CXX17
basic_string<_CharT, _Traits, _Allocator>::~basic_string()
{
#if _LIBCPP_DEBUG_LEVEL == 2
if (!__libcpp_is_constant_evaluated())
__get_db()->__erase_c(this);
#endif
std::__debug_db_erase_c(this);
if (__is_long())
__alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
}
Expand Down Expand Up @@ -3600,15 +3590,12 @@ basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
__is_nothrow_swappable<allocator_type>::value)
#endif
{
#if _LIBCPP_DEBUG_LEVEL == 2
if (!__libcpp_is_constant_evaluated()) {
if (!__is_long())
__get_db()->__invalidate_all(this);
if (!__str.__is_long())
__get_db()->__invalidate_all(&__str);
__get_db()->swap(this, &__str);
}
#endif
if (!__is_long())
std::__debug_db_invalidate_all(this);
if (!__str.__is_long())
std::__debug_db_invalidate_all(&__str);
std::__debug_db_swap(this, &__str);

_LIBCPP_ASSERT(
__alloc_traits::propagate_on_container_swap::value ||
__alloc_traits::is_always_equal::value ||
Expand Down
16 changes: 4 additions & 12 deletions libcxx/include/unordered_map
Expand Up @@ -1693,9 +1693,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
: __table_(_VSTD::move(__u.__table_))
{
_VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Expand All @@ -1712,10 +1710,8 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
__u.__table_.remove((__i++).__i_)->__value_.__move());
}
}
#if _LIBCPP_DEBUG_LEVEL == 2
else
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Expand Down Expand Up @@ -2469,9 +2465,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
: __table_(_VSTD::move(__u.__table_))
{
_VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Expand All @@ -2489,10 +2483,8 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
__u.__table_.remove((__i++).__i_)->__value_.__move());
}
}
#if _LIBCPP_DEBUG_LEVEL == 2
else
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Expand Down
16 changes: 4 additions & 12 deletions libcxx/include/unordered_set
Expand Up @@ -1006,9 +1006,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
: __table_(_VSTD::move(__u.__table_))
{
_VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Value, class _Hash, class _Pred, class _Alloc>
Expand All @@ -1023,10 +1021,8 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
while (__u.size() != 0)
__table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
}
#if _LIBCPP_DEBUG_LEVEL == 2
else
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Value, class _Hash, class _Pred, class _Alloc>
Expand Down Expand Up @@ -1647,9 +1643,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
: __table_(_VSTD::move(__u.__table_))
{
_VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Value, class _Hash, class _Pred, class _Alloc>
Expand All @@ -1664,10 +1658,8 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
while (__u.size() != 0)
__table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
}
#if _LIBCPP_DEBUG_LEVEL == 2
else
__get_db()->swap(this, _VSTD::addressof(__u));
#endif
std::__debug_db_swap(this, std::addressof(__u));
}

template <class _Value, class _Hash, class _Pred, class _Alloc>
Expand Down
25 changes: 6 additions & 19 deletions libcxx/include/vector
Expand Up @@ -413,9 +413,7 @@ public:
~vector()
{
__annotate_delete();
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__erase_c(this);
#endif
std::__debug_db_erase_c(this);

if (this->__begin_ != nullptr)
{
Expand Down Expand Up @@ -1206,9 +1204,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
: __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
{
_VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__x));
#endif
std::__debug_db_swap(this, std::addressof(__x));
this->__begin_ = __x.__begin_;
this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap();
Expand All @@ -1227,9 +1223,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_
this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap();
__x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__x));
#endif
std::__debug_db_swap(this, std::addressof(__x));
}
else
{
Expand Down Expand Up @@ -1299,9 +1293,7 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
this->__end_ = __c.__end_;
this->__end_cap() = __c.__end_cap();
__c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__c));
#endif
std::__debug_db_swap(this, std::addressof(__c));
}

#endif // !_LIBCPP_CXX03_LANG
Expand Down Expand Up @@ -1946,9 +1938,7 @@ vector<_Tp, _Allocator>::swap(vector& __x)
_VSTD::swap(this->__end_cap(), __x.__end_cap());
_VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->swap(this, _VSTD::addressof(__x));
#endif
std::__debug_db_swap(this, std::addressof(__x));
}

template <class _Tp, class _Allocator>
Expand Down Expand Up @@ -2011,12 +2001,9 @@ inline _LIBCPP_INLINE_VISIBILITY
void
vector<_Tp, _Allocator>::__invalidate_all_iterators()
{
#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__invalidate_all(this);
#endif
std::__debug_db_invalidate_all(this);
}


template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
Expand Down

0 comments on commit 08f68df

Please sign in to comment.