forked from OSchip/llvm-project
[LLVM][sancov] Inclusive language: Add -ignorelist option
Adding the `-ignorelist` option that may eventually replace `-blacklist`. With this patch `sancov` accepts both options. Reviewed By: quinnp Differential Revision: https://reviews.llvm.org/D113514
This commit is contained in:
parent
7c20e7ca86
commit
d35bff8bc4
|
@ -1,26 +0,0 @@
|
||||||
REQUIRES: x86-registered-target && host-byteorder-little-endian
|
|
||||||
RUN: sancov -covered-functions %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.0.sancov | FileCheck %s --check-prefix=ALL
|
|
||||||
RUN: sancov -covered-functions -blacklist %p/Inputs/fun_blacklist.txt %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.0.sancov | FileCheck %s
|
|
||||||
RUN: sancov -covered-functions -blacklist %p/Inputs/src_blacklist.txt %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.1.sancov | FileCheck --check-prefix=CHECK1 %s
|
|
||||||
RUN: sancov -print-coverage-stats %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.1.sancov | FileCheck --check-prefix=STATS %s
|
|
||||||
RUN: sancov -print-coverage-stats -blacklist %p/Inputs/fun_blacklist.txt %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.1.sancov | FileCheck --check-prefix=STATS-BLIST %s
|
|
||||||
|
|
||||||
ALL: test.cpp:12 bar(std::string)
|
|
||||||
ALL: test.cpp:14 main
|
|
||||||
|
|
||||||
CHECK-NOT: test.cpp:12 bar(std::string)
|
|
||||||
CHECK: test.cpp:14 main
|
|
||||||
|
|
||||||
CHECK1-NOT: test.cpp:12 bar(std::string)
|
|
||||||
CHECK1-NOT: test.cpp:14 main
|
|
||||||
|
|
||||||
STATS: all-edges: 9
|
|
||||||
STATS: cov-edges: 7
|
|
||||||
STATS: all-functions: 3
|
|
||||||
STATS: cov-functions: 3
|
|
||||||
|
|
||||||
STATS-BLIST: all-edges: 8
|
|
||||||
STATS-BLIST: cov-edges: 6
|
|
||||||
STATS-BLIST: all-functions: 2
|
|
||||||
STATS-BLIST: cov-functions: 2
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
REQUIRES: x86-registered-target && host-byteorder-little-endian
|
||||||
|
RUN: sancov -covered-functions %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.0.sancov | FileCheck %s --check-prefix=ALL
|
||||||
|
RUN: sancov -covered-functions -ignorelist %p/Inputs/fun_ignorelist.txt %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.0.sancov | FileCheck %s
|
||||||
|
RUN: sancov -covered-functions -blacklist %p/Inputs/fun_ignorelist.txt %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.0.sancov | FileCheck %s
|
||||||
|
RUN: sancov -covered-functions -ignorelist %p/Inputs/src_ignorelist.txt %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.1.sancov | FileCheck --check-prefix=CHECK1 %s
|
||||||
|
RUN: sancov -covered-functions -blacklist %p/Inputs/src_ignorelist.txt %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.1.sancov | FileCheck --check-prefix=CHECK1 %s
|
||||||
|
RUN: sancov -print-coverage-stats %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.1.sancov | FileCheck --check-prefix=STATS %s
|
||||||
|
RUN: sancov -print-coverage-stats -ignorelist %p/Inputs/fun_ignorelist.txt %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.1.sancov | FileCheck --check-prefix=STATS-BLIST %s
|
||||||
|
RUN: sancov -print-coverage-stats -blacklist %p/Inputs/fun_ignorelist.txt %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.1.sancov | FileCheck --check-prefix=STATS-BLIST %s
|
||||||
|
|
||||||
|
ALL: test.cpp:12 bar(std::string)
|
||||||
|
ALL: test.cpp:14 main
|
||||||
|
|
||||||
|
CHECK-NOT: test.cpp:12 bar(std::string)
|
||||||
|
CHECK: test.cpp:14 main
|
||||||
|
|
||||||
|
CHECK1-NOT: test.cpp:12 bar(std::string)
|
||||||
|
CHECK1-NOT: test.cpp:14 main
|
||||||
|
|
||||||
|
STATS: all-edges: 9
|
||||||
|
STATS: cov-edges: 7
|
||||||
|
STATS: all-functions: 3
|
||||||
|
STATS: cov-functions: 3
|
||||||
|
|
||||||
|
STATS-BLIST: all-edges: 8
|
||||||
|
STATS-BLIST: cov-edges: 6
|
||||||
|
STATS-BLIST: all-functions: 2
|
||||||
|
STATS-BLIST: cov-functions: 2
|
||||||
|
|
|
@ -103,16 +103,24 @@ static cl::opt<std::string> ClStripPathPrefix(
|
||||||
cl::desc("Strip this prefix from file paths in reports."));
|
cl::desc("Strip this prefix from file paths in reports."));
|
||||||
|
|
||||||
static cl::opt<std::string>
|
static cl::opt<std::string>
|
||||||
ClBlacklist("blacklist", cl::init(""),
|
ClIgnorelist("ignorelist", cl::init(""),
|
||||||
cl::desc("Blacklist file (sanitizer blacklist format)."));
|
cl::desc("Ignorelist file (sanitizer ignorelist format)."));
|
||||||
|
|
||||||
|
static cl::opt<std::string>
|
||||||
|
ClBlacklist("blacklist", cl::init(""), cl::Hidden,
|
||||||
|
cl::desc("ignorelist file (sanitizer ignorelist format)."));
|
||||||
|
|
||||||
static cl::opt<bool> ClUseDefaultBlacklist(
|
static cl::opt<bool> ClUseDefaultBlacklist(
|
||||||
"use_default_blacklist", cl::init(true), cl::Hidden,
|
"use_default_blacklist", cl::init(true), cl::Hidden,
|
||||||
cl::desc("Controls if default blacklist should be used."));
|
cl::desc("Controls if default ignorelist should be used."));
|
||||||
|
|
||||||
static const char *const DefaultBlacklistStr = "fun:__sanitizer_.*\n"
|
static cl::opt<bool> ClUseDefaultIgnorelist(
|
||||||
"src:/usr/include/.*\n"
|
"use_default_ignorelist", cl::init(true), cl::Hidden,
|
||||||
"src:.*/libc\\+\\+/.*\n";
|
cl::desc("Controls if default ignorelist should be used."));
|
||||||
|
|
||||||
|
static const char *const DefaultIgnorelistStr = "fun:__sanitizer_.*\n"
|
||||||
|
"src:/usr/include/.*\n"
|
||||||
|
"src:.*/libc\\+\\+/.*\n";
|
||||||
|
|
||||||
// --------- FORMAT SPECIFICATION ---------
|
// --------- FORMAT SPECIFICATION ---------
|
||||||
|
|
||||||
|
@ -473,48 +481,53 @@ static std::string normalizeFilename(const std::string &FileName) {
|
||||||
return stripPathPrefix(sys::path::convert_to_slash(std::string(S)));
|
return stripPathPrefix(sys::path::convert_to_slash(std::string(S)));
|
||||||
}
|
}
|
||||||
|
|
||||||
class Blacklists {
|
class Ignorelists {
|
||||||
public:
|
public:
|
||||||
Blacklists()
|
Ignorelists()
|
||||||
: DefaultBlacklist(createDefaultBlacklist()),
|
: DefaultIgnorelist(createDefaultIgnorelist()),
|
||||||
UserBlacklist(createUserBlacklist()) {}
|
UserIgnorelist(createUserIgnorelist()) {}
|
||||||
|
|
||||||
bool isBlacklisted(const DILineInfo &I) {
|
bool isIgnorelisted(const DILineInfo &I) {
|
||||||
if (DefaultBlacklist &&
|
if (DefaultIgnorelist &&
|
||||||
DefaultBlacklist->inSection("sancov", "fun", I.FunctionName))
|
DefaultIgnorelist->inSection("sancov", "fun", I.FunctionName))
|
||||||
return true;
|
return true;
|
||||||
if (DefaultBlacklist &&
|
if (DefaultIgnorelist &&
|
||||||
DefaultBlacklist->inSection("sancov", "src", I.FileName))
|
DefaultIgnorelist->inSection("sancov", "src", I.FileName))
|
||||||
return true;
|
return true;
|
||||||
if (UserBlacklist &&
|
if (UserIgnorelist &&
|
||||||
UserBlacklist->inSection("sancov", "fun", I.FunctionName))
|
UserIgnorelist->inSection("sancov", "fun", I.FunctionName))
|
||||||
return true;
|
return true;
|
||||||
if (UserBlacklist && UserBlacklist->inSection("sancov", "src", I.FileName))
|
if (UserIgnorelist &&
|
||||||
|
UserIgnorelist->inSection("sancov", "src", I.FileName))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::unique_ptr<SpecialCaseList> createDefaultBlacklist() {
|
static std::unique_ptr<SpecialCaseList> createDefaultIgnorelist() {
|
||||||
if (!ClUseDefaultBlacklist)
|
if ((!ClUseDefaultIgnorelist) && (!ClUseDefaultBlacklist))
|
||||||
return std::unique_ptr<SpecialCaseList>();
|
return std::unique_ptr<SpecialCaseList>();
|
||||||
std::unique_ptr<MemoryBuffer> MB =
|
std::unique_ptr<MemoryBuffer> MB =
|
||||||
MemoryBuffer::getMemBuffer(DefaultBlacklistStr);
|
MemoryBuffer::getMemBuffer(DefaultIgnorelistStr);
|
||||||
std::string Error;
|
std::string Error;
|
||||||
auto Blacklist = SpecialCaseList::create(MB.get(), Error);
|
auto Ignorelist = SpecialCaseList::create(MB.get(), Error);
|
||||||
failIfNotEmpty(Error);
|
failIfNotEmpty(Error);
|
||||||
return Blacklist;
|
return Ignorelist;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<SpecialCaseList> createUserBlacklist() {
|
static std::unique_ptr<SpecialCaseList> createUserIgnorelist() {
|
||||||
if (ClBlacklist.empty())
|
if ((ClBlacklist.empty()) && ClIgnorelist.empty())
|
||||||
return std::unique_ptr<SpecialCaseList>();
|
return std::unique_ptr<SpecialCaseList>();
|
||||||
|
|
||||||
return SpecialCaseList::createOrDie({{ClBlacklist}},
|
if (!ClBlacklist.empty())
|
||||||
|
return SpecialCaseList::createOrDie({{ClBlacklist}},
|
||||||
|
*vfs::getRealFileSystem());
|
||||||
|
|
||||||
|
return SpecialCaseList::createOrDie({{ClIgnorelist}},
|
||||||
*vfs::getRealFileSystem());
|
*vfs::getRealFileSystem());
|
||||||
}
|
}
|
||||||
std::unique_ptr<SpecialCaseList> DefaultBlacklist;
|
std::unique_ptr<SpecialCaseList> DefaultIgnorelist;
|
||||||
std::unique_ptr<SpecialCaseList> UserBlacklist;
|
std::unique_ptr<SpecialCaseList> UserIgnorelist;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::vector<CoveragePoint>
|
static std::vector<CoveragePoint>
|
||||||
|
@ -523,7 +536,7 @@ getCoveragePoints(const std::string &ObjectFile,
|
||||||
const std::set<uint64_t> &CoveredAddrs) {
|
const std::set<uint64_t> &CoveredAddrs) {
|
||||||
std::vector<CoveragePoint> Result;
|
std::vector<CoveragePoint> Result;
|
||||||
auto Symbolizer(createSymbolizer());
|
auto Symbolizer(createSymbolizer());
|
||||||
Blacklists B;
|
Ignorelists Ig;
|
||||||
|
|
||||||
std::set<std::string> CoveredFiles;
|
std::set<std::string> CoveredFiles;
|
||||||
if (ClSkipDeadFiles) {
|
if (ClSkipDeadFiles) {
|
||||||
|
@ -561,7 +574,7 @@ getCoveragePoints(const std::string &ObjectFile,
|
||||||
CoveredFiles.find(LineInfo->FileName) == CoveredFiles.end())
|
CoveredFiles.find(LineInfo->FileName) == CoveredFiles.end())
|
||||||
continue;
|
continue;
|
||||||
LineInfo->FileName = normalizeFilename(LineInfo->FileName);
|
LineInfo->FileName = normalizeFilename(LineInfo->FileName);
|
||||||
if (B.isBlacklisted(*LineInfo))
|
if (Ig.isIgnorelisted(*LineInfo))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto Id = utohexstr(Addr, true);
|
auto Id = utohexstr(Addr, true);
|
||||||
|
@ -578,7 +591,7 @@ getCoveragePoints(const std::string &ObjectFile,
|
||||||
CoveredFiles.find(FrameInfo.FileName) == CoveredFiles.end())
|
CoveredFiles.find(FrameInfo.FileName) == CoveredFiles.end())
|
||||||
continue;
|
continue;
|
||||||
FrameInfo.FileName = normalizeFilename(FrameInfo.FileName);
|
FrameInfo.FileName = normalizeFilename(FrameInfo.FileName);
|
||||||
if (B.isBlacklisted(FrameInfo))
|
if (Ig.isIgnorelisted(FrameInfo))
|
||||||
continue;
|
continue;
|
||||||
if (Infos.find(FrameInfo) == Infos.end()) {
|
if (Infos.find(FrameInfo) == Infos.end()) {
|
||||||
Infos.insert(FrameInfo);
|
Infos.insert(FrameInfo);
|
||||||
|
@ -878,7 +891,7 @@ symbolize(const RawCoverage &Data, const std::string ObjectFile) {
|
||||||
Hasher.update((*BufOrErr)->getBuffer());
|
Hasher.update((*BufOrErr)->getBuffer());
|
||||||
Coverage->BinaryHash = toHex(Hasher.final());
|
Coverage->BinaryHash = toHex(Hasher.final());
|
||||||
|
|
||||||
Blacklists B;
|
Ignorelists Ig;
|
||||||
auto Symbolizer(createSymbolizer());
|
auto Symbolizer(createSymbolizer());
|
||||||
|
|
||||||
for (uint64_t Addr : *Data.Addrs) {
|
for (uint64_t Addr : *Data.Addrs) {
|
||||||
|
@ -887,7 +900,7 @@ symbolize(const RawCoverage &Data, const std::string ObjectFile) {
|
||||||
auto LineInfo = Symbolizer->symbolizeCode(
|
auto LineInfo = Symbolizer->symbolizeCode(
|
||||||
ObjectFile, {Addr, object::SectionedAddress::UndefSection});
|
ObjectFile, {Addr, object::SectionedAddress::UndefSection});
|
||||||
failIfError(LineInfo);
|
failIfError(LineInfo);
|
||||||
if (B.isBlacklisted(*LineInfo))
|
if (Ig.isIgnorelisted(*LineInfo))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Coverage->CoveredIds.insert(utohexstr(Addr, true));
|
Coverage->CoveredIds.insert(utohexstr(Addr, true));
|
||||||
|
|
Loading…
Reference in New Issue