[PATCH] D58784: [FileCheck]Remove assertions that prevent matching an empty string at file start before CHECK-NEXT/SAME

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 28 06:33:49 PST 2019


jhenderson created this revision.
jhenderson added reviewers: probinson, fedor.sergeev, jdenny.
Herald added subscribers: thopre, kristina.
Herald added a project: LLVM.

This patch removes two assertions that were preventing me writing a test that checked an empty line followed by some text. Here is an example of a set of patterns that caused FileCheck to assert.

  CHECK: {{^$}}
  CHECK-NEXT: foo()

The assertion was because the current location the CHECK-NEXT was scanning from was the start of the buffer. A similar issue occurred with CHECK-SAME. These assertions don't protect against anything, as there is already an error check that checks that CHECK-NEXT/EMPTY/SAME don't appear first in the checks, and the following code works fine if the pointer is at the start of the input.


Repository:
  rL LLVM

https://reviews.llvm.org/D58784

Files:
  lib/Support/FileCheck.cpp
  test/FileCheck/empty-regex-match-at-start.txt


Index: test/FileCheck/empty-regex-match-at-start.txt
===================================================================
--- test/FileCheck/empty-regex-match-at-start.txt
+++ test/FileCheck/empty-regex-match-at-start.txt
@@ -0,0 +1,16 @@
+some text
+more text
+
+; RUN: FileCheck %s --check-prefix=NEXT --input-file=%s
+; NEXT:      {{^}}
+; NEXT-NEXT: more text
+
+; RUN: FileCheck %s --check-prefix=SAME --input-file=%s
+; SAME:      {{^}}
+; SAME-SAME: some text
+
+; RUN: echo "" > %t
+; RUN: echo "" >> %t
+; RUN: FileCheck %s --check-prefix=EMPTY --input-file=%t
+; EMPTY:       {{^}}
+; EMPTY-EMPTY:
Index: lib/Support/FileCheck.cpp
===================================================================
--- lib/Support/FileCheck.cpp
+++ lib/Support/FileCheck.cpp
@@ -1114,12 +1114,6 @@
       Twine(Pat.getCheckTy() == Check::CheckEmpty ? "-EMPTY" : "-NEXT");
 
   // Count the number of newlines between the previous match and this one.
-  assert(Buffer.data() !=
-             SM.getMemoryBuffer(SM.FindBufferContainingLoc(
-                                    SMLoc::getFromPointer(Buffer.data())))
-                 ->getBufferStart() &&
-         "CHECK-NEXT and CHECK-EMPTY can't be the first check in a file");
-
   const char *FirstNewLine = nullptr;
   unsigned NumNewLines = CountNumNewlinesBetween(Buffer, FirstNewLine);
 
@@ -1155,12 +1149,6 @@
     return false;
 
   // Count the number of newlines between the previous match and this one.
-  assert(Buffer.data() !=
-             SM.getMemoryBuffer(SM.FindBufferContainingLoc(
-                                    SMLoc::getFromPointer(Buffer.data())))
-                 ->getBufferStart() &&
-         "CHECK-SAME can't be the first check in a file");
-
   const char *FirstNewLine = nullptr;
   unsigned NumNewLines = CountNumNewlinesBetween(Buffer, FirstNewLine);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58784.188733.patch
Type: text/x-patch
Size: 1839 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190228/30911527/attachment.bin>


More information about the llvm-commits mailing list