Author: Timm Baeder Date: 2025-06-02T10:11:27+02:00 New Revision: f3f07a3f785d60a3afdc230641b91f044e4b2b99
URL: https://github.com/llvm/llvm-project/commit/f3f07a3f785d60a3afdc230641b91f044e4b2b99 DIFF: https://github.com/llvm/llvm-project/commit/f3f07a3f785d60a3afdc230641b91f044e4b2b99.diff LOG: [clang][Basic] Optimize getDiagnosticSeverity() (#141950) Try not to call getDiagInfo() as often and only do it if we really have to. Added: Modified: clang/lib/Basic/DiagnosticIDs.cpp Removed: ################################################################################ diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp index 6fa4066d95f8a..3e90b2d804773 100644 --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/lib/Basic/DiagnosticIDs.cpp @@ -542,26 +542,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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits