* [committed 1/2] libstdc++: Avoid reusing moved-from iterators in PSTL tests [PR90276]
@ 2024-02-02 10:28 Jonathan Wakely
2024-02-02 10:28 ` [committed 2/2] libstdc++: Fix invalid order in PSTL inplace_merge test [PR90276] Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2024-02-02 10:28 UTC (permalink / raw)
To: libstdc++, gcc-patches; +Cc: François Dumont
Tested x86_64-linux. Pushed to trunk.
-- >8 --
The reverse_invoker utility for PSTL tests uses forwarding references for
all parameters, but some of those parameters get forwarded to move
constructors which then leave the objects in a moved-from state. When
the parameters are forwarded a second time that results in making new
copies of moved-from iterators. For libstdc++ debug mode iterators, the
moved-from state is singular, which means copying them will abort at
runtime.
The fix is to make copies of iterator arguments instead of forwarding
them.
The callers of reverse_invoker::operator() also forward the iterators
multiple times, but that's OK because reverse_invoker accepts them by
forwarding reference but then breaks the chain of forwarding and copies
them as lvalues.
libstdc++-v3/ChangeLog:
PR libstdc++/90276
* testsuite/util/pstl/test_utils.h (reverse_invoker): Do not use
perfect forwarding for iterator arguments.
---
libstdc++-v3/testsuite/util/pstl/test_utils.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libstdc++-v3/testsuite/util/pstl/test_utils.h b/libstdc++-v3/testsuite/util/pstl/test_utils.h
index ed6d48b9471..e35084eabb2 100644
--- a/libstdc++-v3/testsuite/util/pstl/test_utils.h
+++ b/libstdc++-v3/testsuite/util/pstl/test_utils.h
@@ -1083,18 +1083,18 @@ struct iterator_invoker<std::forward_iterator_tag, /*isReverse=*/std::true_type>
template <typename IsReverse>
struct reverse_invoker
{
- template <typename... Rest>
+ template <typename Policy, typename Op, typename... Rest>
void
- operator()(Rest&&... rest)
+ operator()(Policy&& exec, Op op, Rest&&... rest)
{
// Random-access iterator
- iterator_invoker<std::random_access_iterator_tag, IsReverse>()(std::forward<Rest>(rest)...);
+ iterator_invoker<std::random_access_iterator_tag, IsReverse>()(std::forward<Policy>(exec), op, rest...);
// Forward iterator
- iterator_invoker<std::forward_iterator_tag, IsReverse>()(std::forward<Rest>(rest)...);
+ iterator_invoker<std::forward_iterator_tag, IsReverse>()(std::forward<Policy>(exec), op, rest...);
// Bidirectional iterator
- iterator_invoker<std::bidirectional_iterator_tag, IsReverse>()(std::forward<Rest>(rest)...);
+ iterator_invoker<std::bidirectional_iterator_tag, IsReverse>()(std::forward<Policy>(exec), op, rest...);
}
};
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* [committed 2/2] libstdc++: Fix invalid order in PSTL inplace_merge test [PR90276]
2024-02-02 10:28 [committed 1/2] libstdc++: Avoid reusing moved-from iterators in PSTL tests [PR90276] Jonathan Wakely
@ 2024-02-02 10:28 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2024-02-02 10:28 UTC (permalink / raw)
To: libstdc++, gcc-patches; +Cc: François Dumont
Tested x86_64-linux. Pushed to trunk.
-- >8 --
This looks like a typo in the upstream test that causes a failure in
debug mode. It has been reported upstream.
libstdc++-v3/ChangeLog:
PR libstdc++/90276
* testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc: Fix
comparison function to use less-than instead of equality.
---
.../testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc
index 576f22423b8..a9205553574 100644
--- a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc
@@ -160,7 +160,7 @@ main()
test_by_type<MemoryChecker>(
[](std::size_t idx){ return MemoryChecker{std::int32_t(idx * 2)}; },
[](std::size_t idx){ return MemoryChecker{std::int32_t(idx * 2 + 1)}; },
- [](const MemoryChecker& val1, const MemoryChecker& val2){ return val1.value() == val2.value(); });
+ [](const MemoryChecker& val1, const MemoryChecker& val2){ return val1.value() < val2.value(); });
EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from inplace_merge: number of ctors calls < num of dtors calls");
EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from inplace_merge: number of ctors calls > num of dtors calls");
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-02 10:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02 10:28 [committed 1/2] libstdc++: Avoid reusing moved-from iterators in PSTL tests [PR90276] Jonathan Wakely
2024-02-02 10:28 ` [committed 2/2] libstdc++: Fix invalid order in PSTL inplace_merge test [PR90276] 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).