mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
Avoid shuffle self-assignment in EXPENSIVE_CHECKS builds
Some versions of libstdc++ perform self-assignment in std::shuffle. This breaks the EXPENSIVE_CHECKS builds of TableGen due to an incorrect assertion in libstdc++. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85828. Fixes https://llvm.org/PR37652 Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D98167
This commit is contained in:
parent
6ae0a3f9c3
commit
b4fdf05aa0
@ -1332,8 +1332,15 @@ template <class Iterator, class RNG>
|
|||||||
void shuffle(Iterator first, Iterator last, RNG &&g) {
|
void shuffle(Iterator first, Iterator last, RNG &&g) {
|
||||||
// It would be better to use a std::uniform_int_distribution,
|
// It would be better to use a std::uniform_int_distribution,
|
||||||
// but that would be stdlib dependent.
|
// but that would be stdlib dependent.
|
||||||
for (auto size = last - first; size > 1; ++first, (void)--size)
|
typedef
|
||||||
std::iter_swap(first, first + g() % size);
|
typename std::iterator_traits<Iterator>::difference_type difference_type;
|
||||||
|
for (auto size = last - first; size > 1; ++first, (void)--size) {
|
||||||
|
difference_type offset = g() % size;
|
||||||
|
// Avoid self-assignment due to incorrect assertions in libstdc++
|
||||||
|
// containers (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85828).
|
||||||
|
if (offset != difference_type(0))
|
||||||
|
std::iter_swap(first, first + offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the length of an array.
|
/// Find the length of an array.
|
||||||
@ -1373,7 +1380,7 @@ inline unsigned presortShuffleEntropy() {
|
|||||||
template <class IteratorTy>
|
template <class IteratorTy>
|
||||||
inline void presortShuffle(IteratorTy Start, IteratorTy End) {
|
inline void presortShuffle(IteratorTy Start, IteratorTy End) {
|
||||||
std::mt19937 Generator(presortShuffleEntropy());
|
std::mt19937 Generator(presortShuffleEntropy());
|
||||||
std::shuffle(Start, End, Generator);
|
llvm::shuffle(Start, End, Generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace detail
|
} // end namespace detail
|
||||||
|
@ -41,7 +41,7 @@ BugDriver::runManyPasses(const std::vector<std::string> &AllPasses) {
|
|||||||
//
|
//
|
||||||
// Step 1: Randomize the order of the optimizer passes.
|
// Step 1: Randomize the order of the optimizer passes.
|
||||||
//
|
//
|
||||||
std::shuffle(PassesToRun.begin(), PassesToRun.end(), randomness);
|
llvm::shuffle(PassesToRun.begin(), PassesToRun.end(), randomness);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Step 2: Run optimizer passes on the program and check for success.
|
// Step 2: Run optimizer passes on the program and check for success.
|
||||||
|
@ -92,7 +92,7 @@ template <typename ElTy> struct ListReducer {
|
|||||||
// distribution (improving the speed of convergence).
|
// distribution (improving the speed of convergence).
|
||||||
if (ShufflingEnabled && NumOfIterationsWithoutProgress > MaxIterations) {
|
if (ShufflingEnabled && NumOfIterationsWithoutProgress > MaxIterations) {
|
||||||
std::vector<ElTy> ShuffledList(TheList);
|
std::vector<ElTy> ShuffledList(TheList);
|
||||||
std::shuffle(ShuffledList.begin(), ShuffledList.end(), randomness);
|
llvm::shuffle(ShuffledList.begin(), ShuffledList.end(), randomness);
|
||||||
errs() << "\n\n*** Testing shuffled set...\n\n";
|
errs() << "\n\n*** Testing shuffled set...\n\n";
|
||||||
// Check that random shuffle doesn't lose the bug
|
// Check that random shuffle doesn't lose the bug
|
||||||
Expected<TestResult> Result = doTest(ShuffledList, empty);
|
Expected<TestResult> Result = doTest(ShuffledList, empty);
|
||||||
|
@ -42,7 +42,7 @@ computeAliasingInstructions(const LLVMState &State, const Instruction *Instr,
|
|||||||
std::vector<unsigned> Opcodes;
|
std::vector<unsigned> Opcodes;
|
||||||
Opcodes.resize(State.getInstrInfo().getNumOpcodes());
|
Opcodes.resize(State.getInstrInfo().getNumOpcodes());
|
||||||
std::iota(Opcodes.begin(), Opcodes.end(), 0U);
|
std::iota(Opcodes.begin(), Opcodes.end(), 0U);
|
||||||
std::shuffle(Opcodes.begin(), Opcodes.end(), randomGenerator());
|
llvm::shuffle(Opcodes.begin(), Opcodes.end(), randomGenerator());
|
||||||
|
|
||||||
std::vector<const Instruction *> AliasingInstructions;
|
std::vector<const Instruction *> AliasingInstructions;
|
||||||
for (const unsigned OtherOpcode : Opcodes) {
|
for (const unsigned OtherOpcode : Opcodes) {
|
||||||
|
@ -718,7 +718,7 @@ static void IntroduceControlFlow(Function *F, Random &R) {
|
|||||||
BoolInst.push_back(&Instr);
|
BoolInst.push_back(&Instr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shuffle(BoolInst.begin(), BoolInst.end(), R);
|
llvm::shuffle(BoolInst.begin(), BoolInst.end(), R);
|
||||||
|
|
||||||
for (auto *Instr : BoolInst) {
|
for (auto *Instr : BoolInst) {
|
||||||
BasicBlock *Curr = Instr->getParent();
|
BasicBlock *Curr = Instr->getParent();
|
||||||
|
Loading…
Reference in New Issue
Block a user