[llvm] [FileCheck] improve prefix validation (PR #92248)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 04:37:54 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-testing-tools
Author: klensy (klensy)
<details>
<summary>Changes</summary>
First commit fixes already existing check with wrong regex, this should break few tests: like https://github.com/llvm/llvm-project/blob/7621a0d36465cf870769cd54035d254d409c2ce4/llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-outline_atomics.ll#L3
Second commit forbids prefixes ends with directive name, like here, to prevent ambiguity: https://github.com/llvm/llvm-project/blob/de18f5ecf80ef7183625c80b04445c614a17c483/lld/test/ELF/arm-exidx-shared.s#L5
---
Full diff: https://github.com/llvm/llvm-project/pull/92248.diff
1 Files Affected:
- (modified) llvm/lib/FileCheck/FileCheck.cpp (+12-1)
``````````diff
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 1719f8ef2b436..0d511611511d2 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -2468,13 +2468,16 @@ FileCheckString::CheckDag(const SourceMgr &SM, StringRef Buffer,
static bool ValidatePrefixes(StringRef Kind, StringSet<> &UniquePrefixes,
ArrayRef<StringRef> SuppliedPrefixes) {
+ static const char *Directives[] = {"-NEXT", "-SAME", "-EMPTY", "-NOT",
+ "-COUNT", "-DAG", "-LABEL"};
+
for (StringRef Prefix : SuppliedPrefixes) {
if (Prefix.empty()) {
errs() << "error: supplied " << Kind << " prefix must not be the empty "
<< "string\n";
return false;
}
- static const Regex Validator("^[a-zA-Z0-9_-]*$");
+ static const Regex Validator("^[a-zA-Z][a-zA-Z0-9_-]*$");
if (!Validator.match(Prefix)) {
errs() << "error: supplied " << Kind << " prefix must start with a "
<< "letter and contain only alphanumeric characters, hyphens, and "
@@ -2486,6 +2489,14 @@ static bool ValidatePrefixes(StringRef Kind, StringSet<> &UniquePrefixes,
<< "check and comment prefixes: '" << Prefix << "'\n";
return false;
}
+ for (StringRef Directive : Directives) {
+ if (Prefix.ends_with(Directive)) {
+ errs() << "error: supplied " << Kind << " prefix must not ends with "
+ << "directive: '" << Directive << "', prefix: '" << Prefix
+ << "'\n";
+ return false;
+ }
+ }
}
return true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/92248
More information about the llvm-commits
mailing list