Updated patch with a new test.

Use __builtin_memmove for trivially copy assignable types

2018-06-19  Glen Joseph Fernandes  <glenj...@gmail.com>

    * include/bits/stl_algobase.h
    (__is_simple_copy_move): Defined helper.
    (__copy_move_a): Used helper.
    (__copy_move_backward_a): Likewise.
    * testsuite/20_util/specialized_algorithms/uninitialized_copy/1.cc:
    New test.
    * testsuite/25_algorithms/copy/58982.cc: Updated tests.
    * testsuite/25_algorithms/copy_n/58982.cc: Likewise.

Attached: patch.txt

Glen
commit 521df588d7a83c662c833c0460d171663c62fd9a
Author: Glen Fernandes <glenj...@gmail.com>
Date:   Fri Jun 15 07:33:07 2018 -0400

    Use __builtin_memmove for trivially copy assignable types
    
    2018-06-19  Glen Joseph Fernandes  <glenj...@gmail.com>
    
        * include/bits/stl_algobase.h
        (__is_simple_copy_move): Defined helper.
        (__copy_move_a): Used helper.
        (__copy_move_backward_a): Likewise.
        * testsuite/20_util/specialized_algorithms/uninitialized_copy/1.cc:
        New test.
        * testsuite/25_algorithms/copy/58982.cc: Updated tests.
        * testsuite/25_algorithms/copy_n/58982.cc: Likewise.

diff --git a/libstdc++-v3/include/bits/stl_algobase.h 
b/libstdc++-v3/include/bits/stl_algobase.h
index 022a3f159..d9e1a7958 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -74,6 +74,16 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+  template<typename _Tp>
+    struct __is_simple_copy_move
+    {
+#if __cplusplus < 201103L
+      enum { __value = __is_trivial(_Tp) };
+#else
+      enum { __value = is_trivially_copy_assignable<_Tp>::value };
+#endif
+    };
+
 #if __cplusplus < 201103L
   // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
   // nutshell, we are partially implementing the resolution of DR 187,
@@ -377,7 +387,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       typedef typename iterator_traits<_II>::value_type _ValueTypeI;
       typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
       typedef typename iterator_traits<_II>::iterator_category _Category;
-      const bool __simple = (__is_trivial(_ValueTypeI)
+      const bool __simple = (__is_simple_copy_move<_ValueTypeI>::__value
                             && __is_pointer<_II>::__value
                             && __is_pointer<_OI>::__value
                             && __are_same<_ValueTypeI, _ValueTypeO>::__value);
@@ -578,7 +588,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       typedef typename iterator_traits<_BI1>::value_type _ValueType1;
       typedef typename iterator_traits<_BI2>::value_type _ValueType2;
       typedef typename iterator_traits<_BI1>::iterator_category _Category;
-      const bool __simple = (__is_trivial(_ValueType1)
+      const bool __simple = (__is_simple_copy_move<_ValueType1>::__value
                             && __is_pointer<_BI1>::__value
                             && __is_pointer<_BI2>::__value
                             && __are_same<_ValueType1, _ValueType2>::__value);
diff --git 
a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/1.cc 
b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/1.cc
new file mode 100644
index 000000000..437b4c2e9
--- /dev/null
+++ 
b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/1.cc
@@ -0,0 +1,38 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <algorithm>
+#include <type_traits>
+
+struct T
+{
+  T() { }
+  T(const T&) = delete;
+};
+
+static_assert(std::is_trivially_copy_assignable<T>::value &&
+  !__is_trivial(T), "T is only trivially copy assignable");
+
+void
+test01(T* result)
+{
+  T t[1];
+  std::uninitialized_copy(t, t+1, result); // { dg-error "here" }
+}
+// { dg-prune-output "use of deleted function" }
diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/58982.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy/58982.cc
index 03d918344..324f0e3b5 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy/58982.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy/58982.cc
@@ -38,4 +38,4 @@ test01(T* result)
   T t[1];
   std::copy(t, t+1, result); // { dg-error "here" }
 }
-// { dg-prune-output "not assignable" }
+// { dg-prune-output "use of deleted function" }
diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_n/58982.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy_n/58982.cc
index dc488cd1f..3eb793218 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy_n/58982.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy_n/58982.cc
@@ -38,4 +38,4 @@ test01(T* result)
   T t[1];
   std::copy_n(t, 1, result); // { dg-error "here" }
 }
-// { dg-prune-output "not assignable" }
+// { dg-prune-output "use of deleted function" }

Reply via email to