aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/FileCheck.cpp
diff options
context:
space:
mode:
authorJoel E. Denny <jdenny.ornl@gmail.com>2020-05-11 09:57:37 -0400
committerJoel E. Denny <jdenny.ornl@gmail.com>2020-05-11 21:11:58 -0400
commit2aa0217add1adbcabbc16e3ec44937e4277e117b (patch)
treef9bcf79c9d6dbe11cd313823896b80fbb183a0bf /llvm/lib/Support/FileCheck.cpp
parent1429e4c3992d2a5f90de5879773b6cf5a050cb5e (diff)
downloadllvm-2aa0217add1adbcabbc16e3ec44937e4277e117b.zip
llvm-2aa0217add1adbcabbc16e3ec44937e4277e117b.tar.gz
llvm-2aa0217add1adbcabbc16e3ec44937e4277e117b.tar.bz2
[FileCheck] Make invalid prefix diagnostics more precise
This will prove especially helpful after D79276, which introduces comment prefixes. Specifically, identifying whether there's a uniqueness violation will be helpful as prefixes will be required to be unique across both check prefixes and comment prefixes. Also, remove a related comment about `cl::list` that no longer seems relevant now that FileCheck is also a library. Reviewed By: jhenderson, thopre Differential Revision: https://reviews.llvm.org/D79375
Diffstat (limited to 'llvm/lib/Support/FileCheck.cpp')
-rw-r--r--llvm/lib/Support/FileCheck.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp
index b89cdfe..369b6df 100644
--- a/llvm/lib/Support/FileCheck.cpp
+++ b/llvm/lib/Support/FileCheck.cpp
@@ -1874,33 +1874,37 @@ size_t FileCheckString::CheckDag(const SourceMgr &SM, StringRef Buffer,
return StartPos;
}
-// A check prefix must contain only alphanumeric, hyphens and underscores.
-static bool ValidateCheckPrefix(StringRef CheckPrefix) {
- static const Regex Validator("^[a-zA-Z0-9_-]*$");
- return Validator.match(CheckPrefix);
-}
-
-bool FileCheck::ValidateCheckPrefixes() {
- StringSet<> PrefixSet;
-
- for (StringRef Prefix : Req.CheckPrefixes) {
- // Reject empty prefixes.
- if (Prefix.empty())
+static bool ValidatePrefixes(StringSet<> &UniquePrefixes,
+ ArrayRef<StringRef> SuppliedPrefixes) {
+ for (StringRef Prefix : SuppliedPrefixes) {
+ if (Prefix.empty()) {
+ errs() << "error: supplied check prefix must not be the empty string\n";
return false;
-
- if (!PrefixSet.insert(Prefix).second)
+ }
+ static const Regex Validator("^[a-zA-Z0-9_-]*$");
+ if (!Validator.match(Prefix)) {
+ errs() << "error: supplied check prefix must start with a letter and "
+ << "contain only alphanumeric characters, hyphens, and "
+ << "underscores: '" << Prefix << "'\n";
return false;
-
- if (!ValidateCheckPrefix(Prefix))
+ }
+ if (!UniquePrefixes.insert(Prefix).second) {
+ errs() << "error: supplied check prefix must be unique among check "
+ << "prefixes: '" << Prefix << "'\n";
return false;
+ }
}
+ return true;
+}
+bool FileCheck::ValidateCheckPrefixes() {
+ StringSet<> UniquePrefixes;
+ if (!ValidatePrefixes(UniquePrefixes, Req.CheckPrefixes))
+ return false;
return true;
}
Regex FileCheck::buildCheckPrefixRegex() {
- // I don't think there's a way to specify an initial value for cl::list,
- // so if nothing was specified, add the default
if (Req.CheckPrefixes.empty()) {
Req.CheckPrefixes.push_back("CHECK");
Req.IsDefaultCheckPrefix = true;