[llvm] r294366 - [libFuzzer] replace std::random_shuffle with std::shuffle as std::random_shuffle is being deprecated in C++17. Also simplify fuzzer::Random. NFC
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 7 14:37:34 PST 2017
Author: kcc
Date: Tue Feb 7 16:37:34 2017
New Revision: 294366
URL: http://llvm.org/viewvc/llvm-project?rev=294366&view=rev
Log:
[libFuzzer] replace std::random_shuffle with std::shuffle as std::random_shuffle is being deprecated in C++17. Also simplify fuzzer::Random. NFC
Modified:
llvm/trunk/lib/Fuzzer/FuzzerCorpus.h
llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp
llvm/trunk/lib/Fuzzer/FuzzerRandom.h
Modified: llvm/trunk/lib/Fuzzer/FuzzerCorpus.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerCorpus.h?rev=294366&r1=294365&r2=294366&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerCorpus.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerCorpus.h Tue Feb 7 16:37:34 2017
@@ -97,7 +97,7 @@ class InputCorpus {
// Hypothesis: units added to the corpus last are more likely to be
// interesting. This function gives more weight to the more recent units.
size_t ChooseUnitIdxToMutate(Random &Rand) {
- size_t Idx = static_cast<size_t>(CorpusDistribution(Rand.Get_mt19937()));
+ size_t Idx = static_cast<size_t>(CorpusDistribution(Rand));
assert(Idx < Inputs.size());
return Idx;
}
Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=294366&r1=294365&r2=294366&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Tue Feb 7 16:37:34 2017
@@ -460,7 +460,7 @@ void Fuzzer::RereadOutputCorpus(size_t M
}
void Fuzzer::ShuffleCorpus(UnitVector *V) {
- std::random_shuffle(V->begin(), V->end(), MD.GetRand());
+ std::shuffle(V->begin(), V->end(), MD.GetRand());
if (Options.PreferSmall)
std::stable_sort(V->begin(), V->end(), [](const Unit &A, const Unit &B) {
return A.size() < B.size();
Modified: llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp?rev=294366&r1=294365&r2=294366&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp Tue Feb 7 16:37:34 2017
@@ -99,8 +99,7 @@ size_t MutationDispatcher::Mutate_Shuffl
Rand(std::min(Size, (size_t)8)) + 1; // [1,8] and <= Size.
size_t ShuffleStart = Rand(Size - ShuffleAmount);
assert(ShuffleStart + ShuffleAmount <= Size);
- std::random_shuffle(Data + ShuffleStart, Data + ShuffleStart + ShuffleAmount,
- Rand);
+ std::shuffle(Data + ShuffleStart, Data + ShuffleStart + ShuffleAmount, Rand);
return Size;
}
Modified: llvm/trunk/lib/Fuzzer/FuzzerRandom.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerRandom.h?rev=294366&r1=294365&r2=294366&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerRandom.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerRandom.h Tue Feb 7 16:37:34 2017
@@ -15,10 +15,11 @@
#include <random>
namespace fuzzer {
-class Random {
+class Random : public std::mt19937 {
public:
- Random(unsigned int seed) : R(seed) {}
- size_t Rand() { return R(); }
+ Random(unsigned int seed) : std::mt19937(seed) {}
+ result_type operator()() { return this->std::mt19937::operator()(); }
+ size_t Rand() { return this->operator()(); }
size_t RandBool() { return Rand() % 2; }
size_t operator()(size_t n) { return n ? Rand() % n : 0; }
intptr_t operator()(intptr_t From, intptr_t To) {
@@ -26,9 +27,6 @@ class Random {
intptr_t RangeSize = To - From + 1;
return operator()(RangeSize) + From;
}
- std::mt19937 &Get_mt19937() { return R; }
- private:
- std::mt19937 R;
};
} // namespace fuzzer
More information about the llvm-commits
mailing list