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

Alexey Samsonov samsonov at google.com
Wed Nov 13 06:12:52 PST 2013


Author: samsonov
Date: Wed Nov 13 08:12:52 2013
New Revision: 194577

URL: http://llvm.org/viewvc/llvm-project?rev=194577&view=rev
Log:
FileCheck: fix matching of one check-prefix is a prefix of another

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

Added:
    llvm/trunk/test/FileCheck/check-multiple-prefixes-substr.txt
Modified:
    llvm/trunk/utils/FileCheck/FileCheck.cpp

Added: llvm/trunk/test/FileCheck/check-multiple-prefixes-substr.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FileCheck/check-multiple-prefixes-substr.txt?rev=194577&view=auto
==============================================================================
--- llvm/trunk/test/FileCheck/check-multiple-prefixes-substr.txt (added)
+++ llvm/trunk/test/FileCheck/check-multiple-prefixes-substr.txt Wed Nov 13 08:12:52 2013
@@ -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}}

Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=194577&r1=194576&r2=194577&view=diff
==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Wed Nov 13 08:12:52 2013
@@ -785,6 +785,10 @@ static StringRef FindFirstCandidateMatch
     // 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
     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;
 }
 





More information about the llvm-commits mailing list