@@ -525,12 +525,6 @@ class WarningsSpecialCaseList : public llvm::SpecialCaseList {
525525 const SourceManager &SM) const ;
526526
527527private:
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) {
592586bool 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
634609bool DiagnosticsEngine::isSuppressedViaMapping (diag::kind DiagId,
0 commit comments