@@ -575,6 +575,12 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
575575 DiagID != diag::fatal_too_many_errors && Diag.FatalsAsError )
576576 Result = diag::Severity::Error;
577577
578+ // Rest of the mappings are only applicable for diagnostics associated with a
579+ // SourceLocation, bail out early for others.
580+ if (!Diag.hasSourceManager ())
581+ return Result;
582+
583+ const auto &SM = Diag.getSourceManager ();
578584 // Custom diagnostics always are emitted in system headers.
579585 bool ShowInSystemHeader =
580586 !GetDiagInfo (DiagID) || GetDiagInfo (DiagID)->WarnShowInSystemHeader ;
@@ -583,15 +589,14 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
583589 // because we also want to ignore extensions and warnings in -Werror and
584590 // -pedantic-errors modes, which *map* warnings/extensions to errors.
585591 if (State->SuppressSystemWarnings && !ShowInSystemHeader && Loc.isValid () &&
586- Diag.getSourceManager ().isInSystemHeader (
587- Diag.getSourceManager ().getExpansionLoc (Loc)))
592+ SM.isInSystemHeader (SM.getExpansionLoc (Loc)))
588593 return diag::Severity::Ignored;
589594
590595 // We also ignore warnings due to system macros
591596 bool ShowInSystemMacro =
592597 !GetDiagInfo (DiagID) || GetDiagInfo (DiagID)->WarnShowInSystemMacro ;
593598 if (State->SuppressSystemWarnings && !ShowInSystemMacro && Loc.isValid () &&
594- Diag. getSourceManager () .isInSystemMacro (Loc))
599+ SM .isInSystemMacro (Loc))
595600 return diag::Severity::Ignored;
596601
597602 return Result;
0 commit comments