[llvm] e714394 - [LLVM][llvm-cov] Inclusive language: rename option -name-whitelist to -name-allowlist

Zarko Todorovski via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 26 08:08:06 PST 2021


Author: Zarko Todorovski
Date: 2021-11-26T11:08:01-05:00
New Revision: e714394ab8f03783490fefe902dcec3585d3fe08

URL: https://github.com/llvm/llvm-project/commit/e714394ab8f03783490fefe902dcec3585d3fe08
DIFF: https://github.com/llvm/llvm-project/commit/e714394ab8f03783490fefe902dcec3585d3fe08.diff

LOG: [LLVM][llvm-cov] Inclusive language: rename option -name-whitelist to -name-allowlist

Renamed the option for llvm-cov and changed variable names to use more
inclusive terms. Also changed the binary for the test.

Reviewed By: alanphipps

Differential Revision: https://reviews.llvm.org/D112816

Added: 
    llvm/test/tools/llvm-cov/Inputs/allowlist1.txt
    llvm/test/tools/llvm-cov/Inputs/allowlist2.txt
    llvm/test/tools/llvm-cov/Inputs/name_allowlist.covmapping
    llvm/test/tools/llvm-cov/Inputs/name_allowlist.cpp
    llvm/test/tools/llvm-cov/Inputs/name_allowlist.proftext
    llvm/test/tools/llvm-cov/name_allowlist.test

Modified: 
    llvm/docs/CommandGuide/llvm-cov.rst
    llvm/docs/ReleaseNotes.rst
    llvm/tools/llvm-cov/CodeCoverage.cpp
    llvm/tools/llvm-cov/CoverageFilters.cpp
    llvm/tools/llvm-cov/CoverageFilters.h

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/llvm-cov.rst b/llvm/docs/CommandGuide/llvm-cov.rst
index 5f4c6e4fb25c7..fe07f9b09e71d 100644
--- a/llvm/docs/CommandGuide/llvm-cov.rst
+++ b/llvm/docs/CommandGuide/llvm-cov.rst
@@ -265,11 +265,18 @@ OPTIONS
 
  Show code coverage only for functions with the given name.
 
+.. option:: -name-allowlist=<FILE>
+
+ 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=<FILE>
 
  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=<FILE> in future releases.
 
 .. option:: -name-regex=<PATTERN>
 

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 2b43915bf47bf..7c6587443fd85 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -152,7 +152,9 @@ During this release ...
 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
index 0000000000000..87a71acf984b7
--- /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
index 0000000000000..f8696bc0e045e
--- /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 0000000000000..7a7ab700f367c
Binary files /dev/null and b/llvm/test/tools/llvm-cov/Inputs/name_allowlist.covmapping 
diff er

diff  --git a/llvm/test/tools/llvm-cov/Inputs/name_allowlist.cpp b/llvm/test/tools/llvm-cov/Inputs/name_allowlist.cpp
new file mode 100644
index 0000000000000..8cfdbc69bc446
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/name_allowlist.cpp
@@ -0,0 +1,18 @@
+int func1() {
+  return 1;
+}
+int func2() {
+  return 1;
+}
+int func3() {
+  return 1;
+}
+int func4() {
+  return 1;
+}
+int func5() {
+  return 1;
+}
+int func6() {
+  return 1;
+}

diff  --git a/llvm/test/tools/llvm-cov/Inputs/name_allowlist.proftext b/llvm/test/tools/llvm-cov/Inputs/name_allowlist.proftext
new file mode 100644
index 0000000000000..c806d1565fb06
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/name_allowlist.proftext
@@ -0,0 +1,56 @@
+_Z5func1v
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+0
+
+_Z5func2v
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+0
+
+_Z5func3v
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+0
+
+_Z5func4v
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+0
+
+main
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+1
+
+_Z5func5v
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+0
+
+_Z5func6v
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+0
+

diff  --git a/llvm/test/tools/llvm-cov/name_allowlist.test b/llvm/test/tools/llvm-cov/name_allowlist.test
new file mode 100644
index 0000000000000..95f2688c8f304
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/name_allowlist.test
@@ -0,0 +1,21 @@
+RUN: llvm-profdata merge %S/Inputs/name_allowlist.proftext -o %t.profdata
+
+RUN: llvm-cov show %S/Inputs/name_allowlist.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp,%S/Inputs -name-allowlist=%S/Inputs/allowlist1.txt %S/Inputs/name_allowlist.cpp > %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
index 5c9ff41a2d5d6..d357ad7c9e100 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -176,8 +176,8 @@ class CodeCoverageTool {
   std::vector<std::pair<std::string, std::unique_ptr<MemoryBuffer>>>
       LoadedSourceFiles;
 
-  /// Whitelist from -name-whitelist to be used for filtering.
-  std::unique_ptr<SpecialCaseList> NameWhitelist;
+  /// Allowlist from -name-allowlist to be used for filtering.
+  std::unique_ptr<SpecialCaseList> NameAllowlist;
 };
 }
 
@@ -668,11 +668,18 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
       cl::ZeroOrMore, cl::cat(FilteringCategory));
 
   cl::list<std::string> 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<std::string> 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<std::string> NameRegexFilters(
       "name-regex", cl::Optional,
       cl::desc("Show code coverage only for functions that match the given "
@@ -809,23 +816,34 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
       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<CoverageFilters>();
       for (const auto &Name : NameFilters)
         NameFilterer->push_back(std::make_unique<NameCoverageFilter>(Name));
-      if (NameWhitelist)
-        NameFilterer->push_back(
-            std::make_unique<NameWhitelistCoverageFilter>(*NameWhitelist));
+      if (NameAllowlist) {
+        if (!NameFilterFiles.empty())
+          NameFilterer->push_back(
+              std::make_unique<NameAllowlistCoverageFilter>(*NameAllowlist));
+        if (!NameFilterFilesDeprecated.empty())
+          NameFilterer->push_back(
+              std::make_unique<NameWhitelistCoverageFilter>(*NameAllowlist));
+      }
       for (const auto &Regex : NameRegexFilters)
         NameFilterer->push_back(
             std::make_unique<NameRegexCoverageFilter>(Regex));

diff  --git a/llvm/tools/llvm-cov/CoverageFilters.cpp b/llvm/tools/llvm-cov/CoverageFilters.cpp
index fac7518d7da29..b7998647cc57e 100644
--- a/llvm/tools/llvm-cov/CoverageFilters.cpp
+++ b/llvm/tools/llvm-cov/CoverageFilters.cpp
@@ -34,6 +34,13 @@ bool NameRegexCoverageFilter::matchesFilename(StringRef Filename) const {
   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 {

diff  --git a/llvm/tools/llvm-cov/CoverageFilters.h b/llvm/tools/llvm-cov/CoverageFilters.h
index 33fd9929c59a2..3040fe74f7cff 100644
--- a/llvm/tools/llvm-cov/CoverageFilters.h
+++ b/llvm/tools/llvm-cov/CoverageFilters.h
@@ -67,7 +67,19 @@ class NameRegexCoverageFilter : public CoverageFilter {
 };
 
 /// 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;
 


        


More information about the llvm-commits mailing list