[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

Danny Mösch via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 24 07:29:51 PDT 2024


================
@@ -454,52 +454,31 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " [-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob,
                          StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  GlobList Globs(CheckGlob);
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-       !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
-    Cur = Cur.trim();
-    if (Cur.empty())
+  for (const auto &Item : Globs.getItems()) {
+    const llvm::Regex &Reg = Item.Regex;
+    const llvm::StringRef Text = Item.Text;
+    if (Text.starts_with("clang-diagnostic"))
       continue;
-    Cur.consume_front("-");
-    if (Cur.starts_with("clang-diagnostic"))
-      continue;
-    if (Cur.contains('*')) {
-      SmallString<128> RegexText("^");
-      StringRef MetaChars("()^$|*+?.[]\\{}");
-      for (char C : Cur) {
-        if (C == '*')
-          RegexText.push_back('.');
-        else if (MetaChars.contains(C))
-          RegexText.push_back('\\');
-        RegexText.push_back(C);
-      }
-      RegexText.push_back('$');
-      llvm::Regex Glob(RegexText);
-      std::string Error;
-      if (!Glob.isValid(Error)) {
-        AnyInvalid = true;
-        llvm::WithColor::error(llvm::errs(), Source)
-            << "building check glob '" << Cur << "' " << Error << "'\n";
-        continue;
-      }
-      if (llvm::none_of(AllChecks.keys(),
-                        [&Glob](StringRef S) { return Glob.match(S); })) {
-        AnyInvalid = true;
+    if (llvm::none_of(AllChecks.keys(), [&Reg](StringRef S) {
+          llvm::errs() << S << '\n';
+          return Reg.match(S);
+        })) {
+      AnyInvalid = true;
+      if (Item.Text.contains('*'))
----------------
SimplyDanny wrote:

Previously this came before the checks for matches in line 466. Seems like the semantic has so changed slightly if only performance-wise, hasn't it?

https://github.com/llvm/llvm-project/pull/85591


More information about the cfe-commits mailing list