summaryrefslogtreecommitdiff
path: root/lib/fuzzer/FuzzerTracePC.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fuzzer/FuzzerTracePC.h')
-rw-r--r--lib/fuzzer/FuzzerTracePC.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/fuzzer/FuzzerTracePC.h b/lib/fuzzer/FuzzerTracePC.h
index bc7e5ec03..300e5db38 100644
--- a/lib/fuzzer/FuzzerTracePC.h
+++ b/lib/fuzzer/FuzzerTracePC.h
@@ -274,8 +274,19 @@ void TracePC::CollectFeatures(Callback HandleFeature) const {
FirstFeature += ValueProfileMap.SizeInBits();
}
+ // Step function, grows similar to 8 * Log_2(A).
+ auto StackDepthStepFunction = [](uint32_t A) -> uint32_t {
+ uint32_t Log2 = 32 - __builtin_clz(A) - 1;
+ if (Log2 < 3) return A;
+ Log2 -= 3;
+ return (Log2 + 1) * 8 + ((A >> Log2) & 7);
+ };
+ assert(StackDepthStepFunction(1024) == 64);
+ assert(StackDepthStepFunction(1024 * 4) == 80);
+ assert(StackDepthStepFunction(1024 * 1024) == 144);
+
if (auto MaxStackOffset = GetMaxStackOffset())
- HandleFeature(FirstFeature + MaxStackOffset / 128);
+ HandleFeature(FirstFeature + StackDepthStepFunction(MaxStackOffset / 8));
}
extern TracePC TPC;