Author: Nico Weber
Date: 2026-10-06T11:49:06Z
New Revision: 037b7c162d6f08496e24673961e498c99f1c7e51

URL: 
https://github.com/llvm/llvm-project/commit/037b7c162d6f08496e24673961e498c99f1c7e51
DIFF: 
https://github.com/llvm/llvm-project/commit/037b7c162d6f08496e24673961e498c99f1c7e51.diff

LOG: [clang/wsm] Check for suppression section before computing presumed loc 
(#229158)

With --warning-suppression-mappings=, every
DiagnosticIDs::getDiagnosticSeverity() call for a diagnostic that isn't
ignored calls WarningsSpecialCaseList::isDiagSuppressed(), so it's
called fairly often.

It seems reasonable to assume that the warning suppression list has few
entries compared to all the diagnostics clang knows about. So checking
if a diag ID is in the list is a) fast and b) rejects most DiagIds.

So check if DiagId is in DiagToSection before calling getPresumedLoc, as
the latter is somewhat expensive.

For 60 random Chromium TUs (linux x64, -O2, with Chromium's suppression
mapping file) picked with probability proportional to their compile
time, sum over all TUs, mean of two runs:

    CPU time: 192.7 s => 191.4 s, -0.7% (runs differ by up to 0.7%)
    instructions: 2009.5e9 => 2001.6e9, -0.40% (runs differ by 0.05%)

No behavior change.

Added: 
    

Modified: 
    clang/lib/Basic/Diagnostic.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 8dd1eabedcaa5..251c8ba6e13db 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -591,12 +591,12 @@ void 
DiagnosticsEngine::setDiagSuppressionMapping(llvm::MemoryBuffer &Input) {
 bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind DiagId,
                                                SourceLocation DiagLoc,
                                                const SourceManager &SM) const {
-  PresumedLoc PLoc = SM.getPresumedLoc(DiagLoc);
-  if (!PLoc.isValid())
-    return false;
   const Section *DiagSection = DiagToSection.lookup(DiagId);
   if (!DiagSection)
     return false;
+  PresumedLoc PLoc = SM.getPresumedLoc(DiagLoc);
+  if (!PLoc.isValid())
+    return false;
 
   StringRef F = llvm::sys::path::remove_leading_dotslash(PLoc.getFilename());
 


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to