Index: lib/fuzzer/FuzzerTracePC.h =================================================================== --- lib/fuzzer/FuzzerTracePC.h +++ lib/fuzzer/FuzzerTracePC.h @@ -178,6 +178,9 @@ Set ObservedPCs; Set ObservedFuncs; + template + void IterateInline8bitCounters(Callback CB) const; + std::pair FocusFunction = {-1, -1}; // Module and PC IDs. ValueBitMap ValueProfileMap; Index: lib/fuzzer/FuzzerTracePC.cpp =================================================================== --- lib/fuzzer/FuzzerTracePC.cpp +++ lib/fuzzer/FuzzerTracePC.cpp @@ -57,9 +57,8 @@ return Res; } -// Initializes unstable counters by copying Inline8bitCounters to unstable -// counters. -void TracePC::InitializeUnstableCounters() { +template +void TracePC::IterateInline8bitCounters(CallBack CB) const { if (NumInline8bitCounters && NumInline8bitCounters == NumPCsInPCTables) { size_t UnstableIdx = 0; for (size_t i = 0; i < NumModulesWithInline8bitCounters; i++) { @@ -67,26 +66,27 @@ size_t Size = ModuleCounters[i].Stop - Beg; assert(Size == (size_t)(ModulePCTable[i].Stop - ModulePCTable[i].Start)); for (size_t j = 0; j < Size; j++, UnstableIdx++) - if (UnstableCounters[UnstableIdx] != kUnstableCounter) - UnstableCounters[UnstableIdx] = Beg[j]; + CB(UnstableIdx, &Beg[j]); } } } +// Initializes unstable counters by copying Inline8bitCounters to unstable +// counters. +void TracePC::InitializeUnstableCounters() { + IterateInline8bitCounters([&](int UnstableIdx, uint8_t *Counter) { + if (UnstableCounters[UnstableIdx] != kUnstableCounter) + UnstableCounters[UnstableIdx] = *Counter; + }); +} + // Compares the current counters with counters from previous runs // and records differences as unstable edges. void TracePC::UpdateUnstableCounters() { - if (NumInline8bitCounters && NumInline8bitCounters == NumPCsInPCTables) { - size_t UnstableIdx = 0; - for (size_t i = 0; i < NumModulesWithInline8bitCounters; i++) { - uint8_t *Beg = ModuleCounters[i].Start; - size_t Size = ModuleCounters[i].Stop - Beg; - assert(Size == (size_t)(ModulePCTable[i].Stop - ModulePCTable[i].Start)); - for (size_t j = 0; j < Size; j++, UnstableIdx++) - if (Beg[j] != UnstableCounters[UnstableIdx]) - UnstableCounters[UnstableIdx] = kUnstableCounter; - } - } + IterateInline8bitCounters([&](int UnstableIdx, uint8_t *Counter) { + if (*Counter != UnstableCounters[UnstableIdx]) + UnstableCounters[UnstableIdx] = kUnstableCounter; + }); } void TracePC::HandleInline8bitCountersInit(uint8_t *Start, uint8_t *Stop) {