Skip to content

Commit a05a2a7

Browse files
author
git apple-llvm automerger
committed
Merge commit '4f6cb060b105' from llvm.org/main into next
2 parents b47fdc8 + 4f6cb06 commit a05a2a7

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

clang/lib/Basic/Diagnostic.cpp

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,6 @@ class WarningsSpecialCaseList : public llvm::SpecialCaseList {
525525
const SourceManager &SM) const;
526526

527527
private:
528-
// Find the longest glob pattern that matches FilePath amongst
529-
// CategoriesToMatchers, return true iff the match exists and belongs to a
530-
// positive category.
531-
bool globsMatches(const llvm::StringMap<Matcher> &CategoriesToMatchers,
532-
StringRef FilePath) const;
533-
534528
llvm::DenseMap<diag::kind, const Section *> DiagToSection;
535529
};
536530
} // namespace
@@ -592,43 +586,24 @@ void DiagnosticsEngine::setDiagSuppressionMapping(llvm::MemoryBuffer &Input) {
592586
bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind DiagId,
593587
SourceLocation DiagLoc,
594588
const SourceManager &SM) const {
589+
PresumedLoc PLoc = SM.getPresumedLoc(DiagLoc);
590+
if (!PLoc.isValid())
591+
return false;
595592
const Section *DiagSection = DiagToSection.lookup(DiagId);
596593
if (!DiagSection)
597594
return false;
598-
const SectionEntries &EntityTypeToCategories = DiagSection->Entries;
599-
auto SrcEntriesIt = EntityTypeToCategories.find("src");
600-
if (SrcEntriesIt == EntityTypeToCategories.end())
595+
596+
StringRef F = llvm::sys::path::remove_leading_dotslash(PLoc.getFilename());
597+
598+
StringRef LongestSup = DiagSection->getLongestMatch("src", F, "");
599+
if (LongestSup.empty())
601600
return false;
602-
const llvm::StringMap<llvm::SpecialCaseList::Matcher> &CategoriesToMatchers =
603-
SrcEntriesIt->getValue();
604-
// We also use presumed locations here to improve reproducibility for
605-
// preprocessed inputs.
606-
if (PresumedLoc PLoc = SM.getPresumedLoc(DiagLoc); PLoc.isValid())
607-
return globsMatches(
608-
CategoriesToMatchers,
609-
llvm::sys::path::remove_leading_dotslash(PLoc.getFilename()));
610-
return false;
611-
}
612601

613-
bool WarningsSpecialCaseList::globsMatches(
614-
const llvm::StringMap<Matcher> &CategoriesToMatchers,
615-
StringRef FilePath) const {
616-
StringRef LongestMatch;
617-
bool LongestIsPositive = false;
618-
for (const auto &Entry : CategoriesToMatchers) {
619-
StringRef Category = Entry.getKey();
620-
const llvm::SpecialCaseList::Matcher &Matcher = Entry.getValue();
621-
bool IsPositive = Category != "emit";
622-
for (const auto &Glob : Matcher.Globs) {
623-
if (Glob->Name.size() < LongestMatch.size())
624-
continue;
625-
if (!Glob->Pattern.match(FilePath))
626-
continue;
627-
LongestMatch = Glob->Name;
628-
LongestIsPositive = IsPositive;
629-
}
630-
}
631-
return LongestIsPositive;
602+
StringRef LongestEmit = DiagSection->getLongestMatch("src", F, "emit");
603+
if (LongestEmit.empty())
604+
return true;
605+
606+
return LongestSup.size() > LongestEmit.size();
632607
}
633608

634609
bool DiagnosticsEngine::isSuppressedViaMapping(diag::kind DiagId,

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,17 @@ unsigned SpecialCaseList::Section::getLastMatch(StringRef Prefix,
273273
return LastLine;
274274
}
275275

276+
StringRef SpecialCaseList::Section::getLongestMatch(StringRef Prefix,
277+
StringRef Query,
278+
StringRef Category) const {
279+
StringRef LongestRule;
280+
if (const Matcher *M = findMatcher(Prefix, Category)) {
281+
M->match(Query, [&](StringRef Rule, unsigned) {
282+
if (LongestRule.size() < Rule.size())
283+
LongestRule = Rule;
284+
});
285+
}
286+
return LongestRule;
287+
}
288+
276289
} // namespace llvm

0 commit comments

Comments
 (0)