[compiler-rt] r337403 - [libFuzzer] Create single template for visiting Inline8bitCounters
Max Moroz via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 18 10:03:28 PDT 2018
Author: dor1s
Date: Wed Jul 18 10:03:27 2018
New Revision: 337403
URL: http://llvm.org/viewvc/llvm-project?rev=337403&view=rev
Log:
[libFuzzer] Create single template for visiting Inline8bitCounters
Summary:
Created IterateInline8bitCounters, a single template for visiting Inline8bitCounters (nested for loop)
Made InitializeUnstableCounters and UpdateUnstableCounters both send a lambda to IterateInline8bitCounters.
Patch by Kyungtak Woo (@kevinwkt).
Reviewers: Dor1s, metzman, kcc, morehouse
Reviewed By: metzman, morehouse
Subscribers: delcypher, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D49453
Modified:
compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp
compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp?rev=337403&r1=337402&r2=337403&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp Wed Jul 18 10:03:27 2018
@@ -57,36 +57,36 @@ size_t TracePC::GetTotalPCCoverage() {
return Res;
}
-// Initializes unstable counters by copying Inline8bitCounters to unstable
-// counters.
-void TracePC::InitializeUnstableCounters() {
+template<class CallBack>
+void TracePC::IterateInline8bitCounters(CallBack CB) const {
if (NumInline8bitCounters && NumInline8bitCounters == NumPCsInPCTables) {
- size_t UnstableIdx = 0;
+ size_t CounterIdx = 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 (UnstableCounters[UnstableIdx] != kUnstableCounter)
- UnstableCounters[UnstableIdx] = Beg[j];
+ for (size_t j = 0; j < Size; j++, CounterIdx++)
+ CB(i, j, CounterIdx);
}
}
}
+// Initializes unstable counters by copying Inline8bitCounters to unstable
+// counters.
+void TracePC::InitializeUnstableCounters() {
+ IterateInline8bitCounters([&](int i, int j, int UnstableIdx) {
+ if (UnstableCounters[UnstableIdx] != kUnstableCounter)
+ UnstableCounters[UnstableIdx] = ModuleCounters[i].Start[j];
+ });
+}
+
// 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 i, int j, int UnstableIdx) {
+ if (ModuleCounters[i].Start[j] != UnstableCounters[UnstableIdx])
+ UnstableCounters[UnstableIdx] = kUnstableCounter;
+ });
}
void TracePC::HandleInline8bitCountersInit(uint8_t *Start, uint8_t *Stop) {
@@ -191,15 +191,10 @@ void TracePC::UpdateObservedPCs() {
if (NumPCsInPCTables) {
if (NumInline8bitCounters == NumPCsInPCTables) {
- 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++)
- if (Beg[j])
- Observe(ModulePCTable[i].Start[j]);
- }
+ IterateInline8bitCounters([&](int i, int j, int CounterIdx) {
+ if (ModuleCounters[i].Start[j])
+ Observe(ModulePCTable[i].Start[j]);
+ });
} else if (NumGuards == NumPCsInPCTables) {
size_t GuardIdx = 1;
for (size_t i = 0; i < NumModules; i++) {
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h?rev=337403&r1=337402&r2=337403&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h Wed Jul 18 10:03:27 2018
@@ -178,6 +178,9 @@ private:
Set<uintptr_t> ObservedPCs;
Set<uintptr_t> ObservedFuncs;
+ template <class Callback>
+ void IterateInline8bitCounters(Callback CB) const;
+
std::pair<size_t, size_t> FocusFunction = {-1, -1}; // Module and PC IDs.
ValueBitMap ValueProfileMap;
More information about the llvm-commits
mailing list