From 1e6e80480b14314d5cd0c595f5698103570855b6 Mon Sep 17 00:00:00 2001 From: James Henderson Date: Tue, 12 Mar 2019 15:37:34 +0000 Subject: [PATCH] [FileCheck]Remove assertions that prevent matching an empty string at file start before CHECK-NEXT/SAME This patch removes two assertions that were preventing writing of a test that checked an empty line followed by some text. For example: 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. Reviewed by: probinson, thopre, jdenny Differential Revision: https://reviews.llvm.org/D58784 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355928 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/FileCheck.cpp | 12 ------------ test/FileCheck/empty-regex-match-at-start.txt | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 test/FileCheck/empty-regex-match-at-start.txt diff --git a/lib/Support/FileCheck.cpp b/lib/Support/FileCheck.cpp index 5f6ffab894b..92c42646e7e 100644 --- a/lib/Support/FileCheck.cpp +++ b/lib/Support/FileCheck.cpp @@ -1114,12 +1114,6 @@ bool FileCheckString::CheckNext(const SourceMgr &SM, StringRef Buffer) const { 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 @@ bool FileCheckString::CheckSame(const SourceMgr &SM, StringRef Buffer) const { 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); diff --git a/test/FileCheck/empty-regex-match-at-start.txt b/test/FileCheck/empty-regex-match-at-start.txt new file mode 100644 index 00000000000..8a6ea60d3eb --- /dev/null +++ b/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: -- 2.50.1