[llvm] e1ed4d9 - Revert "[FileCheck] Make invalid prefix diagnostics more precise"

Joel E. Denny via llvm-commits llvm-commits at lists.llvm.org
Mon May 11 16:41:44 PDT 2020


Author: Joel E. Denny
Date: 2020-05-11T19:41:22-04:00
New Revision: e1ed4d9eb506a38772bfa659dcc09052eaff2e5d

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

LOG: Revert "[FileCheck] Make invalid prefix diagnostics more precise"

This reverts commit a78e13745d4ee4a42e41ebbe698159f651515fc5 to try to
fix a bot:

http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/23489

Added: 
    

Modified: 
    llvm/lib/Support/FileCheck.cpp
    llvm/test/FileCheck/validate-check-prefix.txt
    llvm/utils/FileCheck/FileCheck.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp
index 369b6dfa7edf..b89cdfe4520d 100644
--- a/llvm/lib/Support/FileCheck.cpp
+++ b/llvm/lib/Support/FileCheck.cpp
@@ -1874,37 +1874,33 @@ size_t FileCheckString::CheckDag(const SourceMgr &SM, StringRef Buffer,
   return StartPos;
 }
 
-static bool ValidatePrefixes(StringSet<> &UniquePrefixes,
-                             ArrayRef<StringRef> SuppliedPrefixes) {
-  for (StringRef Prefix : SuppliedPrefixes) {
-    if (Prefix.empty()) {
-      errs() << "error: supplied check prefix must not be the empty string\n";
+// A check prefix must contain only alphanumeric, hyphens and underscores.
+static bool ValidateCheckPrefix(StringRef CheckPrefix) {
+  static const Regex Validator("^[a-zA-Z0-9_-]*$");
+  return Validator.match(CheckPrefix);
+}
+
+bool FileCheck::ValidateCheckPrefixes() {
+  StringSet<> PrefixSet;
+
+  for (StringRef Prefix : Req.CheckPrefixes) {
+    // Reject empty prefixes.
+    if (Prefix.empty())
       return false;
-    }
-    static const Regex Validator("^[a-zA-Z0-9_-]*$");
-    if (!Validator.match(Prefix)) {
-      errs() << "error: supplied check prefix must start with a letter and "
-             << "contain only alphanumeric characters, hyphens, and "
-             << "underscores: '" << Prefix << "'\n";
+
+    if (!PrefixSet.insert(Prefix).second)
       return false;
-    }
-    if (!UniquePrefixes.insert(Prefix).second) {
-      errs() << "error: supplied check prefix must be unique among check "
-             << "prefixes: '" << Prefix << "'\n";
+
+    if (!ValidateCheckPrefix(Prefix))
       return false;
-    }
   }
-  return true;
-}
 
-bool FileCheck::ValidateCheckPrefixes() {
-  StringSet<> UniquePrefixes;
-  if (!ValidatePrefixes(UniquePrefixes, Req.CheckPrefixes))
-    return false;
   return true;
 }
 
 Regex FileCheck::buildCheckPrefixRegex() {
+  // I don't think there's a way to specify an initial value for cl::list,
+  // so if nothing was specified, add the default
   if (Req.CheckPrefixes.empty()) {
     Req.CheckPrefixes.push_back("CHECK");
     Req.IsDefaultCheckPrefix = true;

diff  --git a/llvm/test/FileCheck/validate-check-prefix.txt b/llvm/test/FileCheck/validate-check-prefix.txt
index 29f352cb1bd9..de6f126fd786 100644
--- a/llvm/test/FileCheck/validate-check-prefix.txt
+++ b/llvm/test/FileCheck/validate-check-prefix.txt
@@ -1,13 +1,10 @@
 // RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=A! -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
 // RUN: FileCheck -check-prefix=A1a-B_c -input-file %s %s
-// RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=REPEAT -check-prefix=REPEAT -input-file %s %s 2>&1 | FileCheck -check-prefix=DUPLICATE_PREFIX %s
+// RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=REPEAT -check-prefix=REPEAT -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
 // RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=VALID -check-prefix=A! -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
-// RUN: %ProtectFileCheckOutput not FileCheck -check-prefix= -input-file %s %s 2>&1 | FileCheck -check-prefix=EMPTY_PREFIX %s
+// RUN: %ProtectFileCheckOutput not FileCheck -check-prefix= -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
 foobar
 ; A1a-B_c: foobar
 
-; BAD_PREFIX: supplied check prefix must start with a letter and contain only alphanumeric characters, hyphens, and underscores: 'A!'
-
-; DUPLICATE_PREFIX: error: supplied check prefix must be unique among check prefixes: 'REPEAT'
-
-; EMPTY_PREFIX: error: supplied check prefix must not be the empty string
+; BAD_PREFIX: Supplied check-prefix is invalid! Prefixes must be
+  unique and start with a letter and contain only alphanumeric characters, hyphens and underscores

diff  --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp
index 46821ece7cd9..3f7d77711ee0 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -601,8 +601,12 @@ int main(int argc, char **argv) {
     Req.Verbose = true;
 
   FileCheck FC(Req);
-  if (!FC.ValidateCheckPrefixes())
+  if (!FC.ValidateCheckPrefixes()) {
+    errs() << "Supplied check-prefix is invalid! Prefixes must be unique and "
+              "start with a letter and contain only alphanumeric characters, "
+              "hyphens and underscores\n";
     return 2;
+  }
 
   Regex PrefixRE = FC.buildCheckPrefixRegex();
   std::string REError;


        


More information about the llvm-commits mailing list