Skip to content

Commit 662c043

Browse files
committed
[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 llvm-svn: 355928
1 parent c156306 commit 662c043

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

llvm/lib/Support/FileCheck.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,12 +1114,6 @@ bool FileCheckString::CheckNext(const SourceMgr &SM, StringRef Buffer) const {
11141114
Twine(Pat.getCheckTy() == Check::CheckEmpty ? "-EMPTY" : "-NEXT");
11151115

11161116
// Count the number of newlines between the previous match and this one.
1117-
assert(Buffer.data() !=
1118-
SM.getMemoryBuffer(SM.FindBufferContainingLoc(
1119-
SMLoc::getFromPointer(Buffer.data())))
1120-
->getBufferStart() &&
1121-
"CHECK-NEXT and CHECK-EMPTY can't be the first check in a file");
1122-
11231117
const char *FirstNewLine = nullptr;
11241118
unsigned NumNewLines = CountNumNewlinesBetween(Buffer, FirstNewLine);
11251119

@@ -1155,12 +1149,6 @@ bool FileCheckString::CheckSame(const SourceMgr &SM, StringRef Buffer) const {
11551149
return false;
11561150

11571151
// Count the number of newlines between the previous match and this one.
1158-
assert(Buffer.data() !=
1159-
SM.getMemoryBuffer(SM.FindBufferContainingLoc(
1160-
SMLoc::getFromPointer(Buffer.data())))
1161-
->getBufferStart() &&
1162-
"CHECK-SAME can't be the first check in a file");
1163-
11641152
const char *FirstNewLine = nullptr;
11651153
unsigned NumNewLines = CountNumNewlinesBetween(Buffer, FirstNewLine);
11661154

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
some text
2+
more text
3+
4+
RUN: FileCheck %s --check-prefix=NEXT --input-file=%s
5+
NEXT: {{^}}
6+
NEXT-NEXT: more text
7+
8+
RUN: FileCheck %s --check-prefix=SAME --input-file=%s
9+
SAME: {{^}}
10+
SAME-SAME: some text
11+
12+
RUN: echo "" > %t
13+
RUN: echo "" >> %t
14+
RUN: FileCheck %s --check-prefix=EMPTY --input-file=%t
15+
EMPTY: {{^}}
16+
EMPTY-EMPTY:

0 commit comments

Comments
 (0)