[PATCH] D50356: [libFuzzer] Use std::discrete_distribution for input selection.
Matt Morehouse via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 6 12:54:07 PDT 2018
morehouse created this revision.
morehouse added a reviewer: kcc.
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.
https://reviews.llvm.org/D50356
Files:
compiler-rt/lib/fuzzer/FuzzerCorpus.h
Index: compiler-rt/lib/fuzzer/FuzzerCorpus.h
===================================================================
--- compiler-rt/lib/fuzzer/FuzzerCorpus.h
+++ compiler-rt/lib/fuzzer/FuzzerCorpus.h
@@ -174,7 +174,7 @@
// Returns an index of random unit from the corpus to mutate.
size_t ChooseUnitIdxToMutate(Random &Rand) {
- size_t Idx = static_cast<size_t>(CorpusDistribution(Rand));
+ size_t Idx = CorpusDistribution(Rand);
assert(Idx < Inputs.size());
return Idx;
}
@@ -276,9 +276,7 @@
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 @@
Printf("%f ", Weights[i]);
Printf("Weights\n");
}
- CorpusDistribution = std::piecewise_constant_distribution<double>(
- Intervals.begin(), Intervals.end(), Weights.begin());
+ CorpusDistribution =
+ std::discrete_distribution<size_t>(Weights.begin(), Weights.end());
}
- std::piecewise_constant_distribution<double> CorpusDistribution;
+ std::discrete_distribution<size_t> CorpusDistribution;
- Vector<double> Intervals;
Vector<double> Weights;
std::unordered_set<std::string> Hashes;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50356.159371.patch
Type: text/x-patch
Size: 1431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180806/4097d340/attachment.bin>
More information about the llvm-commits
mailing list