[llvm] r290039 - [libFuzzer] use less memory for merge
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 17 00:20:24 PST 2016
Author: kcc
Date: Sat Dec 17 02:20:24 2016
New Revision: 290039
URL: http://llvm.org/viewvc/llvm-project?rev=290039&view=rev
Log:
[libFuzzer] use less memory for merge
Modified:
llvm/trunk/lib/Fuzzer/FuzzerMerge.cpp
llvm/trunk/lib/Fuzzer/FuzzerMerge.h
llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp
Modified: llvm/trunk/lib/Fuzzer/FuzzerMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerMerge.cpp?rev=290039&r1=290038&r2=290039&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerMerge.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerMerge.cpp Sat Dec 17 02:20:24 2016
@@ -94,10 +94,11 @@ bool Merger::Parse(std::istream &IS, boo
return false;
LastSeenStartMarker = kInvalidStartMarker;
if (ParseCoverage) {
- while (!ISS1.rdstate()) {
- ISS1 >> std::hex >> N;
- Files[CurrentFileIdx].Features.insert(N);
- }
+ auto &V = Files[CurrentFileIdx].Features;
+ V.clear();
+ while (ISS1 >> std::hex >> N)
+ V.push_back(N);
+ std::sort(V.begin(), V.end());
}
} else {
return false;
@@ -115,7 +116,7 @@ bool Merger::Parse(std::istream &IS, boo
size_t Merger::Merge(std::vector<std::string> *NewFiles) {
NewFiles->clear();
assert(NumFilesInFirstCorpus <= Files.size());
- std::set<size_t> AllFeatures;
+ std::set<uint32_t> AllFeatures;
// What features are in the initial corpus?
for (size_t i = 0; i < NumFilesInFirstCorpus; i++) {
@@ -127,7 +128,7 @@ size_t Merger::Merge(std::vector<std::st
// Remove all features that we already know from all other inputs.
for (size_t i = NumFilesInFirstCorpus; i < Files.size(); i++) {
auto &Cur = Files[i].Features;
- std::set<size_t> Tmp;
+ std::vector<uint32_t> Tmp;
std::set_difference(Cur.begin(), Cur.end(), AllFeatures.begin(),
AllFeatures.end(), std::inserter(Tmp, Tmp.begin()));
Cur.swap(Tmp);
Modified: llvm/trunk/lib/Fuzzer/FuzzerMerge.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerMerge.h?rev=290039&r1=290038&r2=290039&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerMerge.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerMerge.h Sat Dec 17 02:20:24 2016
@@ -50,7 +50,7 @@ namespace fuzzer {
struct MergeFileInfo {
std::string Name;
size_t Size = 0;
- std::set<size_t> Features;
+ std::vector<uint32_t> Features;
};
struct Merger {
Modified: llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp?rev=290039&r1=290038&r2=290039&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp (original)
+++ llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp Sat Dec 17 02:20:24 2016
@@ -620,7 +620,7 @@ TEST(Merge, Bad) {
}
}
-void EQ(const std::set<size_t> &A, const std::set<size_t> &B) {
+void EQ(const std::vector<uint32_t> &A, const std::vector<uint32_t> &B) {
EXPECT_EQ(A, B);
}
@@ -699,8 +699,11 @@ TEST(Merge, Good) {
EXPECT_TRUE(M.Parse("3\n1\nA\nB\nC\n"
"STARTED 0 1000\nDONE 0 1 2 3\n"
"STARTED 1 1001\nDONE 1 4 5 6 \n"
- "STARTED 2 1002\nDONE 2 6 1 3 \n"
+ "STARTED 2 1002\nDONE 2 6 1 3\n"
"", true));
+ EQ(M.Files[0].Features, {1, 2, 3});
+ EQ(M.Files[1].Features, {4, 5, 6});
+ EQ(M.Files[2].Features, {1, 3, 6});
EXPECT_EQ(3U, M.Merge(&NewFiles));
EQ(NewFiles, {"B"});
}
More information about the llvm-commits
mailing list