https://github.com/nico updated https://github.com/llvm/llvm-project/pull/229158

>From e8890882d073b7a4b325accdfc8efeea257d0bc0 Mon Sep 17 00:00:00 2001
From: Nico Weber <[email protected]>
Date: Sun, 20 Sep 2026 10:50:38 -0400
Subject: [PATCH] [clang/wsm] Check for suppression section before computing
 presumed loc

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.
---
 clang/lib/Basic/Diagnostic.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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