[libcxx-commits] [PATCH] D146421: [libc++] Disable the __insertion_sort_unguarded optimization

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 20 08:28:59 PDT 2023


ldionne updated this revision to Diff 506603.
ldionne added a comment.

Fix clang-tidy


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146421/new/

https://reviews.llvm.org/D146421

Files:
  libcxx/include/__algorithm/sort.h


Index: libcxx/include/__algorithm/sort.h
===================================================================
--- libcxx/include/__algorithm/sort.h
+++ libcxx/include/__algorithm/sort.h
@@ -737,11 +737,18 @@
     }
     // Use insertion sort if the length of the range is below the specified limit.
     if (__len < __limit) {
+      // TODO: Invalid comparison predicates can cause __insertion_sort_unguarded to go out-of-bounds, which is
+      //       highly undesirable. Disable the __insertion_sort_unguarded optimization until we at least have a
+      //       way to assert that we're not going out of bounds.
+#if 1
+      std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
+#else
       if (__leftmost) {
         std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
       } else {
         std::__insertion_sort_unguarded<_AlgPolicy, _Compare>(__first, __last, __comp);
       }
+#endif
       return;
     }
     if (__depth == 0) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146421.506603.patch
Type: text/x-patch
Size: 982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230320/09646e46/attachment-0001.bin>


More information about the libcxx-commits mailing list