[PATCH] D90281: [FileCheck] Report missing prefixes when more than one is provided.

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 27 19:03:04 PDT 2020


mtrofin created this revision.
mtrofin added reviewers: thopre, jhenderson.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
mtrofin requested review of this revision.

If more than a prefix is provided - e.g. --check-prefixes=CHECK,FOO - we
don't report if (say) FOO is never used. This may lead to a gap in our
test coverage.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90281

Files:
  llvm/lib/FileCheck/FileCheck.cpp


Index: llvm/lib/FileCheck/FileCheck.cpp
===================================================================
--- llvm/lib/FileCheck/FileCheck.cpp
+++ llvm/lib/FileCheck/FileCheck.cpp
@@ -23,6 +23,7 @@
 #include <cstdint>
 #include <list>
 #include <tuple>
+#include <unordered_set>
 #include <utility>
 
 using namespace llvm;
@@ -1825,7 +1826,10 @@
   // found.
   unsigned LineNumber = 1;
 
-  bool FoundUsedCheckPrefix = false;
+  StringSet<> PrefixesNotFound;
+  for (auto CP : Req.CheckPrefixes)
+    PrefixesNotFound.insert(CP);
+
   while (1) {
     Check::FileCheckType CheckTy;
 
@@ -1837,7 +1841,7 @@
     if (UsedPrefix.empty())
       break;
     if (CheckTy != Check::CheckComment)
-      FoundUsedCheckPrefix = true;
+      PrefixesNotFound.erase(UsedPrefix);
 
     assert(UsedPrefix.data() == Buffer.data() &&
            "Failed to move Buffer's start forward, or pointed prefix outside "
@@ -1930,14 +1934,16 @@
 
   // When there are no used prefixes we report an error except in the case that
   // no prefix is specified explicitly but -implicit-check-not is specified.
-  if (!FoundUsedCheckPrefix &&
+  if (!PrefixesNotFound.empty() &&
       (ImplicitNegativeChecks.empty() || !Req.IsDefaultCheckPrefix)) {
     errs() << "error: no check strings found with prefix"
            << (Req.CheckPrefixes.size() > 1 ? "es " : " ");
-    for (size_t I = 0, E = Req.CheckPrefixes.size(); I != E; ++I) {
-      if (I != 0)
+    bool First = true;
+    for (auto P : PrefixesNotFound.keys()) {
+      if (!First)
         errs() << ", ";
-      errs() << "\'" << Req.CheckPrefixes[I] << ":'";
+      errs() << "\'" << P << ":'";
+      First = false;
     }
     errs() << '\n';
     return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90281.301163.patch
Type: text/x-patch
Size: 1711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201028/4ca8c458/attachment.bin>


More information about the llvm-commits mailing list