[llvm-dev] [cfe-dev] RFC: Extend UBSan with qsort checks

Marshall Clow via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 14 22:11:37 PST 2016


On Tue, Jan 12, 2016 at 10:27 PM, Yury Gribov via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

>
> As for C++11, it has for e.g. srtd::sort:
>
> "Requires: operator< (for the version with no arguments) or comp (for the
> version with a comparison argument) defines a strict weak ordering (25.4)."
>
> which also sounds like UB.


Exactly correct.
If your comparison operator does not define a SWO, then you have no
guarantees of the results. Crashes are common.

In principle, I am very much in favor of a checker like this.
Passing an invalid comparison operator is one of the most common misuses of
std::sort.

I worry about the cost, though.

-- Marshall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160114/4c967cf5/attachment.html>


More information about the llvm-dev mailing list