[llvm] 4f6cb06 - [NFC][SpecialCaseList] Move "LongestMatch" logic from WarningsSpecialCaseList into SpecialCaseList (#162409)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 8 12:03:30 PDT 2025
Author: Vitaly Buka
Date: 2025-10-08T19:03:25Z
New Revision: 4f6cb060b105f38d3652886b0f5b183cafe91095
URL: https://github.com/llvm/llvm-project/commit/4f6cb060b105f38d3652886b0f5b183cafe91095
DIFF: https://github.com/llvm/llvm-project/commit/4f6cb060b105f38d3652886b0f5b183cafe91095.diff
LOG: [NFC][SpecialCaseList] Move "LongestMatch" logic from WarningsSpecialCaseList into SpecialCaseList (#162409)
This way we can be more flexible optimizing SpecialCaseList internals.
Added:
Modified:
clang/lib/Basic/Diagnostic.cpp
llvm/lib/Support/SpecialCaseList.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 2b89370a42d1b..a955c3bca337f 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -517,12 +517,6 @@ class WarningsSpecialCaseList : public llvm::SpecialCaseList {
const SourceManager &SM) const;
private:
- // Find the longest glob pattern that matches FilePath amongst
- // CategoriesToMatchers, return true iff the match exists and belongs to a
- // positive category.
- bool globsMatches(const llvm::StringMap<Matcher> &CategoriesToMatchers,
- StringRef FilePath) const;
-
llvm::DenseMap<diag::kind, const Section *> DiagToSection;
};
} // namespace
@@ -584,43 +578,24 @@ void DiagnosticsEngine::setDiagSuppressionMapping(llvm::MemoryBuffer &Input) {
bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind DiagId,
SourceLocation DiagLoc,
const SourceManager &SM) const {
+ PresumedLoc PLoc = SM.getPresumedLoc(DiagLoc);
+ if (!PLoc.isValid())
+ return false;
const Section *DiagSection = DiagToSection.lookup(DiagId);
if (!DiagSection)
return false;
- const SectionEntries &EntityTypeToCategories = DiagSection->Entries;
- auto SrcEntriesIt = EntityTypeToCategories.find("src");
- if (SrcEntriesIt == EntityTypeToCategories.end())
+
+ StringRef F = llvm::sys::path::remove_leading_dotslash(PLoc.getFilename());
+
+ StringRef LongestSup = DiagSection->getLongestMatch("src", F, "");
+ if (LongestSup.empty())
return false;
- const llvm::StringMap<llvm::SpecialCaseList::Matcher> &CategoriesToMatchers =
- SrcEntriesIt->getValue();
- // We also use presumed locations here to improve reproducibility for
- // preprocessed inputs.
- if (PresumedLoc PLoc = SM.getPresumedLoc(DiagLoc); PLoc.isValid())
- return globsMatches(
- CategoriesToMatchers,
- llvm::sys::path::remove_leading_dotslash(PLoc.getFilename()));
- return false;
-}
-bool WarningsSpecialCaseList::globsMatches(
- const llvm::StringMap<Matcher> &CategoriesToMatchers,
- StringRef FilePath) const {
- StringRef LongestMatch;
- bool LongestIsPositive = false;
- for (const auto &Entry : CategoriesToMatchers) {
- StringRef Category = Entry.getKey();
- const llvm::SpecialCaseList::Matcher &Matcher = Entry.getValue();
- bool IsPositive = Category != "emit";
- for (const auto &Glob : Matcher.Globs) {
- if (Glob->Name.size() < LongestMatch.size())
- continue;
- if (!Glob->Pattern.match(FilePath))
- continue;
- LongestMatch = Glob->Name;
- LongestIsPositive = IsPositive;
- }
- }
- return LongestIsPositive;
+ StringRef LongestEmit = DiagSection->getLongestMatch("src", F, "emit");
+ if (LongestEmit.empty())
+ return true;
+
+ return LongestSup.size() > LongestEmit.size();
}
bool DiagnosticsEngine::isSuppressedViaMapping(diag::kind DiagId,
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 6c684376d493c..f184efa433f3d 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -273,4 +273,17 @@ unsigned SpecialCaseList::Section::getLastMatch(StringRef Prefix,
return LastLine;
}
+StringRef SpecialCaseList::Section::getLongestMatch(StringRef Prefix,
+ StringRef Query,
+ StringRef Category) const {
+ StringRef LongestRule;
+ if (const Matcher *M = findMatcher(Prefix, Category)) {
+ M->match(Query, [&](StringRef Rule, unsigned) {
+ if (LongestRule.size() < Rule.size())
+ LongestRule = Rule;
+ });
+ }
+ return LongestRule;
+}
+
} // namespace llvm
More information about the llvm-commits
mailing list