[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

Whisperity via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 10 07:03:40 PDT 2018


whisperity added a comment.

The basics of the heuristics look okay as comparing pointers from non-continuous block of memory is undefined, it would be worthy to check if no compiler warning (perhaps by specifying `-W -Wall -Wextra -Weverything` and various others of these enable-all flags!) is emitted if `std::sort` is instantiated for such a use case.

There is a chance for a serious false positive with the current approach! One thing which you should add as a **FIXME**, and implement in a follow-up patch. Using `std::sort`, `std::unique` and then `erase` is common technique for deduplicating a container (which in some cases might even be quicker than using, let's say `std::set` <https://stackoverflow.com/a/1041939/1428773>). In case my container contains arbitrary memory addresses (e.g. multiple things give me different stuff but might give the same thing multiple times) which I don't want to do things with more than once, I might use `sort`-`unique`-`erase` and the `sort` call will emit a report.


Repository:
  rC Clang

https://reviews.llvm.org/D50488





More information about the cfe-commits mailing list