diff --git a/llvm/docs/CommandGuide/llvm-cov.rst b/llvm/docs/CommandGuide/llvm-cov.rst --- a/llvm/docs/CommandGuide/llvm-cov.rst +++ b/llvm/docs/CommandGuide/llvm-cov.rst @@ -265,11 +265,18 @@ Show code coverage only for functions with the given name. +.. option:: -name-allowlist= + + Show code coverage only for functions listed in the given file. Each line in + the file should start with `allowlist_fun:`, immediately followed by the name + of the function to accept. This name can be a wildcard expression. + .. option:: -name-whitelist= Show code coverage only for functions listed in the given file. Each line in the file should start with `whitelist_fun:`, immediately followed by the name - of the function to accept. This name can be a wildcard expression. + of the function to accept. This name can be a wildcard expression. This option + will be deprecated for `-name-allowlist= in future releases. .. option:: -name-regex= diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst --- a/llvm/docs/ReleaseNotes.rst +++ b/llvm/docs/ReleaseNotes.rst @@ -152,7 +152,9 @@ Changes to the LLVM tools --------------------------------- -* ... +* llvm-cov: `-name-allowlist` is now accepted in addition to `-name-whitelist`. + `-name-whitelist` is marked as deprecated and to be removed in future + releases. Changes to LLDB --------------------------------- diff --git a/llvm/test/tools/llvm-cov/Inputs/allowlist1.txt b/llvm/test/tools/llvm-cov/Inputs/allowlist1.txt new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-cov/Inputs/allowlist1.txt @@ -0,0 +1,4 @@ +# Comment + +allowlist_fun:*func1* +allowlist_fun:*func2* diff --git a/llvm/test/tools/llvm-cov/Inputs/allowlist2.txt b/llvm/test/tools/llvm-cov/Inputs/allowlist2.txt new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-cov/Inputs/allowlist2.txt @@ -0,0 +1,2 @@ +allowlist_fun:*func3* +allowlist_fun:*func4* diff --git a/llvm/test/tools/llvm-cov/Inputs/name_allowlist.covmapping b/llvm/test/tools/llvm-cov/Inputs/name_allowlist.covmapping new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ %t.one_list +RUN: FileCheck -input-file=%t.one_list -check-prefix=ONE_ALLOWLIST %s +RUN: FileCheck -input-file=%t.one_list -check-prefix=ONE_ALLOWLIST_NEG %s +ONE_ALLOWLIST: _Z5func1v: +ONE_ALLOWLIST: _Z5func2v: +ONE_ALLOWLIST_NEG-NOT: _Z5func3v: +ONE_ALLOWLIST_NEG-NOT: _Z5func4v: +ONE_ALLOWLIST_NEG-NOT: _Z5func5v: +ONE_ALLOWLIST_NEG-NOT: _Z5func6v: + +RUN: llvm-cov show %S/Inputs/name_allowlist.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp,%S/Inputs -name-allowlist=%S/Inputs/allowlist1.txt -name-allowlist=%S/Inputs/allowlist2.txt %S/Inputs/name_allowlist.cpp > %t.two_list +RUN: FileCheck -input-file=%t.two_list -check-prefix=TWO_ALLOWLIST %s +RUN: FileCheck -input-file=%t.two_list -check-prefix=TWO_ALLOWLIST_NEG %s +TWO_ALLOWLIST: _Z5func1v: +TWO_ALLOWLIST: _Z5func2v: +TWO_ALLOWLIST: _Z5func3v: +TWO_ALLOWLIST: _Z5func4v: +TWO_ALLOWLIST_NEG-NOT: _Z5func5v: +TWO_ALLOWLIST_NEG-NOT: _Z5func6v: diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -176,8 +176,8 @@ std::vector>> LoadedSourceFiles; - /// Whitelist from -name-whitelist to be used for filtering. - std::unique_ptr NameWhitelist; + /// Allowlist from -name-allowlist to be used for filtering. + std::unique_ptr NameAllowlist; }; } @@ -668,11 +668,18 @@ cl::ZeroOrMore, cl::cat(FilteringCategory)); cl::list NameFilterFiles( - "name-whitelist", cl::Optional, + "name-allowlist", cl::Optional, cl::desc("Show code coverage only for functions listed in the given " "file"), cl::ZeroOrMore, cl::cat(FilteringCategory)); + // Allow for accepting previous option name. + cl::list NameFilterFilesDeprecated( + "name-whitelist", cl::Optional, cl::Hidden, + cl::desc("Show code coverage only for functions listed in the given " + "file. Deprecated, use -name-allowlist instead"), + cl::ZeroOrMore, cl::cat(FilteringCategory)); + cl::list NameRegexFilters( "name-regex", cl::Optional, cl::desc("Show code coverage only for functions that match the given " @@ -809,23 +816,34 @@ ViewOpts.DemanglerOpts.swap(DemanglerOpts); } - // Read in -name-whitelist files. - if (!NameFilterFiles.empty()) { + // Read in -name-allowlist files. + if (!NameFilterFiles.empty() || !NameFilterFilesDeprecated.empty()) { std::string SpecialCaseListErr; - NameWhitelist = SpecialCaseList::create( - NameFilterFiles, *vfs::getRealFileSystem(), SpecialCaseListErr); - if (!NameWhitelist) + if (!NameFilterFiles.empty()) + NameAllowlist = SpecialCaseList::create( + NameFilterFiles, *vfs::getRealFileSystem(), SpecialCaseListErr); + if (!NameFilterFilesDeprecated.empty()) + NameAllowlist = SpecialCaseList::create(NameFilterFilesDeprecated, + *vfs::getRealFileSystem(), + SpecialCaseListErr); + + if (!NameAllowlist) error(SpecialCaseListErr); } // Create the function filters - if (!NameFilters.empty() || NameWhitelist || !NameRegexFilters.empty()) { + if (!NameFilters.empty() || NameAllowlist || !NameRegexFilters.empty()) { auto NameFilterer = std::make_unique(); for (const auto &Name : NameFilters) NameFilterer->push_back(std::make_unique(Name)); - if (NameWhitelist) - NameFilterer->push_back( - std::make_unique(*NameWhitelist)); + if (NameAllowlist) { + if (!NameFilterFiles.empty()) + NameFilterer->push_back( + std::make_unique(*NameAllowlist)); + if (!NameFilterFilesDeprecated.empty()) + NameFilterer->push_back( + std::make_unique(*NameAllowlist)); + } for (const auto &Regex : NameRegexFilters) NameFilterer->push_back( std::make_unique(Regex)); diff --git a/llvm/tools/llvm-cov/CoverageFilters.h b/llvm/tools/llvm-cov/CoverageFilters.h --- a/llvm/tools/llvm-cov/CoverageFilters.h +++ b/llvm/tools/llvm-cov/CoverageFilters.h @@ -67,7 +67,19 @@ }; /// Matches functions whose name appears in a SpecialCaseList in the -/// whitelist_fun section. +/// allowlist_fun section. +class NameAllowlistCoverageFilter : public CoverageFilter { + const SpecialCaseList &Allowlist; + +public: + NameAllowlistCoverageFilter(const SpecialCaseList &Allowlist) + : Allowlist(Allowlist) {} + + bool matches(const coverage::CoverageMapping &CM, + const coverage::FunctionRecord &Function) const override; +}; + +// TODO: Remove this class when -name-whitelist option is removed. class NameWhitelistCoverageFilter : public CoverageFilter { const SpecialCaseList &Whitelist; diff --git a/llvm/tools/llvm-cov/CoverageFilters.cpp b/llvm/tools/llvm-cov/CoverageFilters.cpp --- a/llvm/tools/llvm-cov/CoverageFilters.cpp +++ b/llvm/tools/llvm-cov/CoverageFilters.cpp @@ -34,6 +34,13 @@ return llvm::Regex(Regex).match(Filename); } +bool NameAllowlistCoverageFilter::matches( + const coverage::CoverageMapping &, + const coverage::FunctionRecord &Function) const { + return Allowlist.inSection("llvmcov", "allowlist_fun", Function.Name); +} + +// TODO: remove this when -name-whitelist option is removed. bool NameWhitelistCoverageFilter::matches( const coverage::CoverageMapping &, const coverage::FunctionRecord &Function) const {