[PATCH] FileCheck: fix matching of one check-prefix is a prefix of another

Alexey Samsonov samsonov at google.com
Wed Nov 13 05:03:02 PST 2013


Hi dsanders,

Fix a case when "FileCheck --check-prefix=CHECK --check-prefix=CHECKER"
would silently ignore check-lines of the form:
  CHECKER: foo

http://llvm-reviews.chandlerc.com/D2168

Files:
  test/FileCheck/check-multiple-prefixes-substr.txt
  utils/FileCheck/FileCheck.cpp

Index: test/FileCheck/check-multiple-prefixes-substr.txt
===================================================================
--- /dev/null
+++ test/FileCheck/check-multiple-prefixes-substr.txt
@@ -0,0 +1,5 @@
+// RUN: FileCheck -check-prefix=CHECKER -check-prefix=CHECK -input-file %s %s
+// RUN: FileCheck -check-prefix=CHECK -check-prefix=CHECKER -input-file %s %s
+
+foo
+; CHECKER: fo{{o}}
Index: utils/FileCheck/FileCheck.cpp
===================================================================
--- utils/FileCheck/FileCheck.cpp
+++ utils/FileCheck/FileCheck.cpp
@@ -785,30 +785,31 @@
     // We only want to find the first match to avoid skipping some.
     if (PrefixLoc > FirstLoc)
       continue;
+    // If one matching check-prefix is a prefix of another, choose the
+    // longer one.
+    if (PrefixLoc == FirstLoc && Prefix.size() < FirstPrefix.size())
+      continue;
 
     StringRef Rest = Buffer.drop_front(PrefixLoc);
     // Make sure we have actually found the prefix, and not a word containing
     // it. This should also prevent matching the wrong prefix when one is a
     // substring of another.
     if (PrefixLoc != 0 && IsPartOfWord(Buffer[PrefixLoc - 1]))
       continue;
 
-    Check::CheckType Ty = FindCheckType(Rest, Prefix);
-
     FirstLoc = PrefixLoc;
-    FirstTy = Ty;
-    // We've found the first matching check prefix. If it is invalid, we should
-    // continue the search after it.
-    FirstPrefix = (Ty == Check::CheckNone) ? "" : Prefix;
+    FirstTy = FindCheckType(Rest, Prefix);
+    FirstPrefix = Prefix;
   }
 
-  if (FirstPrefix.empty()) {
+  // If the first prefix is invalid, we should continue the search after it.
+  if (FirstTy == Check::CheckNone) {
     CheckLoc = SearchLoc;
-  } else {
-    CheckTy = FirstTy;
-    CheckLoc = FirstLoc;
+    return "";
   }
 
+  CheckTy = FirstTy;
+  CheckLoc = FirstLoc;
   return FirstPrefix;
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2168.1.patch
Type: text/x-patch
Size: 1900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131113/d974498f/attachment.bin>


More information about the llvm-commits mailing list