[clang] 897f3dd - [Sema] Move Diags.isIgnored() checks off hot paths, it's not free. NFC

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 7 07:18:44 PDT 2022


Author: Sam McCall
Date: 2022-09-07T16:18:31+02:00
New Revision: 897f3ddc6154fee9bc072f800ceab8202b236b0a

URL: https://github.com/llvm/llvm-project/commit/897f3ddc6154fee9bc072f800ceab8202b236b0a
DIFF: https://github.com/llvm/llvm-project/commit/897f3ddc6154fee9bc072f800ceab8202b236b0a.diff

LOG: [Sema] Move Diags.isIgnored() checks off hot paths, it's not free. NFC

This speeds up clangd's buildAST() (i.e. parsing with a preamble) by 5% on
clangd/AST.cpp, by avoiding filling up the diagnostic state map with entries for
all the files where templates are being instantiated from.

(I would assume it has a similar effect on PCH and modules compiles).

This approach is obviously pretty fragile, and we should find ways to make
isIgnored() cheaper instead. But these changes in particular don't seem to make
the code worse in any case.

Differential Revision: https://reviews.llvm.org/D129683

Added: 
    

Modified: 
    clang/lib/Sema/Sema.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 5215b60defe8a..7ccf6330b49b8 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -575,10 +575,7 @@ void Sema::diagnoseNullableToNonnullConversion(QualType DstType,
   Diag(Loc, diag::warn_nullability_lost) << SrcType << DstType;
 }
 
-void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
-  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
-                      E->getBeginLoc()))
-    return;
+void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) {
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
     return;
@@ -588,6 +585,10 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
   if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
     return;
 
+  if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
+                      E->getBeginLoc()))
+    return;
+
   // Don't diagnose the conversion from a 0 literal to a null pointer argument
   // in a synthesized call to operator<=>.
   if (!CodeSynthesisContexts.empty() &&


        


More information about the cfe-commits mailing list