FileCheck: fix matching of one check-prefix is a prefix of another
authorAlexey Samsonov <samsonov@google.com>
Wed, 13 Nov 2013 14:12:52 +0000 (14:12 +0000)
committerAlexey Samsonov <samsonov@google.com>
Wed, 13 Nov 2013 14:12:52 +0000 (14:12 +0000)
Summary:
Fix a case when "FileCheck --check-prefix=CHECK --check-prefix=CHECKER"
would silently ignore check-lines of the form:
  CHECKER: foo

Reviewers: dsanders

Reviewed By: dsanders

CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D2168

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194577 91177308-0d34-0410-b5e6-96231b3b80d8

test/FileCheck/check-multiple-prefixes-substr.txt [new file with mode: 0644]
utils/FileCheck/FileCheck.cpp

diff --git a/test/FileCheck/check-multiple-prefixes-substr.txt b/test/FileCheck/check-multiple-prefixes-substr.txt
new file mode 100644 (file)
index 0000000..76a2ca8
--- /dev/null
@@ -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 d5f760246d6697c7f32ee13f0d331998d4aff76f..f2510d7dfd708dc9b7493e2035316e50e5bbee71 100644 (file)
@@ -785,6 +785,10 @@ static StringRef FindFirstCandidateMatch(StringRef &Buffer,
     // 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
@@ -793,22 +797,19 @@ static StringRef FindFirstCandidateMatch(StringRef &Buffer,
     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;
 }