[libcxx-commits] [PATCH] D154913: [libc++][PSTL] Fix double-move in std::transform_reduce

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 10 18:07:44 PDT 2023


philnik created this revision.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154913

Files:
  libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
  libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.transform_reduce.unary.pass.cpp


Index: libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.transform_reduce.unary.pass.cpp
===================================================================
--- libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.transform_reduce.unary.pass.cpp
+++ libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.transform_reduce.unary.pass.cpp
@@ -20,6 +20,7 @@
 //                      T init, BinaryOperation binary_op, UnaryOperation unary_op);
 
 #include <numeric>
+#include <string>
 #include <vector>
 
 #include "MoveOnly.h"
@@ -42,8 +43,14 @@
           Iter1(std::data(a)),
           Iter1(std::data(a) + std::size(a)),
           ValueT(34),
-          [](ValueT i, ValueT j) { return i + j; },
-          [](ValueT i) { return i + 1; });
+          [check = std::string("Banane")](ValueT i, ValueT j) {
+            assert(check == "Banane"); // ensure that no bouble-moves happen
+            return i + j;
+          },
+          [check = std::string("Banane")](ValueT i) {
+            assert(check == "Banane"); // ensure that no bouble-moves happen
+            return i + 1;
+          });
       static_assert(std::is_same_v<decltype(ret), ValueT>);
       assert(ret == expected);
     }
Index: libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
===================================================================
--- libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
+++ libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
@@ -163,7 +163,7 @@
           std::move(__last),
           [__transform](_ForwardIterator __iter) { return __transform(*__iter); },
           std::move(__init),
-          std::move(__reduce),
+          __reduce,
           [=](_ForwardIterator __brick_first, _ForwardIterator __brick_last, _Tp __brick_init) {
             return std::__pstl_transform_reduce<__remove_parallel_policy_t<_ExecutionPolicy>>(
                 __cpu_backend_tag{},


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154913.538887.patch
Type: text/x-patch
Size: 1979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230711/8a1603d2/attachment.bin>


More information about the libcxx-commits mailing list