diff --git a/libcxx/include/__algorithm/sort.h b/libcxx/include/__algorithm/sort.h --- a/libcxx/include/__algorithm/sort.h +++ b/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) {