From be57e8e328696870abf4cf168e80114710476552 Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Fri, 17 Aug 2018 01:30:27 +0000 Subject: [PATCH] Revert "[libFuzzer] Use std::discrete_distribution for input selection." This reverts r339973 due to msan.test failing on sanitizer-x86_64-linux-fuzzer bot. llvm-svn: 339976 --- compiler-rt/lib/fuzzer/FuzzerCorpus.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler-rt/lib/fuzzer/FuzzerCorpus.h b/compiler-rt/lib/fuzzer/FuzzerCorpus.h index 11f5f1baf0da..8ad14656cffc 100644 --- a/compiler-rt/lib/fuzzer/FuzzerCorpus.h +++ b/compiler-rt/lib/fuzzer/FuzzerCorpus.h @@ -174,7 +174,7 @@ class InputCorpus { // Returns an index of random unit from the corpus to mutate. size_t ChooseUnitIdxToMutate(Random &Rand) { - size_t Idx = CorpusDistribution(Rand); + size_t Idx = static_cast(CorpusDistribution(Rand)); assert(Idx < Inputs.size()); return Idx; } @@ -276,7 +276,9 @@ private: void UpdateCorpusDistribution() { size_t N = Inputs.size(); assert(N); + Intervals.resize(N + 1); Weights.resize(N); + std::iota(Intervals.begin(), Intervals.end(), 0); for (size_t i = 0; i < N; i++) Weights[i] = Inputs[i]->NumFeatures ? (i + 1) * (Inputs[i]->HasFocusFunction ? 1000 : 1) @@ -289,11 +291,12 @@ private: Printf("%f ", Weights[i]); Printf("Weights\n"); } - CorpusDistribution = - std::discrete_distribution(Weights.begin(), Weights.end()); + CorpusDistribution = std::piecewise_constant_distribution( + Intervals.begin(), Intervals.end(), Weights.begin()); } - std::discrete_distribution CorpusDistribution; + std::piecewise_constant_distribution CorpusDistribution; + Vector Intervals; Vector Weights; std::unordered_set Hashes;