[libFuzzer] implement value profile for switch, increase the size of the PCs array...
authorKostya Serebryany <kcc@google.com>
Tue, 11 Oct 2016 01:14:41 +0000 (01:14 +0000)
committerKostya Serebryany <kcc@google.com>
Tue, 11 Oct 2016 01:14:41 +0000 (01:14 +0000)
llvm-svn: 283841

llvm/lib/Fuzzer/FuzzerTracePC.cpp
llvm/lib/Fuzzer/FuzzerTracePC.h
llvm/lib/Fuzzer/test/trace-pc/CMakeLists.txt

index aa5bd9b..3b3e1f2 100644 (file)
@@ -27,10 +27,10 @@ void TracePC::HandleTrace(uint32_t *Guard, uintptr_t PC) {
   uint8_t *CounterPtr = &Counters[Idx % kNumCounters];
   uint8_t Counter = *CounterPtr;
   if (Counter == 0) {
-    if (!PCs[Idx]) {
+    if (!PCs[Idx % kNumPCs]) {
       AddNewPCID(Idx);
       TotalPCCoverage++;
-      PCs[Idx] = PC;
+      PCs[Idx % kNumPCs] = PC;
     }
   }
   if (UseCounters) {
@@ -227,7 +227,12 @@ void __sanitizer_cov_trace_cmp1(uint8_t Arg1, int8_t Arg2) {
 
 __attribute__((visibility("default")))
 void __sanitizer_cov_trace_switch(uint64_t Val, uint64_t *Cases) {
-  // TODO(kcc): support value profile here.
+  uint64_t N = Cases[0];
+  uint64_t *Vals = Cases + 2;
+  char *PC = (char*)__builtin_return_address(0);
+  for (size_t i = 0; i < N; i++)
+    if (Val != Vals[i])
+      fuzzer::AddValueForCmp(PC + i, Val, Vals[i]);
 }
 
 __attribute__((visibility("default")))
index 49f7faa..9a10b44 100644 (file)
@@ -87,7 +87,7 @@ private:
   static const size_t kNumCounters = 1 << 14;
   alignas(8) uint8_t Counters[kNumCounters];
 
-  static const size_t kNumPCs = 1 << 20;
+  static const size_t kNumPCs = 1 << 24;
   uintptr_t PCs[kNumPCs];
 
   ValueBitMap ValueProfileMap;
index a1eeb72..d5caa18 100644 (file)
@@ -10,6 +10,8 @@ set(TracePCTests
   NullDerefTest
   ShrinkControlFlowTest
   ShrinkValueProfileTest
+  SwitchTest
+  Switch2Test
   FullCoverageSetTest
   )