Skip to content

Conversation

vitalybuka
Copy link
Collaborator

To pass something into Cb in match().

No need to bother with test coverage, as it's
legacy transitional code, maybe we can remove it
soon.

Created using spr 1.3.6
@llvmbot
Copy link
Member

llvmbot commented Oct 8, 2025

@llvm/pr-subscribers-llvm-support

Author: Vitaly Buka (vitalybuka)

Changes

To pass something into Cb in match().

No need to bother with test coverage, as it's
legacy transitional code, maybe we can remove it
soon.


Full diff: https://github.com/llvm/llvm-project/pull/162408.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Support/SpecialCaseList.h (+12-1)
  • (modified) llvm/lib/Support/SpecialCaseList.cpp (+7-8)
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h
index bb382f64b084f..64cad804ad911 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -134,6 +134,7 @@ class SpecialCaseList {
     }
 
     struct Glob {
+      Glob(StringRef Name, unsigned LineNo) : Name(Name), LineNo(LineNo) {}
       std::string Name;
       unsigned LineNo;
       GlobPattern Pattern;
@@ -143,8 +144,18 @@ class SpecialCaseList {
       Glob() = default;
     };
 
+    struct Reg {
+      Reg(StringRef Name, unsigned LineNo, Regex &&Rg)
+          : Name(Name), LineNo(LineNo), Rg(std::move(Rg)) {}
+      std::string Name;
+      unsigned LineNo;
+      Regex Rg;
+      Reg(Reg &&) = delete;
+      Reg() = default;
+    };
+
     std::vector<std::unique_ptr<Matcher::Glob>> Globs;
-    std::vector<std::pair<std::unique_ptr<Regex>, unsigned>> RegExes;
+    std::vector<std::unique_ptr<Reg>> RegExes;
   };
 
   using SectionEntries = StringMap<StringMap<Matcher>>;
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 9a1b47faab3ed..6ad8d7d4e7ffa 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -52,15 +52,14 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
     if (!CheckRE.isValid(REError))
       return createStringError(errc::invalid_argument, REError);
 
-    RegExes.emplace_back(std::make_pair(
-        std::make_unique<Regex>(std::move(CheckRE)), LineNumber));
+    auto Rg =
+        std::make_unique<Matcher::Reg>(Pattern, LineNumber, std::move(CheckRE));
+    RegExes.emplace_back(std::move(Rg));
 
     return Error::success();
   }
 
-  auto Glob = std::make_unique<Matcher::Glob>();
-  Glob->Name = Pattern.str();
-  Glob->LineNo = LineNumber;
+  auto Glob = std::make_unique<Matcher::Glob>(Pattern, LineNumber);
   // We must be sure to use the string in `Glob` rather than the provided
   // reference which could be destroyed before match() is called
   if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024)
@@ -76,9 +75,9 @@ void SpecialCaseList::Matcher::match(
   for (const auto &Glob : reverse(Globs))
     if (Glob->Pattern.match(Query))
       Cb(Glob->Name, Glob->LineNo);
-  for (const auto &[Regex, LineNumber] : reverse(RegExes))
-    if (Regex->match(Query))
-      Cb(/*FIXME: there is no users of this param yet */ "", LineNumber);
+  for (const auto &Regex : reverse(RegExes))
+    if (Regex->Rg.match(Query))
+      Cb(Regex->Name, Regex->LineNo);
 }
 
 // TODO: Refactor this to return Expected<...>

@vitalybuka vitalybuka enabled auto-merge (squash) October 8, 2025 00:52
@vitalybuka vitalybuka changed the title [NFC][SpecialCaseList] Add Name into Regex version [NFC][SpecialCaseList] Add Name into Regex matcher Oct 8, 2025
@vitalybuka vitalybuka merged commit 7212d27 into main Oct 8, 2025
9 of 10 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/nfcspecialcaselist-add-name-into-regex-version branch October 8, 2025 01:22
@vitalybuka
Copy link
Collaborator Author

Ops, I didn't expect it will autosubmit without review.
@fmayer It's trivial, but please take a look

svkeerthy pushed a commit that referenced this pull request Oct 9, 2025
To pass something into Cb in `match()`.

No need to bother with test coverage, as it's
legacy transitional code, maybe we can remove it
soon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants