[PATCH] D49621: [libFuzzer] Initial implementation of weighted mutation leveraging during runtime.

Matt Morehouse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 2 08:56:51 PDT 2018


morehouse added inline comments.


================
Comment at: lib/fuzzer/FuzzerMutate.cpp:523
   for (int Iter = 0; Iter < 100; Iter++) {
-    auto M = &Mutators[Rand(Mutators.size())];
+    // Even when use weighted mutations, fallback to the default selection in
+    // 20% of cases.
----------------
use -> using


================
Comment at: lib/fuzzer/FuzzerMutate.cpp:525
+    // 20% of cases.
+    if (Options.UseWeightedMutations && Rand(100) < 80)
+      M = &Mutators[WeightedIndex()];
----------------
Maybe  `if (... && Rand(5))` would be simpler.


================
Comment at: lib/fuzzer/FuzzerMutate.cpp:605
+  for (size_t i = 0; i < Stats.size(); i++)
+    Weights[i] = Stats[i] / SumOfStats;
+  Distribution = std::discrete_distribution<size_t>(Weights.begin(), Weights.end());
----------------
Is normalization necessary?  I think `discrete_distribution` might do this internally.


================
Comment at: lib/fuzzer/FuzzerMutate.cpp:606
+    Weights[i] = Stats[i] / SumOfStats;
+  Distribution = std::discrete_distribution<size_t>(Weights.begin(), Weights.end());
+}
----------------
I think you can do `Distribution.param(Weights)` rather than reconstructing.  Might be faster.


================
Comment at: lib/fuzzer/FuzzerMutate.h:103
 
-  void RecordUsefulMutations();
+  /// Refreshes current mutation stats recalculated based on most previous run.
+  void UpdateMutationStats();
----------------
What is the "most previous run"?  Please clarify comment


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D49621





More information about the llvm-commits mailing list