diff options
Diffstat (limited to 'clang/lib/Basic/Diagnostic.cpp')
| -rw-r--r-- | clang/lib/Basic/Diagnostic.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 2d0e35811636..ae71758bc81e 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -500,7 +500,8 @@ public: // the last section take precedence in such cases. void processSections(DiagnosticsEngine &Diags); - bool isDiagSuppressed(diag::kind DiagId, StringRef FilePath) const; + bool isDiagSuppressed(diag::kind DiagId, SourceLocation DiagLoc, + const SourceManager &SM) const; private: // Find the longest glob pattern that matches FilePath amongst @@ -573,13 +574,14 @@ void DiagnosticsEngine::setDiagSuppressionMapping(llvm::MemoryBuffer &Input) { WarningSuppressionList->processSections(*this); DiagSuppressionMapping = [WarningSuppressionList(std::move(WarningSuppressionList))]( - diag::kind DiagId, StringRef Path) { - return WarningSuppressionList->isDiagSuppressed(DiagId, Path); + diag::kind DiagId, SourceLocation DiagLoc, const SourceManager &SM) { + return WarningSuppressionList->isDiagSuppressed(DiagId, DiagLoc, SM); }; } bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind DiagId, - StringRef FilePath) const { + SourceLocation DiagLoc, + const SourceManager &SM) const { const Section *DiagSection = DiagToSection.lookup(DiagId); if (!DiagSection) return false; @@ -589,7 +591,13 @@ bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind DiagId, return false; const llvm::StringMap<llvm::SpecialCaseList::Matcher> &CategoriesToMatchers = SrcEntriesIt->getValue(); - return globsMatches(CategoriesToMatchers, FilePath); + // 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( @@ -614,8 +622,10 @@ bool WarningsSpecialCaseList::globsMatches( } bool DiagnosticsEngine::isSuppressedViaMapping(diag::kind DiagId, - StringRef FilePath) const { - return DiagSuppressionMapping && DiagSuppressionMapping(DiagId, FilePath); + SourceLocation DiagLoc) const { + if (!hasSourceManager() || !DiagSuppressionMapping) + return false; + return DiagSuppressionMapping(DiagId, DiagLoc, getSourceManager()); } void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) { |
