[libcxx-commits] [libcxx] 08f68df - [libc++] Add a few more debug wrapper functions

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 11 12:33:05 PDT 2022


Author: Nikolas Klauser
Date: 2022-05-11T21:32:37+02:00
New Revision: 08f68dfef6102e7b18116aec30ecb712cedfc2d9

URL: https://github.com/llvm/llvm-project/commit/08f68dfef6102e7b18116aec30ecb712cedfc2d9
DIFF: https://github.com/llvm/llvm-project/commit/08f68dfef6102e7b18116aec30ecb712cedfc2d9.diff

LOG: [libc++] Add a few more debug wrapper functions

Reviewed By: ldionne, #libc, jloser

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D125176

Added: 
    

Modified: 
    libcxx/include/__debug
    libcxx/include/__hash_table
    libcxx/include/list
    libcxx/include/string
    libcxx/include/unordered_map
    libcxx/include/unordered_set
    libcxx/include/vector

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__debug b/libcxx/include/__debug
index 1296b4db5bbf5..39539af0e9185 100644
--- a/libcxx/include/__debug
+++ b/libcxx/include/__debug
@@ -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

diff  --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index d180187a73587..a1a4d4455d58d 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -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>
@@ -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>
@@ -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);
@@ -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>

diff  --git a/libcxx/include/list b/libcxx/include/list
index aa8b2c0805bfb..0f765d2f1b395 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -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);
     }
 };
 
@@ -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>
@@ -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>
@@ -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>

diff  --git a/libcxx/include/string b/libcxx/include/string
index 11c17549151d8..c113e2f8b1b08 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -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>
@@ -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>
@@ -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
@@ -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());
 }
@@ -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 ||

diff  --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map
index a31c2c6ddea0d..e5741b054660d 100644
--- a/libcxx/include/unordered_map
+++ b/libcxx/include/unordered_map
@@ -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>
@@ -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>
@@ -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>
@@ -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>

diff  --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set
index f23de20456859..de0e12197d16a 100644
--- a/libcxx/include/unordered_set
+++ b/libcxx/include/unordered_set
@@ -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>
@@ -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>
@@ -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>
@@ -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>

diff  --git a/libcxx/include/vector b/libcxx/include/vector
index 165b21d18e59c..753b0232840f7 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -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)
       {
@@ -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();
@@ -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
     {
@@ -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
@@ -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>
@@ -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


        


More information about the libcxx-commits mailing list