[llvm] [NFC][SpecialCaseList] Move "LongestMatch" logic from WarningsSpecialCaseList into SpecialCaseList (PR #162409)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 8 11:29:41 PDT 2025
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/162409
>From 666267e2307fa87498cc0625e82a02ae5424c0fc Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 7 Oct 2025 17:50:41 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
=?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6
[skip ci]
---
llvm/include/llvm/Support/SpecialCaseList.h | 13 ++++++++++++-
llvm/lib/Support/SpecialCaseList.cpp | 15 +++++++--------
2 files changed, 19 insertions(+), 9 deletions(-)
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<...>
More information about the llvm-commits
mailing list