-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++][ranges] Fix ranges::join_view
segmented iterator trait
#158347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-libcxx Author: None (lbonn) ChangesThe outer iterator needs to move to the next segment when calling __compose. Without this change, Other specializations using the segmented iterator trait were likely to be affected as well. Fixes #158279, #93180 cc @philnik777 Full diff: https://github.com/llvm/llvm-project/pull/158347.diff 2 Files Affected:
diff --git a/libcxx/include/__ranges/join_view.h b/libcxx/include/__ranges/join_view.h
index 327b349f476a7..6097754f403ec 100644
--- a/libcxx/include/__ranges/join_view.h
+++ b/libcxx/include/__ranges/join_view.h
@@ -410,8 +410,12 @@ struct __segmented_iterator_traits<_JoinViewIterator> {
static constexpr _LIBCPP_HIDE_FROM_ABI _JoinViewIterator
__compose(__segment_iterator __seg_iter, __local_iterator __local_iter) {
- return _JoinViewIterator(
- std::move(__seg_iter).__get_data(), std::move(__seg_iter).__get_iter(), std::move(__local_iter));
+ auto&& __outer = std::move(__seg_iter).__get_iter();
+ if (__local_iter == ranges::end(*__outer)) {
+ ++__outer;
+ return _JoinViewIterator(*std::move(__seg_iter).__get_data(), __outer);
+ }
+ return _JoinViewIterator(std::move(__seg_iter).__get_data(), __outer, std::move(__local_iter));
}
};
diff --git a/libcxx/test/std/ranges/range.adaptors/range.join/range.join.iterator/find.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.join/range.join.iterator/find.pass.cpp
new file mode 100644
index 0000000000000..f8bee2227d0b9
--- /dev/null
+++ b/libcxx/test/std/ranges/range.adaptors/range.join/range.join.iterator/find.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+#include <algorithm>
+#include <cassert>
+#include <ranges>
+#include <type_traits>
+
+#include "../types.h"
+
+constexpr bool test() {
+ // Test the segmented iterator implementation of join_view
+ // https://github.com/llvm/llvm-project/issues/158279
+ {
+ int buffer1[2][1] = {{1}, {2}};
+ auto joined = std::views::join(buffer1);
+ assert(std::ranges::find(joined, 1) == std::ranges::begin(joined));
+ assert(std::ranges::find(joined, 2) == std::ranges::next(std::ranges::begin(joined)));
+ assert(std::ranges::find(joined, 3) == std::ranges::end(joined));
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+ static_assert(test());
+
+ return 0;
+}
|
da8fb07
to
192c920
Compare
I've moved the logic inside of the iterator itself instead of the segmented iterator trait which was meant to be kept simpler (I believe) |
Not sure what is going on with the macos failures, I don't think they are touching these changes.
They already have some XFAIL on some other linux and freebsd targets. |
libcxx/test/std/ranges/range.adaptors/range.join/range.join.iterator/find.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/ranges/range.adaptors/range.join/range.join.iterator/find.pass.cpp
Outdated
Show resolved
Hide resolved
192c920
to
d8fb715
Compare
d8fb715
to
5f3e1db
Compare
libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
Outdated
Show resolved
Hide resolved
The outer iterator needs to move to the next segment when calling __compose. Without this change, `find_segment_if` would never reach the end of the join_view which caused erroneous result when calling `ranges::find` on a join_view of bidirectional ranges.
5f3e1db
to
b41db68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Do you need me to commit this?
@philnik777 yes thank you, I would need your help for that. In my opinion it is also worth a backport, I will request it through llvmbot once it is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Merging as CI failures are unrelated.
@lbonn Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
/cherry-pick d1b5607 |
/pull-request #161008 |
@lbonn Could you make you mail address public for GitHub for next contribution(s)? We conventionally expect public mail address on GitHub.
|
@frederick-vs-ja oh no, sorry about that! I've made the change for next time. |
…vm#158347) The outer iterator needs to move to the next segment when calling __compose. Without this change, `find_segment_if` would never reach the end of the join_view which caused erroneous result when calling `ranges::find` on a join_view of bidirectional ranges. Other specializations using the segmented iterator trait were likely to be affected as well. Fixes llvm#158279 Fixes llvm#93180
…vm#158347) The outer iterator needs to move to the next segment when calling __compose. Without this change, `find_segment_if` would never reach the end of the join_view which caused erroneous result when calling `ranges::find` on a join_view of bidirectional ranges. Other specializations using the segmented iterator trait were likely to be affected as well. Fixes llvm#158279 Fixes llvm#93180 (cherry picked from commit d1b5607)
The outer iterator needs to move to the next segment when calling __compose.
Without this change,
find_segment_if
would never reach the end of the join_view which caused erroneous result when callingranges::find
on a join_view of bidirectional ranges.Other specializations using the segmented iterator trait were likely to be affected as well.
Fixes #158279
Fixes #93180