[llvm-dev, cfe-dev] Fix failures uncovered by randomly shuffling containers before sorting

Hi,

I have a patch under review which randomly shuffles a container before calling std::sort or array_pod_sort: https://reviews.llvm.org/D39245

This is intended to uncover non-deterministic sorting order for elements with the same key.
However, the patch cannot be merged unless the failures it uncovers can be fixed - otherwise bots will start breaking as soon as it merges.

The following are the current ninja check-all failures with this patch (across all targets on an asserts build):

 Clang :: Driver/autocomplete\.c
 Clang :: Misc/diag\-template\-diffing\.cpp
 Clang :: Misc/error\-limit\-multiple\-notes\.cpp
 Clang :: OpenMP/task\_firstprivate\_codegen\.cpp
 Clang :: OpenMP/task\_private\_codegen\.cpp
 Clang :: OpenMP/taskloop\_firstprivate\_codegen\.cpp
 Clang :: OpenMP/taskloop\_lastprivate\_codegen\.cpp
 Clang :: OpenMP/taskloop\_private\_codegen\.cpp
 Clang :: OpenMP/taskloop\_simd\_firstprivate\_codegen\.cpp
 Clang :: OpenMP/taskloop\_simd\_lastprivate

1 warning(s) in tests.
_codegen.cpp
Clang :: OpenMP/taskloop_simd_private_codegen.cpp
Clang :: SemaCXX/builtin-ptrtomember-overload-1.cpp
LLVM :: CodeGen/ARM/switch-minsize.ll
LLVM :: CodeGen/Hexagon/args.ll
LLVM :: CodeGen/Hexagon/expand-condsets-basic.ll
LLVM :: CodeGen/Hexagon/gp-rel.ll
LLVM :: CodeGen/Hexagon/packetize_cond_inst.ll
LLVM :: CodeGen/Hexagon/simple_addend.ll
LLVM :: CodeGen/Hexagon/swp-matmul-bitext.ll
LLVM :: CodeGen/Hexagon/swp-stages4.ll
LLVM :: CodeGen/Hexagon/swp-vsum.ll
LLVM :: CodeGen/X86/switch-bt.ll
LLVM :: CodeGen/X86/switch-density.ll
LLVM :: CodeGen/X86/switch.ll
LLVM :: CodeGen/X86/x86-shrink-wrapping.ll
LLVM :: DebugInfo/X86/multiple-aranges.ll
LLVM :: MC/Hexagon/align.s
LLVM :: MC/Hexagon/asmMap.s
LLVM :: MC/Hexagon/bug20416.s
LLVM :: MC/Hexagon/double-vector-producer.s
LLVM :: MC/Hexagon/duplex-registers.s
LLVM :: MC/Hexagon/instructions/j.s
LLVM :: Transforms/Util/PredicateInfo/testandor.ll

I am trying to fix as many of these as possible. However, it would be much faster if you can look into the failures related to your specific areas and fix those :slight_smile:

In order to reproduce a failure you would need to apply the above patch and then change calls to std::sort and array_pod_sort with llvm::sort in the source/header files related to your test case.
Alternately, you can apply these 2 patches which convert *all* std::sort & array_pod_sort to llvm::sort:
llvm --> https://reviews.llvm.org/differential/diff/120879
clang --> https://reviews.llvm.org/differential/diff/120880

Here's the bugzilla to track this --> https://bugs.llvm.org/show_bug.cgi?id=35135

--Mandeep