[libcxx-commits] [PATCH] D157065: [libc++] Fix std::layout_left::stride(r)

Christian Trott via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 3 20:40:43 PDT 2023


crtrott created this revision.
crtrott added a reviewer: libc++.
crtrott added a project: libc++.
Herald added a project: All.
crtrott requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.

The function was using the stride calculation for layout_right not layout_left. And the test was also testing for layout_right ...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157065

Files:
  libcxx/include/__mdspan/layout_left.h
  libcxx/test/std/containers/views/mdspan/layout_left/stride.pass.cpp


Index: libcxx/test/std/containers/views/mdspan/layout_left/stride.pass.cpp
===================================================================
--- libcxx/test/std/containers/views/mdspan/layout_left/stride.pass.cpp
+++ libcxx/test/std/containers/views/mdspan/layout_left/stride.pass.cpp
@@ -39,8 +39,8 @@
   constexpr size_t D = std::dynamic_extent;
   test_stride<std::extents<unsigned, D>>(std::array<unsigned, 1>{1}, 7);
   test_stride<std::extents<unsigned, 7>>(std::array<unsigned, 1>{1});
-  test_stride<std::extents<unsigned, 7, 8>>(std::array<unsigned, 2>{8, 1});
-  test_stride<std::extents<int64_t, D, 8, D, D>>(std::array<int64_t, 4>{720, 90, 10, 1}, 7, 9, 10);
+  test_stride<std::extents<unsigned, 7, 8>>(std::array<unsigned, 2>{1, 7});
+  test_stride<std::extents<int64_t, D, 8, D, D>>(std::array<int64_t, 4>{1, 7, 56, 504}, 7, 9, 10);
   return true;
 }
 
Index: libcxx/include/__mdspan/layout_left.h
===================================================================
--- libcxx/include/__mdspan/layout_left.h
+++ libcxx/include/__mdspan/layout_left.h
@@ -164,7 +164,7 @@
     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
         __r < extents_type::rank(), "layout_left::mapping::stride(): invalid rank index");
     index_type __s = 1;
-    for (rank_type __i = extents_type::rank() - 1; __i > __r; __i--)
+    for (rank_type __i = 0; __i < __r; __i++)
       __s *= __extents_.extent(__i);
     return __s;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157065.547095.patch
Type: text/x-patch
Size: 1424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230804/f1e7e164/attachment.bin>


More information about the libcxx-commits mailing list