[llvm] r293128 - [libFuzzer] further simplify __sanitizer_cov_trace_pc_guard

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 25 17:34:58 PST 2017


Author: kcc
Date: Wed Jan 25 19:34:58 2017
New Revision: 293128

URL: http://llvm.org/viewvc/llvm-project?rev=293128&view=rev
Log:
[libFuzzer] further simplify __sanitizer_cov_trace_pc_guard

Modified:
    llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
    llvm/trunk/lib/Fuzzer/FuzzerTracePC.h

Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp?rev=293128&r1=293127&r2=293128&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp Wed Jan 25 19:34:58 2017
@@ -32,12 +32,12 @@ ATTRIBUTE_NO_SANITIZE_ALL
 void TracePC::HandleTrace(uint32_t *Guard, uintptr_t PC) {
   uint32_t Idx = *Guard;
   PCs[Idx] = PC;
-  Counters[Idx % kNumCounters]++;
+  Counters[Idx]++;
 }
 
 size_t TracePC::GetTotalPCCoverage() {
   size_t Res = 0;
-  for (size_t i = 1; i < GetNumPCs(); i++)
+  for (size_t i = 1, N = GetNumPCs(); i < N; i++)
     if (PCs[i])
       Res++;
   return Res;

Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.h?rev=293128&r1=293127&r2=293128&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.h Wed Jan 25 19:34:58 2017
@@ -64,7 +64,7 @@ class TracePC {
 
   void ResetMaps() {
     ValueProfileMap.Reset();
-    memset(Counters, 0, sizeof(Counters));
+    memset(Counters, 0, GetNumPCs());
   }
 
   void UpdateFeatureSet(size_t CurrentElementIdx, size_t CurrentElementSize);
@@ -105,10 +105,8 @@ private:
   size_t NumModules;  // linker-initialized.
   size_t NumGuards;  // linker-initialized.
 
-  static const size_t kNumCounters = 1 << 14;
-  alignas(8) uint8_t Counters[kNumCounters];
-
-  static const size_t kNumPCs = 1 << 24;
+  static const size_t kNumPCs = 1 << 21;
+  alignas(8) uint8_t Counters[kNumPCs];
   uintptr_t PCs[kNumPCs];
 
   std::set<uintptr_t> *PrintedPCs;
@@ -122,7 +120,7 @@ size_t TracePC::CollectFeatures(Callback
   size_t Res = 0;
   const size_t Step = 8;
   assert(reinterpret_cast<uintptr_t>(Counters) % Step == 0);
-  size_t N = Min(kNumCounters, NumGuards + 1);
+  size_t N = GetNumPCs();
   N = (N + Step - 1) & ~(Step - 1);  // Round up.
   for (size_t Idx = 0; Idx < N; Idx += Step) {
     uint64_t Bundle = *reinterpret_cast<uint64_t*>(&Counters[Idx]);
@@ -146,7 +144,7 @@ size_t TracePC::CollectFeatures(Callback
   }
   if (UseValueProfile)
     ValueProfileMap.ForEach([&](size_t Idx) {
-      if (CB(NumGuards * 8 + Idx))
+      if (CB(N * 8 + Idx))
         Res++;
     });
   return Res;




More information about the llvm-commits mailing list