[PATCH] D39245: [ADT] Shuffle containers before sorting to uncover non-deterministic behavior

Mandeep Singh Grang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 16:25:37 PDT 2017


mgrang added a comment.

In https://reviews.llvm.org/D39245#905733, @dexonsmith wrote:

> > std::sort and array_pod_sort both use quicksort
>
> FWIW, most standards-compliant std::sort implementations use introsort... although it's also unstable.
>
> > NOTE: To randomly shuffle before std::sort we may have to change all calls to std::sort with llvm::sort.
>
> It looks to me like the current overloads of llvm::sort take a parallel execution policy, which would be unfortunate boilerplate to add.  Perhaps you should create an overload in ADT/STLExtras.h with the same signature as std::sort (that wraps std::sort with the initial call to std::random_shuffle).


Sure, I can add overload for llvm::sort which takes ExecutionPolicy and invoke std::sort. However, it would still mean changing all calls to std::sort with llvm::sort if this feature needs to be tested. Is there a way to do this w/o changing the callers? #define std::sort llvm::sort won't work because of the double colon (::), redefining std::sort will result in duplicate definitions, etc.


Repository:
  rL LLVM

https://reviews.llvm.org/D39245





More information about the llvm-commits mailing list