[clang] 2337990 - [clang][NFC] Bail out early when checking system-header/macro suppressions

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 1 02:17:36 PDT 2024


Author: Kadir Cetinkaya
Date: 2024-11-01T10:02:37+01:00
New Revision: 2337990cae89f32c9a58b63748bc837d9feb7d3f

URL: https://github.com/llvm/llvm-project/commit/2337990cae89f32c9a58b63748bc837d9feb7d3f
DIFF: https://github.com/llvm/llvm-project/commit/2337990cae89f32c9a58b63748bc837d9feb7d3f.diff

LOG: [clang][NFC] Bail out early when checking system-header/macro suppressions

Added: 
    

Modified: 
    clang/lib/Basic/DiagnosticIDs.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index d45bb0f392d457..fc8bd29faa080f 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -575,6 +575,12 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
       DiagID != diag::fatal_too_many_errors && Diag.FatalsAsError)
     Result = diag::Severity::Error;
 
+  // Rest of the mappings are only applicable for diagnostics associated with a
+  // SourceLocation, bail out early for others.
+  if (!Diag.hasSourceManager())
+    return Result;
+
+  const auto &SM = Diag.getSourceManager();
   // Custom diagnostics always are emitted in system headers.
   bool ShowInSystemHeader =
       !GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;
@@ -583,15 +589,14 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
   // 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() &&
-      Diag.getSourceManager().isInSystemHeader(
-          Diag.getSourceManager().getExpansionLoc(Loc)))
+      SM.isInSystemHeader(SM.getExpansionLoc(Loc)))
     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() &&
-      Diag.getSourceManager().isInSystemMacro(Loc))
+      SM.isInSystemMacro(Loc))
     return diag::Severity::Ignored;
 
   return Result;


        


More information about the cfe-commits mailing list