@@ -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
@@ -584,43 +578,24 @@ void DiagnosticsEngine::setDiagSuppressionMapping(llvm::MemoryBuffer &Input) {
584578bool WarningsSpecialCaseList::isDiagSuppressed (diag::kind DiagId,
585579 SourceLocation DiagLoc,
586580 const SourceManager &SM) const {
581+ PresumedLoc PLoc = SM.getPresumedLoc (DiagLoc);
582+ if (!PLoc.isValid ())
583+ return false ;
587584 const Section *DiagSection = DiagToSection.lookup (DiagId);
588585 if (!DiagSection)
589586 return false ;
590- const SectionEntries &EntityTypeToCategories = DiagSection->Entries ;
591- auto SrcEntriesIt = EntityTypeToCategories.find (" src" );
592- if (SrcEntriesIt == EntityTypeToCategories.end ())
587+
588+ StringRef F = llvm::sys::path::remove_leading_dotslash (PLoc.getFilename ());
589+
590+ StringRef LongestSup = DiagSection->getLongestMatch (" src" , F, " " );
591+ if (LongestSup.empty ())
593592 return false ;
594- const llvm::StringMap<llvm::SpecialCaseList::Matcher> &CategoriesToMatchers =
595- SrcEntriesIt->getValue ();
596- // We also use presumed locations here to improve reproducibility for
597- // preprocessed inputs.
598- if (PresumedLoc PLoc = SM.getPresumedLoc (DiagLoc); PLoc.isValid ())
599- return globsMatches (
600- CategoriesToMatchers,
601- llvm::sys::path::remove_leading_dotslash (PLoc.getFilename ()));
602- return false ;
603- }
604593
605- bool WarningsSpecialCaseList::globsMatches (
606- const llvm::StringMap<Matcher> &CategoriesToMatchers,
607- StringRef FilePath) const {
608- StringRef LongestMatch;
609- bool LongestIsPositive = false ;
610- for (const auto &Entry : CategoriesToMatchers) {
611- StringRef Category = Entry.getKey ();
612- const llvm::SpecialCaseList::Matcher &Matcher = Entry.getValue ();
613- bool IsPositive = Category != " emit" ;
614- for (const auto &Glob : Matcher.Globs ) {
615- if (Glob->Name .size () < LongestMatch.size ())
616- continue ;
617- if (!Glob->Pattern .match (FilePath))
618- continue ;
619- LongestMatch = Glob->Name ;
620- LongestIsPositive = IsPositive;
621- }
622- }
623- return LongestIsPositive;
594+ StringRef LongestEmit = DiagSection->getLongestMatch (" src" , F, " emit" );
595+ if (LongestEmit.empty ())
596+ return true ;
597+
598+ return LongestSup.size () > LongestEmit.size ();
624599}
625600
626601bool DiagnosticsEngine::isSuppressedViaMapping (diag::kind DiagId,
0 commit comments