FileCheck: fix a bug with multiple --check-prefix options.
authorAlexey Samsonov <samsonov@google.com>
Wed, 13 Nov 2013 11:56:22 +0000 (11:56 +0000)
committerAlexey Samsonov <samsonov@google.com>
Wed, 13 Nov 2013 11:56:22 +0000 (11:56 +0000)
Summary:
This fixes a subtle bug in new FileCheck feature added
in r194343. When we search for the first satisfying check-prefix,
we should actually return the first encounter of some check-prefix as a
substring, even if it's not a part of valid check-line. Otherwise
"FileCheck --check-prefix=FOO --check-prefix=BAR" with check file:

  FOO not a vaild check-line
  FOO: foo
  BAR: bar

incorrectly accepted file:

  fog
  bar

as it skipped the first two encounters of FOO, matching only BAR: line.

Reviewers: arsenm, dsanders

Reviewed By: dsanders

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

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

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

diff --git a/test/FileCheck/check-multiple-prefixes-nomatch.txt b/test/FileCheck/check-multiple-prefixes-nomatch.txt
new file mode 100644 (file)
index 0000000..9d38359
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: not FileCheck -input-file %s %s -check-prefix=FOO -check-prefix=BAR 2>&1 | FileCheck %s
+
+BAR
+bar
+foo
+; BAR: ba{{z}}
+; FOO: fo{{o}}
+
+; CHECK: {{error: expected string not found in input}}
+; CHECK-NEXT: {{B}}AR: ba{{[{][{]z[}][}]}}
index c9eb8a650c809120be67d68dc8b0d8c3d1953a10..d5f760246d6697c7f32ee13f0d331998d4aff76f 100644 (file)
@@ -794,12 +794,12 @@ static StringRef FindFirstCandidateMatch(StringRef &Buffer,
       continue;
 
     Check::CheckType Ty = FindCheckType(Rest, Prefix);
-    if (Ty == Check::CheckNone)
-      continue;
 
     FirstLoc = PrefixLoc;
     FirstTy = Ty;
-    FirstPrefix = Prefix;
+    // We've found the first matching check prefix. If it is invalid, we should
+    // continue the search after it.
+    FirstPrefix = (Ty == Check::CheckNone) ? "" : Prefix;
   }
 
   if (FirstPrefix.empty()) {