From: Matt Morehouse Date: Fri, 17 Aug 2018 00:13:22 +0000 (+0000) Subject: [libFuzzer] Use std::discrete_distribution for input selection. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0094d31f5b51691994f38c5de85c4a962fb75b61;p=platform%2Fupstream%2Fllvm.git [libFuzzer] Use std::discrete_distribution for input selection. Summary: Since we're casting from double to size_t during input selection, we really want a discrete distribution over size_t rather than a piecewise distribution over doubles. Reviewers: kcc Reviewed By: kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D50356 llvm-svn: 339973 --- diff --git a/compiler-rt/lib/fuzzer/FuzzerCorpus.h b/compiler-rt/lib/fuzzer/FuzzerCorpus.h index 8ad1465..11f5f1b 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 = static_cast(CorpusDistribution(Rand)); + size_t Idx = CorpusDistribution(Rand); assert(Idx < Inputs.size()); return Idx; } @@ -276,9 +276,7 @@ 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) @@ -291,12 +289,11 @@ private: Printf("%f ", Weights[i]); Printf("Weights\n"); } - CorpusDistribution = std::piecewise_constant_distribution( - Intervals.begin(), Intervals.end(), Weights.begin()); + CorpusDistribution = + std::discrete_distribution(Weights.begin(), Weights.end()); } - std::piecewise_constant_distribution CorpusDistribution; + std::discrete_distribution CorpusDistribution; - Vector Intervals; Vector Weights; std::unordered_set Hashes;