]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix parallel std::exclusive_scan [PR108236]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 3 Dec 2024 16:36:05 +0000 (16:36 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 3 Dec 2024 21:34:26 +0000 (21:34 +0000)
commitcd107a6343c96c4ef26096e250d43a4a4211eced
treec2ea5aa63af2d981be6ae67f76e2f772d482113f
parentaa7acf6fc9251cc9bdb9a406dc58439eb54e1217
libstdc++: Fix parallel std::exclusive_scan [PR108236]

The standard says that std::exclusive_scan can be used to work in
place, i.e. where the output range is the same as the input range. This
means that the first sum cannot be written to the output until after
reading the first input value, otherwise we'll already have overwritten
the first input value.

While writing a new testcase I also realised that the serial version of
std::exclusive_scan uses copy construction for the accumulator variable,
but the standard only requires Cpp17MoveConstructible. We also require
move assignable, which is missing from the standard's requirements, but
we should at least use move construction not copy construction.

A similar problem exists for some other new C++17 numeric algos, but
I'll fix the others in a subsequent commit.

libstdc++-v3/ChangeLog:

PR libstdc++/108236
* include/pstl/glue_numeric_impl.h (exclusive_scan): Pass __init
as rvalue.
* include/pstl/numeric_impl.h (__brick_transform_scan): Do not
write through __result until after reading through __first. Move
__init into return value.
(__pattern_transform_scan): Pass __init as rvalue.
* include/std/numeric (exclusive_scan): Move construct instead
of copy constructing.
* testsuite/26_numerics/exclusive_scan/2.cc: New test.
* testsuite/26_numerics/pstl/numeric_ops/108236.cc: New test.
libstdc++-v3/include/pstl/glue_numeric_impl.h
libstdc++-v3/include/pstl/numeric_impl.h
libstdc++-v3/include/std/numeric
libstdc++-v3/testsuite/26_numerics/exclusive_scan/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/26_numerics/pstl/numeric_ops/108236.cc [new file with mode: 0644]