[llvm] r285147 - [libFuzzer] simplify the code in TracePC::HandleTrace a bit more
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 25 17:42:53 PDT 2016
Author: kcc
Date: Tue Oct 25 19:42:52 2016
New Revision: 285147
URL: http://llvm.org/viewvc/llvm-project?rev=285147&view=rev
Log:
[libFuzzer] simplify the code in TracePC::HandleTrace a bit more
Modified:
llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=285147&r1=285146&r2=285147&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Tue Oct 25 19:42:52 2016
@@ -381,15 +381,14 @@ void Fuzzer::SetMaxMutationLen(size_t Ma
void Fuzzer::CheckExitOnSrcPosOrItem() {
if (!Options.ExitOnSrcPos.empty()) {
- uintptr_t *PCIDs;
- if (size_t NumNewPCIDs = TPC.GetNewPCIDs(&PCIDs)) {
- for (size_t i = 0; i < NumNewPCIDs; i++) {
- std::string Descr = DescribePC("%L", TPC.GetPCbyPCID(PCIDs[i]));
- if (Descr.find(Options.ExitOnSrcPos) != std::string::npos) {
- Printf("INFO: found line matching '%s', exiting.\n",
- Options.ExitOnSrcPos.c_str());
- _Exit(0);
- }
+ for (size_t i = 1, N = TPC.GetNumPCs(); i < N; i++) {
+ uintptr_t PC = TPC.GetPC(i);
+ if (!PC) continue;
+ std::string Descr = DescribePC("%L", PC);
+ if (Descr.find(Options.ExitOnSrcPos) != std::string::npos) {
+ Printf("INFO: found line matching '%s', exiting.\n",
+ Options.ExitOnSrcPos.c_str());
+ _Exit(0);
}
}
}
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp?rev=285147&r1=285146&r2=285147&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp Tue Oct 25 19:42:52 2016
@@ -30,14 +30,10 @@ TracePC TPC;
void TracePC::HandleTrace(uint32_t *Guard, uintptr_t PC) {
uint32_t Idx = *Guard;
if (!Idx) return;
+ if (!PCs[Idx % kNumPCs])
+ PCs[Idx % kNumPCs] = PC;
uint8_t *CounterPtr = &Counters[Idx % kNumCounters];
uint8_t Counter = *CounterPtr;
- if (Counter == 0) {
- if (!PCs[Idx % kNumPCs]) {
- AddNewPCID(Idx);
- PCs[Idx % kNumPCs] = PC;
- }
- }
if (UseCounters) {
if (Counter < 128)
*CounterPtr = Counter + 1;
@@ -51,7 +47,7 @@ void TracePC::HandleTrace(uint32_t *Guar
size_t TracePC::GetTotalPCCoverage() {
size_t Res = 0;
- for (size_t i = 0; i < Min(NumGuards+1, kNumPCs); i++)
+ for (size_t i = 1; i < GetNumPCs(); i++)
if (PCs[i])
Res++;
return Res;
@@ -140,7 +136,7 @@ void TracePC::PrintNewPCs() {
if (DoPrintNewPCs) {
if (!PrintedPCs)
PrintedPCs = new std::set<uintptr_t>;
- for (size_t i = 0; i < Min(NumGuards + 1, kNumPCs); i++)
+ for (size_t i = 1; i < GetNumPCs(); i++)
if (PCs[i] && PrintedPCs->insert(PCs[i]).second)
PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PCs[i]);
}
@@ -156,7 +152,7 @@ void TracePC::PrintCoverage() {
std::map<std::string, uintptr_t> ModuleOffsets;
std::set<std::string> CoveredFiles, CoveredFunctions, CoveredLines;
Printf("COVERAGE:\n");
- for (size_t i = 0; i < Min(NumGuards + 1, kNumPCs); i++) {
+ for (size_t i = 1; i < GetNumPCs(); i++) {
if (!PCs[i]) continue;
std::string FileStr = DescribePC("%s", PCs[i]);
if (!IsInterestingCoverageFile(FileStr)) continue;
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.h?rev=285147&r1=285146&r2=285147&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.h Tue Oct 25 19:42:52 2016
@@ -61,15 +61,7 @@ class TracePC {
return UseValueProfile && MaxValueProfileMap->MergeFrom(ValueProfileMap);
}
- size_t GetNewPCIDs(uintptr_t **NewPCIDsPtr) {
- *NewPCIDsPtr = NewPCIDs;
- return Min(kMaxNewPCIDs, NumNewPCIDs);
- }
-
- uintptr_t GetPCbyPCID(uintptr_t PCID) { return PCs[PCID]; }
-
void ResetMaps() {
- NumNewPCIDs = 0;
ValueProfileMap.Reset();
memset(Counters, 0, sizeof(Counters));
}
@@ -95,19 +87,17 @@ class TracePC {
TableOfRecentCompares<uint64_t, kTORCSize> TORC8;
void PrintNewPCs();
+ size_t GetNumPCs() const { return Min(kNumPCs, NumGuards + 1); }
+ uintptr_t GetPC(size_t Idx) {
+ assert(Idx < GetNumPCs());
+ return PCs[Idx];
+ }
private:
bool UseCounters = false;
bool UseValueProfile = false;
bool DoPrintNewPCs = false;
- static const size_t kMaxNewPCIDs = 1024;
- uintptr_t NewPCIDs[kMaxNewPCIDs];
- size_t NumNewPCIDs = 0;
- void AddNewPCID(uintptr_t PCID) {
- NewPCIDs[(NumNewPCIDs++) % kMaxNewPCIDs] = PCID;
- }
-
struct Module {
uint32_t *Start, *Stop;
};
More information about the llvm-commits
mailing list