@@ -517,12 +517,6 @@ class WarningsSpecialCaseList : public llvm::SpecialCaseList {
517517 const SourceManager &SM) const ;
518518
519519private:
520- // Find the longest glob pattern that matches FilePath amongst
521- // CategoriesToMatchers, return true iff the match exists and belongs to a
522- // positive category.
523- bool globsMatches (const llvm::StringMap<Matcher> &CategoriesToMatchers,
524- StringRef FilePath) const ;
525-
526520 llvm::DenseMap<diag::kind, const Section *> DiagToSection;
527521};
528522} // namespace
@@ -537,33 +531,16 @@ WarningsSpecialCaseList::create(const llvm::MemoryBuffer &Input,
537531}
538532
539533void WarningsSpecialCaseList::processSections (DiagnosticsEngine &Diags) {
540- // Drop the default section introduced by special case list, we only support
541- // exact diagnostic group names.
542- // FIXME: We should make this configurable in the parser instead.
543- // FIXME: C++20 can use std::erase_if(Sections, [](Section &sec) { return
544- // sec.SectionStr == "*"; });
545- llvm::erase_if (Sections, [](Section &sec) { return sec.SectionStr == " *" ; });
546- // Make sure we iterate sections by their line numbers.
547- std::vector<std::pair<unsigned , const Section *>> LineAndSectionEntry;
548- LineAndSectionEntry.reserve (Sections.size ());
549- for (const auto &Entry : Sections) {
550- StringRef DiagName = Entry.SectionStr ;
551- // Each section has a matcher with that section's name, attached to that
552- // line.
553- const auto &DiagSectionMatcher = Entry.SectionMatcher ;
554- unsigned DiagLine = 0 ;
555- for (const auto &Glob : DiagSectionMatcher->Globs )
556- if (Glob->Name == DiagName) {
557- DiagLine = Glob->LineNo ;
558- break ;
559- }
560- LineAndSectionEntry.emplace_back (DiagLine, &Entry);
561- }
562- llvm::sort (LineAndSectionEntry);
563534 static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
564- for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
535+ for (const auto &SectionEntry : Sections) {
536+ StringRef DiagGroup = SectionEntry.SectionStr ;
537+ if (DiagGroup == " *" ) {
538+ // Drop the default section introduced by special case list, we only
539+ // support exact diagnostic group names.
540+ // FIXME: We should make this configurable in the parser instead.
541+ continue ;
542+ }
565543 SmallVector<diag::kind> GroupDiags;
566- StringRef DiagGroup = SectionEntry->SectionStr ;
567544 if (Diags.getDiagnosticIDs ()->getDiagnosticsInGroup (
568545 WarningFlavor, DiagGroup, GroupDiags)) {
569546 StringRef Suggestion =
@@ -576,7 +553,7 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
576553 for (diag::kind Diag : GroupDiags)
577554 // We're intentionally overwriting any previous mappings here to make sure
578555 // latest one takes precedence.
579- DiagToSection[Diag] = SectionEntry;
556+ DiagToSection[Diag] = & SectionEntry;
580557 }
581558}
582559
@@ -601,43 +578,26 @@ void DiagnosticsEngine::setDiagSuppressionMapping(llvm::MemoryBuffer &Input) {
601578bool WarningsSpecialCaseList::isDiagSuppressed (diag::kind DiagId,
602579 SourceLocation DiagLoc,
603580 const SourceManager &SM) const {
581+ PresumedLoc PLoc = SM.getPresumedLoc (DiagLoc);
582+ if (!PLoc.isValid ())
583+ return false ;
604584 const Section *DiagSection = DiagToSection.lookup (DiagId);
605585 if (!DiagSection)
606586 return false ;
607- const SectionEntries &EntityTypeToCategories = DiagSection->Entries ;
608- auto SrcEntriesIt = EntityTypeToCategories.find (" src" );
609- if (SrcEntriesIt == EntityTypeToCategories.end ())
587+
588+ StringRef F = llvm::sys::path::remove_leading_dotslash (PLoc.getFilename ());
589+
590+ unsigned SuppressLineNo =
591+ llvm::SpecialCaseList::inSectionBlame (DiagSection->Entries , " src" , F, " " );
592+ if (!SuppressLineNo)
610593 return false ;
611- const llvm::StringMap<llvm::SpecialCaseList::Matcher> &CategoriesToMatchers =
612- SrcEntriesIt->getValue ();
613- // We also use presumed locations here to improve reproducibility for
614- // preprocessed inputs.
615- if (PresumedLoc PLoc = SM.getPresumedLoc (DiagLoc); PLoc.isValid ())
616- return globsMatches (
617- CategoriesToMatchers,
618- llvm::sys::path::remove_leading_dotslash (PLoc.getFilename ()));
619- return false ;
620- }
621594
622- bool WarningsSpecialCaseList::globsMatches (
623- const llvm::StringMap<Matcher> &CategoriesToMatchers,
624- StringRef FilePath) const {
625- StringRef LongestMatch;
626- bool LongestIsPositive = false ;
627- for (const auto &Entry : CategoriesToMatchers) {
628- StringRef Category = Entry.getKey ();
629- const llvm::SpecialCaseList::Matcher &Matcher = Entry.getValue ();
630- bool IsPositive = Category != " emit" ;
631- for (const auto &Glob : Matcher.Globs ) {
632- if (Glob->Name .size () < LongestMatch.size ())
633- continue ;
634- if (!Glob->Pattern .match (FilePath))
635- continue ;
636- LongestMatch = Glob->Name ;
637- LongestIsPositive = IsPositive;
638- }
639- }
640- return LongestIsPositive;
595+ unsigned EmitLineNo = llvm::SpecialCaseList::inSectionBlame (
596+ DiagSection->Entries , " src" , F, " emit" );
597+ if (!EmitLineNo)
598+ return true ;
599+
600+ return SuppressLineNo > EmitLineNo;
641601}
642602
643603bool DiagnosticsEngine::isSuppressedViaMapping (diag::kind DiagId,
0 commit comments