[llvm] r299180 - [libFuzzer] simplify the code a bit
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 30 21:17:46 PDT 2017
Author: kcc
Date: Thu Mar 30 23:17:45 2017
New Revision: 299180
URL: http://llvm.org/viewvc/llvm-project?rev=299180&view=rev
Log:
[libFuzzer] simplify the code a bit
Modified:
llvm/trunk/lib/Fuzzer/FuzzerCorpus.h
llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
Modified: llvm/trunk/lib/Fuzzer/FuzzerCorpus.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerCorpus.h?rev=299180&r1=299179&r2=299180&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerCorpus.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerCorpus.h Thu Mar 30 23:17:45 2017
@@ -133,7 +133,7 @@ class InputCorpus {
Printf("EVICTED %zd\n", Idx);
}
- bool AddFeature(size_t Idx, uint32_t NewSize, bool Shrink) {
+ void AddFeature(size_t Idx, uint32_t NewSize, bool Shrink) {
assert(NewSize);
Idx = Idx % kFeatureSetSize;
uint32_t OldSize = GetFeature(Idx);
@@ -148,17 +148,17 @@ class InputCorpus {
} else {
NumAddedFeatures++;
}
+ NumUpdatedFeatures++;
if (FeatureDebug)
Printf("ADD FEATURE %zd sz %d\n", Idx, NewSize);
SmallestElementPerFeature[Idx] = Inputs.size();
InputSizesPerFeature[Idx] = NewSize;
CountingFeatures = true;
- return true;
}
- return false;
}
size_t NumFeatures() const { return NumAddedFeatures; }
+ size_t NumFeatureUpdates() const { return NumUpdatedFeatures; }
void ResetFeatureSet() {
assert(Inputs.empty());
@@ -212,6 +212,7 @@ private:
bool CountingFeatures = false;
size_t NumAddedFeatures = 0;
+ size_t NumUpdatedFeatures = 0;
uint32_t InputSizesPerFeature[kFeatureSetSize];
uint32_t SmallestElementPerFeature[kFeatureSetSize];
Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=299180&r1=299179&r2=299180&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Thu Mar 30 23:17:45 2017
@@ -407,11 +407,11 @@ size_t Fuzzer::RunOne(const uint8_t *Dat
ExecuteCallback(Data, Size);
- size_t Res = 0;
- if (size_t NumFeatures = TPC.CollectFeatures([&](size_t Feature) -> bool {
- return Corpus.AddFeature(Feature, Size, Options.Shrink);
- }))
- Res = NumFeatures;
+ size_t NumUpdatesBefore = Corpus.NumFeatureUpdates();
+ TPC.CollectFeatures([&](size_t Feature) {
+ Corpus.AddFeature(Feature, Size, Options.Shrink);
+ });
+ size_t NumUpdatesAfter = Corpus.NumFeatureUpdates();
auto TimeOfUnit =
duration_cast<seconds>(UnitStopTime - UnitStartTime).count();
@@ -424,7 +424,7 @@ size_t Fuzzer::RunOne(const uint8_t *Dat
Printf("Slowest unit: %zd s:\n", TimeOfLongestUnitInSeconds);
WriteUnitToFileWithPrefix({Data, Data + Size}, "slow-unit-");
}
- return Res;
+ return NumUpdatesAfter - NumUpdatesBefore;
}
size_t Fuzzer::GetCurrentUnitInFuzzingThead(const uint8_t **Data) const {
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.h?rev=299180&r1=299179&r2=299180&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.h Thu Mar 30 23:17:45 2017
@@ -58,7 +58,7 @@ class TracePC {
void SetUseCounters(bool UC) { UseCounters = UC; }
void SetUseValueProfile(bool VP) { UseValueProfile = VP; }
void SetPrintNewPCs(bool P) { DoPrintNewPCs = P; }
- template <class Callback> size_t CollectFeatures(Callback CB) const;
+ template <class Callback> void CollectFeatures(Callback CB) const;
void ResetMaps() {
ValueProfileMap.Reset();
@@ -129,8 +129,7 @@ void ForEachNonZeroByte(const uint8_t *B
template <class Callback> // bool Callback(size_t Feature)
ATTRIBUTE_NO_SANITIZE_ALL
__attribute__((noinline))
-size_t TracePC::CollectFeatures(Callback HandleFeature) const {
- size_t Res = 0;
+void TracePC::CollectFeatures(Callback HandleFeature) const {
uint8_t *Counters = this->Counters();
size_t N = GetNumPCs();
auto Handle8bitCounter = [&](size_t Idx, uint8_t Counter) {
@@ -143,8 +142,7 @@ size_t TracePC::CollectFeatures(Callback
else if (Counter >= 4) Bit = 3;
else if (Counter >= 3) Bit = 2;
else if (Counter >= 2) Bit = 1;
- if (HandleFeature(Idx * 8 + Bit))
- Res++;
+ HandleFeature(Idx * 8 + Bit);
};
ForEachNonZeroByte(Counters, Counters + N, 0, Handle8bitCounter);
@@ -153,10 +151,8 @@ size_t TracePC::CollectFeatures(Callback
if (UseValueProfile)
ValueProfileMap.ForEach([&](size_t Idx) {
- if (HandleFeature(N * 8 + Idx))
- Res++;
+ HandleFeature(N * 8 + Idx);
});
- return Res;
}
extern TracePC TPC;
More information about the llvm-commits
mailing list