public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497]
Date: Thu, 20 Jun 2024 16:30:14 +0100	[thread overview]
Message-ID: <20240620153240.2022128-2-jwakely@redhat.com> (raw)
In-Reply-To: <20240620153240.2022128-1-jwakely@redhat.com>

Tested x86_64-linux.

-- >8 --

This replaces all uses of the std::__is_pointer type trait with uses of
the new __is_pointer built-in. Since the class template was only used to
enable some performance optimizations for algorithms, we can use the
built-in when __has_builtin(__is_pointer) is true (which is the case for
GCC trunk and for current versions of Clang) and just forego the
optimization otherwise.

Removing the uses of std::__is_pointer means it can be removed from
<bits/cpp_type_traits.h>, which is another step towards fixing PR
115497.

libstdc++-v3/ChangeLog:

	PR libstdc++/115497
	* include/bits/deque.tcc (__lex_cmp_dit): Replace __is_pointer
	class template with __is_pointer(T) built-in.
	(__lexicographical_compare_aux1): Likewise.
	* include/bits/stl_algobase.h (__equal_aux1): Likewise.
	(__lexicographical_compare_aux1): Likewise.
---
 libstdc++-v3/include/bits/deque.tcc      | 19 ++++++++++++-------
 libstdc++-v3/include/bits/stl_algobase.h | 13 +++++++++----
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc
index 2c12358ca5b..deb010a0ebb 100644
--- a/libstdc++-v3/include/bits/deque.tcc
+++ b/libstdc++-v3/include/bits/deque.tcc
@@ -1271,18 +1271,21 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 	_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref, _Ptr> __last1,
 	const _Tp2* __first2, const _Tp2* __last2)
     {
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
       const bool __simple =
 	(__is_memcmp_ordered_with<_Tp1, _Tp2>::__value
-	 && __is_pointer<_Ptr>::__value
+	 && __is_pointer(_Ptr)
 #if __cplusplus > 201703L && __cpp_lib_concepts
 	 // For C++20 iterator_traits<volatile T*>::value_type is non-volatile
 	 // so __is_byte<T> could be true, but we can't use memcmp with
 	 // volatile data.
-	 && !is_volatile_v<_Tp1>
-	 && !is_volatile_v<_Tp2>
+	 && !is_volatile_v<_Tp1> && !is_volatile_v<_Tp2>
 #endif
 	 );
       typedef std::__lexicographical_compare<__simple> _Lc;
+#else
+      typedef std::__lexicographical_compare<false> _Lc;
+#endif
 
       while (__first1._M_node != __last1._M_node)
 	{
@@ -1327,19 +1330,21 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 		_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __first2,
 		_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __last2)
     {
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
       const bool __simple =
 	(__is_memcmp_ordered_with<_Tp1, _Tp2>::__value
-	 && __is_pointer<_Ptr1>::__value
-	 && __is_pointer<_Ptr2>::__value
+	 && __is_pointer(_Ptr1) && __is_pointer(_Ptr2)
 #if __cplusplus > 201703L && __cpp_lib_concepts
 	 // For C++20 iterator_traits<volatile T*>::value_type is non-volatile
 	 // so __is_byte<T> could be true, but we can't use memcmp with
 	 // volatile data.
-	 && !is_volatile_v<_Tp1>
-	 && !is_volatile_v<_Tp2>
+	 && !is_volatile_v<_Tp1> && !is_volatile_v<_Tp2>
 #endif
 	 );
       typedef std::__lexicographical_compare<__simple> _Lc;
+#else
+      typedef std::__lexicographical_compare<false> _Lc;
+#endif
 
       while (__first1 != __last1)
 	{
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index 1a0f8c14073..57ff2f7cb08 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -1256,8 +1256,10 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
     {
       typedef typename iterator_traits<_II1>::value_type _ValueType1;
       const bool __simple = ((__is_integer<_ValueType1>::__value
-			      || __is_pointer<_ValueType1>::__value)
-			     && __memcmpable<_II1, _II2>::__value);
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
+			      || __is_pointer(_ValueType1)
+#endif
+			     ) && __memcmpable<_II1, _II2>::__value);
       return std::__equal<__simple>::equal(__first1, __last1, __first2);
     }
 
@@ -1420,10 +1422,10 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
     {
       typedef typename iterator_traits<_II1>::value_type _ValueType1;
       typedef typename iterator_traits<_II2>::value_type _ValueType2;
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
       const bool __simple =
 	(__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
-	 && __is_pointer<_II1>::__value
-	 && __is_pointer<_II2>::__value
+	 && __is_pointer(_II1) && __is_pointer(_II2)
 #if __cplusplus > 201703L && __glibcxx_concepts
 	 // For C++20 iterator_traits<volatile T*>::value_type is non-volatile
 	 // so __is_byte<T> could be true, but we can't use memcmp with
@@ -1432,6 +1434,9 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 	 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
 #endif
 	 );
+#else
+      const bool __simple = false;
+#endif
 
       return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
 							    __first2, __last2);
-- 
2.45.2


  reply	other threads:[~2024-06-20 15:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-20 15:30 [PATCH 1/4] libstdc++: Don't use std::__is_scalar in std::valarray initialization [PR115497] Jonathan Wakely
2024-06-20 15:30 ` Jonathan Wakely [this message]
2024-06-20 15:30 ` [PATCH 3/4] libstdc++: Remove std::__is_void class template [PR115497] Jonathan Wakely
2024-06-20 15:30 ` [PATCH 4/4] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497] Jonathan Wakely
2024-06-21  9:31   ` Jonathan Wakely
2024-06-21 16:08     ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240620153240.2022128-2-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).