summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2017-02-07 22:37:34 +0000
committerKostya Serebryany <kcc@google.com>2017-02-07 22:37:34 +0000
commit6ac64c3a6da5dc0d2380a130919caa9055cb3765 (patch)
treea8f2e67ad55dd302347079808e2d7692b0dda964 /llvm/lib/Fuzzer
parent39c138cc765f76b9f52d33b23bd02a66d7a4bdc1 (diff)
downloadbcm5719-llvm-6ac64c3a6da5dc0d2380a130919caa9055cb3765.tar.gz
bcm5719-llvm-6ac64c3a6da5dc0d2380a130919caa9055cb3765.zip
[libFuzzer] replace std::random_shuffle with std::shuffle as std::random_shuffle is being deprecated in C++17. Also simplify fuzzer::Random. NFC
llvm-svn: 294366
Diffstat (limited to 'llvm/lib/Fuzzer')
-rw-r--r--llvm/lib/Fuzzer/FuzzerCorpus.h2
-rw-r--r--llvm/lib/Fuzzer/FuzzerLoop.cpp2
-rw-r--r--llvm/lib/Fuzzer/FuzzerMutate.cpp3
-rw-r--r--llvm/lib/Fuzzer/FuzzerRandom.h10
4 files changed, 7 insertions, 10 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerCorpus.h b/llvm/lib/Fuzzer/FuzzerCorpus.h
index 468d5e5ddc7..8c2f7039280 100644
--- a/llvm/lib/Fuzzer/FuzzerCorpus.h
+++ b/llvm/lib/Fuzzer/FuzzerCorpus.h
@@ -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;
}
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp
index 8f4161ebe98..d15f2e20df4 100644
--- a/llvm/lib/Fuzzer/FuzzerLoop.cpp
+++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp
@@ -460,7 +460,7 @@ void Fuzzer::RereadOutputCorpus(size_t MaxSize) {
}
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();
diff --git a/llvm/lib/Fuzzer/FuzzerMutate.cpp b/llvm/lib/Fuzzer/FuzzerMutate.cpp
index 6b1ac4e3b0b..7c7e6688aa7 100644
--- a/llvm/lib/Fuzzer/FuzzerMutate.cpp
+++ b/llvm/lib/Fuzzer/FuzzerMutate.cpp
@@ -99,8 +99,7 @@ size_t MutationDispatcher::Mutate_ShuffleBytes(uint8_t *Data, size_t Size,
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;
}
diff --git a/llvm/lib/Fuzzer/FuzzerRandom.h b/llvm/lib/Fuzzer/FuzzerRandom.h
index b1be0bb935f..8a1aa3ef5fd 100644
--- a/llvm/lib/Fuzzer/FuzzerRandom.h
+++ b/llvm/lib/Fuzzer/FuzzerRandom.h
@@ -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
OpenPOWER on IntegriCloud