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

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 16:32:55 PDT 2017


dexonsmith added a comment.

In https://reviews.llvm.org/D39245#905862, @mgrang wrote:

> 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.


You mean, add an overload that does not take ExecutionPolicy?

> 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.

I think the best thing to do is to update the callers to call `llvm::sort` instead of `std::sort`.


Repository:
  rL LLVM

https://reviews.llvm.org/D39245





More information about the llvm-commits mailing list