* [PATCH 1/4] libstdc++: Don't use std::__is_scalar in std::valarray initialization [PR115497]
@ 2024-06-20 15:30 Jonathan Wakely
2024-06-20 15:30 ` [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497] Jonathan Wakely
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-20 15:30 UTC (permalink / raw)
To: libstdc++, gcc-patches
We know that valarray's value_type must be DefaultConstructible, so we
don't need to test that. I think __is_trivial is sufficient to tell us
we can use memset to value-initialize the elements.
Tested x86_64-linux.
-- >8 --
This removes the use of the std::__is_scalar trait from <valarray>,
where it can be replaced by __is_trivial. It's used to decide whether we
can use memset to value-initialize valarray elements, but memset is
suitable for any trivial types, because value-initializing them is
equivalent to filling them with zeros.
This is another step towards removing the class templates in
<bits/cpp_type_traits.h> that conflict with Clang built-in names.
libstdc++-v3/ChangeLog:
PR libstdc++/115497
* include/bits/valarray_array.h (__valarray_default_construct):
Use __is_trivial(_Tp). instead of __is_scalar<_Tp>.
---
libstdc++-v3/include/bits/valarray_array.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h
index 66b74f9aaac..07c49ce1057 100644
--- a/libstdc++-v3/include/bits/valarray_array.h
+++ b/libstdc++-v3/include/bits/valarray_array.h
@@ -80,7 +80,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
struct _Array_default_ctor<_Tp, true>
{
- // For fundamental types, it suffices to say 'memset()'
+ // For trivial types, it suffices to say 'memset()'
inline static void
_S_do_it(_Tp* __b, _Tp* __e)
{ __builtin_memset(__b, 0, (__e - __b) * sizeof(_Tp)); }
@@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline void
__valarray_default_construct(_Tp* __b, _Tp* __e)
{
- _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
+ _Array_default_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e);
}
// Turn a raw-memory into an array of _Tp filled with __t
--
2.45.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497]
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
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
2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-20 15:30 UTC (permalink / raw)
To: libstdc++, gcc-patches
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] libstdc++: Remove std::__is_void class template [PR115497]
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 ` [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497] Jonathan Wakely
@ 2024-06-20 15:30 ` Jonathan Wakely
2024-06-20 15:30 ` [PATCH 4/4] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497] Jonathan Wakely
2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-20 15:30 UTC (permalink / raw)
To: libstdc++, gcc-patches
Tested x86_64-linux.
-- >8 --
This removes the std::__is_void trait, as it conflicts with a Clang
built-in. There is only one use of the trait, which can easily be
replaced by simpler code.
Although Clang has a hack to make the class template work despite using
a reserved name, removing std::__is_void will allow that hack to be
dropped at some future date.
libstdc++-v3/ChangeLog:
PR libstdc++/115497
* include/bits/cpp_type_traits.h (__is_void): Remove.
* include/debug/helper_functions.h (_Distance_traits):
Adjust partial specialization to match void directly, instead of
using __is_void<T>::__type and matching __true_type.
---
libstdc++-v3/include/bits/cpp_type_traits.h | 15 ---------------
libstdc++-v3/include/debug/helper_functions.h | 5 ++---
2 files changed, 2 insertions(+), 18 deletions(-)
diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index 6834dee5557..4d83b9472e6 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -105,21 +105,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef __true_type __type;
};
- // Holds if the template-argument is a void type.
- template<typename _Tp>
- struct __is_void
- {
- enum { __value = 0 };
- typedef __false_type __type;
- };
-
- template<>
- struct __is_void<void>
- {
- enum { __value = 1 };
- typedef __true_type __type;
- };
-
//
// Integer types
//
diff --git a/libstdc++-v3/include/debug/helper_functions.h b/libstdc++-v3/include/debug/helper_functions.h
index 5474399dc67..d686a29e8ee 100644
--- a/libstdc++-v3/include/debug/helper_functions.h
+++ b/libstdc++-v3/include/debug/helper_functions.h
@@ -66,13 +66,12 @@ namespace __gnu_debug
typedef
typename std::iterator_traits<_Iterator>::difference_type _ItDiffType;
- template<typename _DiffType,
- typename = typename std::__is_void<_DiffType>::__type>
+ template<typename _DiffType, typename = _DiffType> // PR c++/85282
struct _DiffTraits
{ typedef _DiffType __type; };
template<typename _DiffType>
- struct _DiffTraits<_DiffType, std::__true_type>
+ struct _DiffTraits<_DiffType, void>
{ typedef std::ptrdiff_t __type; };
typedef typename _DiffTraits<_ItDiffType>::__type _DiffType;
--
2.45.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497]
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 ` [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497] Jonathan Wakely
2024-06-20 15:30 ` [PATCH 3/4] libstdc++: Remove std::__is_void class template [PR115497] Jonathan Wakely
@ 2024-06-20 15:30 ` Jonathan Wakely
2024-06-21 9:31 ` Jonathan Wakely
2 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-20 15:30 UTC (permalink / raw)
To: libstdc++, gcc-patches
We still have __is_arithmetic in <bits/cpp_type_traits.h> after this,
but that needs a lot more work to remove its uses from <cmath> and
<tr1/cmath>.
Tested x86_64-linux.
-- >8 --
This removes the std::__is_pointer and std::__is_scalar traits, as they
conflicts with a Clang built-in.
Although Clang has a hack to make the class templates work despite using
reserved names, removing these class templates will allow that hack to
be dropped at some future date.
libstdc++-v3/ChangeLog:
PR libstdc++/115497
* include/bits/cpp_type_traits.h (__is_pointer, __is_scalar):
Remove.
(__is_arithmetic): Do not use __is_pointer in the primary
template. Add partial specialization for pointers.
---
libstdc++-v3/include/bits/cpp_type_traits.h | 33 ---------------------
1 file changed, 33 deletions(-)
diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index 4d83b9472e6..abe0c7603e3 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -343,31 +343,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
};
#endif
- //
- // Pointer types
- //
-#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
- template<typename _Tp, bool _IsPtr = __is_pointer(_Tp)>
- struct __is_pointer : __truth_type<_IsPtr>
- {
- enum { __value = _IsPtr };
- };
-#else
- template<typename _Tp>
- struct __is_pointer
- {
- enum { __value = 0 };
- typedef __false_type __type;
- };
-
- template<typename _Tp>
- struct __is_pointer<_Tp*>
- {
- enum { __value = 1 };
- typedef __true_type __type;
- };
-#endif
-
//
// An arithmetic type is an integer type or a floating point type
//
@@ -376,14 +351,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
: public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >
{ };
- //
- // A scalar type is an arithmetic type or a pointer type
- //
- template<typename _Tp>
- struct __is_scalar
- : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
- { };
-
//
// For use in std::copy and std::find overloads for streambuf iterators.
//
--
2.45.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 4/4] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497]
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
0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-21 9:31 UTC (permalink / raw)
To: libstdc++, gcc-patches
Oops, this patch series actually depends on
https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655267.html which
was posted separately, but needs to be applied before 4/4 in this
series.
On Thu, 20 Jun 2024 at 16:35, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> We still have __is_arithmetic in <bits/cpp_type_traits.h> after this,
> but that needs a lot more work to remove its uses from <cmath> and
> <tr1/cmath>.
>
> Tested x86_64-linux.
>
> -- >8 --
>
> This removes the std::__is_pointer and std::__is_scalar traits, as they
> conflicts with a Clang built-in.
>
> Although Clang has a hack to make the class templates work despite using
> reserved names, removing these class templates will allow that hack to
> be dropped at some future date.
>
> libstdc++-v3/ChangeLog:
>
> PR libstdc++/115497
> * include/bits/cpp_type_traits.h (__is_pointer, __is_scalar):
> Remove.
> (__is_arithmetic): Do not use __is_pointer in the primary
> template. Add partial specialization for pointers.
> ---
> libstdc++-v3/include/bits/cpp_type_traits.h | 33 ---------------------
> 1 file changed, 33 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
> index 4d83b9472e6..abe0c7603e3 100644
> --- a/libstdc++-v3/include/bits/cpp_type_traits.h
> +++ b/libstdc++-v3/include/bits/cpp_type_traits.h
> @@ -343,31 +343,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
> };
> #endif
>
> - //
> - // Pointer types
> - //
> -#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
> - template<typename _Tp, bool _IsPtr = __is_pointer(_Tp)>
> - struct __is_pointer : __truth_type<_IsPtr>
> - {
> - enum { __value = _IsPtr };
> - };
> -#else
> - template<typename _Tp>
> - struct __is_pointer
> - {
> - enum { __value = 0 };
> - typedef __false_type __type;
> - };
> -
> - template<typename _Tp>
> - struct __is_pointer<_Tp*>
> - {
> - enum { __value = 1 };
> - typedef __true_type __type;
> - };
> -#endif
> -
> //
> // An arithmetic type is an integer type or a floating point type
> //
> @@ -376,14 +351,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
> : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >
> { };
>
> - //
> - // A scalar type is an arithmetic type or a pointer type
> - //
> - template<typename _Tp>
> - struct __is_scalar
> - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
> - { };
> -
> //
> // For use in std::copy and std::find overloads for streambuf iterators.
> //
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 4/4] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497]
2024-06-21 9:31 ` Jonathan Wakely
@ 2024-06-21 16:08 ` Jonathan Wakely
0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-21 16:08 UTC (permalink / raw)
To: libstdc++, gcc-patches
This series (and the patch it depends on) have been pushed to trunk now.
On Fri, 21 Jun 2024 at 10:31, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> Oops, this patch series actually depends on
> https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655267.html which
> was posted separately, but needs to be applied before 4/4 in this
> series.
>
> On Thu, 20 Jun 2024 at 16:35, Jonathan Wakely <jwakely@redhat.com> wrote:
> >
> > We still have __is_arithmetic in <bits/cpp_type_traits.h> after this,
> > but that needs a lot more work to remove its uses from <cmath> and
> > <tr1/cmath>.
> >
> > Tested x86_64-linux.
> >
> > -- >8 --
> >
> > This removes the std::__is_pointer and std::__is_scalar traits, as they
> > conflicts with a Clang built-in.
> >
> > Although Clang has a hack to make the class templates work despite using
> > reserved names, removing these class templates will allow that hack to
> > be dropped at some future date.
> >
> > libstdc++-v3/ChangeLog:
> >
> > PR libstdc++/115497
> > * include/bits/cpp_type_traits.h (__is_pointer, __is_scalar):
> > Remove.
> > (__is_arithmetic): Do not use __is_pointer in the primary
> > template. Add partial specialization for pointers.
> > ---
> > libstdc++-v3/include/bits/cpp_type_traits.h | 33 ---------------------
> > 1 file changed, 33 deletions(-)
> >
> > diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
> > index 4d83b9472e6..abe0c7603e3 100644
> > --- a/libstdc++-v3/include/bits/cpp_type_traits.h
> > +++ b/libstdc++-v3/include/bits/cpp_type_traits.h
> > @@ -343,31 +343,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
> > };
> > #endif
> >
> > - //
> > - // Pointer types
> > - //
> > -#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
> > - template<typename _Tp, bool _IsPtr = __is_pointer(_Tp)>
> > - struct __is_pointer : __truth_type<_IsPtr>
> > - {
> > - enum { __value = _IsPtr };
> > - };
> > -#else
> > - template<typename _Tp>
> > - struct __is_pointer
> > - {
> > - enum { __value = 0 };
> > - typedef __false_type __type;
> > - };
> > -
> > - template<typename _Tp>
> > - struct __is_pointer<_Tp*>
> > - {
> > - enum { __value = 1 };
> > - typedef __true_type __type;
> > - };
> > -#endif
> > -
> > //
> > // An arithmetic type is an integer type or a floating point type
> > //
> > @@ -376,14 +351,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
> > : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >
> > { };
> >
> > - //
> > - // A scalar type is an arithmetic type or a pointer type
> > - //
> > - template<typename _Tp>
> > - struct __is_scalar
> > - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
> > - { };
> > -
> > //
> > // For use in std::copy and std::find overloads for streambuf iterators.
> > //
> > --
> > 2.45.2
> >
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-06-21 16:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497] Jonathan Wakely
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
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).