Skip to content

Commit ba702aa

Browse files
committed
filecheck: forbid filecheck prefix to ends with directive name
1 parent 9b01522 commit ba702aa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 11 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 *Directives[] = {"-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,14 @@ static bool ValidatePrefixes(StringRef Kind, StringSet<> &UniquePrefixes,
24862489
<< "check and comment prefixes: '" << Prefix << "'\n";
24872490
return false;
24882491
}
2492+
for (StringRef Directive : Directives) {
2493+
if (Prefix.ends_with(Directive)) {
2494+
errs() << "error: supplied " << Kind << " prefix must not ends with "
2495+
<< "directive: '" << Directive << "', prefix: '" << Prefix
2496+
<< "'\n";
2497+
return false;
2498+
}
2499+
}
24892500
}
24902501
return true;
24912502
}

0 commit comments

Comments
 (0)