Skip to content

Commit a056ef7

Browse files
committed
filecheck: forbid filecheck prefix to ends with directive name
1 parent 9940620 commit a056ef7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,9 @@ FileCheckString::CheckDag(const SourceMgr &SM, StringRef Buffer,
24682468

24692469
static bool ValidatePrefixes(StringRef Kind, StringSet<> &UniquePrefixes,
24702470
ArrayRef<StringRef> SuppliedPrefixes) {
2471+
static const char *Suffixes[] = {"-NEXT", "-SAME", "-EMPTY", "-NOT",
2472+
"-COUNT", "-DAG", "-LABEL"};
2473+
24712474
for (StringRef Prefix : SuppliedPrefixes) {
24722475
if (Prefix.empty()) {
24732476
errs() << "error: supplied " << Kind << " prefix must not be the empty "
@@ -2486,6 +2489,13 @@ static bool ValidatePrefixes(StringRef Kind, StringSet<> &UniquePrefixes,
24862489
<< "check and comment prefixes: '" << Prefix << "'\n";
24872490
return false;
24882491
}
2492+
for (StringRef Suffix : Suffixes) {
2493+
if (Prefix.ends_with(Suffix)) {
2494+
errs() << "error: supplied " << Kind << " prefix must not end with "
2495+
<< "directive: '" << Suffix << "', prefix: '" << Prefix << "'\n";
2496+
return false;
2497+
}
2498+
}
24892499
}
24902500
return true;
24912501
}

0 commit comments

Comments
 (0)