Skip to content

Commit 9ec8096

Browse files
ldionnetstellar
authored andcommitted
[release/16.x][libc++] Revert the bitset sort optimization
Part of the bitset sort optimization can cause code using an invalid comparator to go out-of-bounds, which is potentially dangerous. This was an unintended consequence of the original patch, or at least the fact that we didn't have anything in place to catch that or announce that to vendors was unintended. More specifically, std::sort assumes that the comparison predicate is a strict weak order (which is a pre-condition to the algorithm). However, in practice, some predicates may not satisfy the pre-condition in subtle ways. While that is technically a user problem, we need a good answer for how to handle this given that we know this exists in the wild and unconditionally reading out-of-bounds data is not a great answer. We can't weaken the preconditions of the algorithm, however letting this situation happen without even a way of diagnosing the issue is pretty bad. Hence, this patch reverts the optimization from release/16.x so that we can buy a bit of time to figure out how to properly handle and communicate this change in the LLVM 17 release. The bitset sort optimization was 4eddbf9 (aka https://llvm.org/D122780). This patch is not a pure revert of the patch, I also fixed up the includes a bit. Differential Revision: https://reviews.llvm.org/D146421
1 parent 34e907f commit 9ec8096

File tree

2 files changed

+147
-432
lines changed

2 files changed

+147
-432
lines changed

libcxx/docs/ReleaseNotes.rst

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ Improvements and New Features
9090
now provided when implementations in the global namespace are provided by
9191
the C library.
9292
- Implemented ``<memory_resource>`` header from C++17
93-
- `D122780 <https://reviews.llvm.org/D122780>`_ Improved the performance of std::sort
9493
- The ``ranges`` versions of ``copy``, ``move``, ``copy_backward`` and ``move_backward`` are now also optimized for
9594
``std::deque<>::iterator``, which can lead to up to 20x performance improvements on certain algorithms.
9695
- The ``std`` and ``ranges`` versions of ``copy``, ``move``, ``copy_backward`` and ``move_backward`` are now also

0 commit comments

Comments
 (0)