@@ -575,6 +575,12 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
575
575
DiagID != diag::fatal_too_many_errors && Diag.FatalsAsError )
576
576
Result = diag::Severity::Error;
577
577
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 ();
578
584
// Custom diagnostics always are emitted in system headers.
579
585
bool ShowInSystemHeader =
580
586
!GetDiagInfo (DiagID) || GetDiagInfo (DiagID)->WarnShowInSystemHeader ;
@@ -583,15 +589,14 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
583
589
// because we also want to ignore extensions and warnings in -Werror and
584
590
// -pedantic-errors modes, which *map* warnings/extensions to errors.
585
591
if (State->SuppressSystemWarnings && !ShowInSystemHeader && Loc.isValid () &&
586
- Diag.getSourceManager ().isInSystemHeader (
587
- Diag.getSourceManager ().getExpansionLoc (Loc)))
592
+ SM.isInSystemHeader (SM.getExpansionLoc (Loc)))
588
593
return diag::Severity::Ignored;
589
594
590
595
// We also ignore warnings due to system macros
591
596
bool ShowInSystemMacro =
592
597
!GetDiagInfo (DiagID) || GetDiagInfo (DiagID)->WarnShowInSystemMacro ;
593
598
if (State->SuppressSystemWarnings && !ShowInSystemMacro && Loc.isValid () &&
594
- Diag. getSourceManager () .isInSystemMacro (Loc))
599
+ SM .isInSystemMacro (Loc))
595
600
return diag::Severity::Ignored;
596
601
597
602
return Result;
0 commit comments