Skip to content

[clang][Basic] Optimize getDiagnosticSeverity() #141950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions clang/lib/Basic/DiagnosticIDs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,26 +543,32 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
return Result;

const auto &SM = Diag.getSourceManager();

bool ShowInSystemHeader =
IsCustomDiag
? CustomDiagInfo->getDescription(DiagID).ShouldShowInSystemHeader()
: !GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;

// If we are in a system header, we ignore it. We look at the diagnostic class
// because we also want to ignore extensions and warnings in -Werror and
// -pedantic-errors modes, which *map* warnings/extensions to errors.
if (State->SuppressSystemWarnings && !ShowInSystemHeader && Loc.isValid() &&
SM.isInSystemHeader(SM.getExpansionLoc(Loc)))
return diag::Severity::Ignored;

if (State->SuppressSystemWarnings && Loc.isValid() &&
SM.isInSystemHeader(SM.getExpansionLoc(Loc))) {
bool ShowInSystemHeader = true;
if (IsCustomDiag)
ShowInSystemHeader =
CustomDiagInfo->getDescription(DiagID).ShouldShowInSystemHeader();
else if (const StaticDiagInfoRec *Rec = GetDiagInfo(DiagID))
ShowInSystemHeader = Rec->WarnShowInSystemHeader;

if (!ShowInSystemHeader)
return diag::Severity::Ignored;
}
// We also ignore warnings due to system macros
bool ShowInSystemMacro =
!GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemMacro;
if (State->SuppressSystemWarnings && !ShowInSystemMacro && Loc.isValid() &&
SM.isInSystemMacro(Loc))
return diag::Severity::Ignored;
if (State->SuppressSystemWarnings && Loc.isValid() &&
SM.isInSystemMacro(Loc)) {

bool ShowInSystemMacro = true;
if (const StaticDiagInfoRec *Rec = GetDiagInfo(DiagID))
ShowInSystemMacro = Rec->WarnShowInSystemMacro;

if (!ShowInSystemMacro)
return diag::Severity::Ignored;
}
// Clang-diagnostics pragmas always take precedence over suppression mapping.
if (!Mapping.isPragma() && Diag.isSuppressedViaMapping(DiagID, Loc))
return diag::Severity::Ignored;
Expand Down
Loading