Index: test/tools/sancov/Inputs/blacklist.txt =================================================================== --- /dev/null +++ test/tools/sancov/Inputs/blacklist.txt @@ -0,0 +1 @@ +fun:bar* Index: test/tools/sancov/blacklist.test =================================================================== --- /dev/null +++ test/tools/sancov/blacklist.test @@ -0,0 +1,5 @@ +REQUIRES: x86_64-linux +RUN: sancov -obj %p/Inputs/test-linux_x86_64 -covered-functions -blacklist %p/Inputs/blacklist.txt %p/Inputs/test-linux_x86_64.sancov | FileCheck %s + +CHECK-NOT: Inputs{{[/\\]}}test.cpp:12 bar(std::string) +CHECK: Inputs{{[/\\]}}test.cpp:14 main Index: tools/sancov/sancov.cc =================================================================== --- tools/sancov/sancov.cc +++ tools/sancov/sancov.cc @@ -34,6 +34,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/SpecialCaseList.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/ToolOutputFile.h" @@ -80,6 +81,12 @@ "strip_path_prefix", cl::init(""), cl::desc("Strip this prefix from file paths in reports.")); +static cl::opt ClBlacklist( + "blacklist", cl::init(""), + cl::desc("Blacklist file (sanitizer blacklist format).")); + +static const char *const DefaultBlacklist = "fun:__sancov*"; + // --------- FORMAT SPECIFICATION --------- struct FileHeader { @@ -337,9 +344,26 @@ return Result; } +static std::unique_ptr createBlacklist() { + if (!ClBlacklist.empty()) + return SpecialCaseList::createOrDie({{ClBlacklist}}); + std::unique_ptr MB = MemoryBuffer::getMemBuffer(DefaultBlacklist); + std::string Error; + auto Blacklist = SpecialCaseList::create(MB.get(), Error); + FailIfNotEmpty(Error); + return Blacklist; +} + static void printFunctionLocs(const std::set &FnLocs, raw_ostream &OS) { + std::unique_ptr Blacklist = createBlacklist(); + for (const FunctionLoc &FnLoc : FnLocs) { + if (Blacklist->inSection("fun", FnLoc.FunctionName)) + continue; + if (Blacklist->inSection("src", FnLoc.Loc.FileName)) + continue; + OS << stripPathPrefix(FnLoc.Loc.FileName) << ":" << FnLoc.Loc.Line << " " << FnLoc.FunctionName << "\n"; } @@ -444,6 +468,7 @@ std::unique_ptr> Addrs; }; + } // namespace int main(int argc, char **argv) {