[PATCH] D50356: [libFuzzer] Use std::discrete_distribution for input selection.

Matt Morehouse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 16 17:14:05 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT339973: [libFuzzer] Use std::discrete_distribution for input selection. (authored by morehouse, committed by ).
Herald added a subscriber: Sanitizers.

Changed prior to commit:
  https://reviews.llvm.org/D50356?vs=159371&id=161146#toc

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D50356

Files:
  lib/fuzzer/FuzzerCorpus.h


Index: lib/fuzzer/FuzzerCorpus.h
===================================================================
--- lib/fuzzer/FuzzerCorpus.h
+++ 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.161146.patch
Type: text/x-patch
Size: 1395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180817/bbbbc10d/attachment.bin>


More information about the llvm-commits mailing list