Author: Anonmiraj
Date: 2026-07-13T16:25:35+03:00
New Revision: 592953beff733a1e28f6c6e5e39f948fb035a329

URL: 
https://github.com/llvm/llvm-project/commit/592953beff733a1e28f6c6e5e39f948fb035a329
DIFF: 
https://github.com/llvm/llvm-project/commit/592953beff733a1e28f6c6e5e39f948fb035a329.diff

LOG: [clang][Diagnostics] Only record lexer check points when colors are 
enabled (#204926)

Only build lexer check points when colored diagnostics are enabled,
since that's the only case where they're ever used,
This should reduce the cost on larger builds.

| Commit | Basket Ir | Delta |
|---|---|---|
| 863b2c84 (Parent) | 30,240,576,150 | — |
| 718aac9f (Commit) | 30,336,607,185 | +0.318% |
| **+ this pr** | **30,279,772,621** | **+0.130%** |


**synthetic error file (12.3k lines, 300 errors):**

| Build | Error-TU Ir (colors on) | Δ vs commit |
|---|---|---|
| 718aac9f (Commit) | 1,386,488,658 | — |
| **+ this pr** | **1,387,140,588** | **+0.05%** |

Resolves #203764

---------

Co-authored-by: Timm Baeder <[email protected]>

Added: 
    

Modified: 
    clang/include/clang/Lex/Preprocessor.h
    clang/lib/Lex/Preprocessor.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 413e80e7645f9..1c917dcfe7b7e 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -383,6 +383,9 @@ class Preprocessor {
   llvm::DenseMap<FileID, SmallVector<const char *>> CheckPoints;
   unsigned CheckPointCounter = 0;
 
+  /// Whether to record lexer check points for diagnostic snippet highlighting.
+  bool RecordCheckPoints = false;
+
   /// Whether we're importing a standard C++20 named Modules.
   bool ImportingCXXNamedModules = false;
 

diff  --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 1625d5918e8f5..5ee53a93732bb 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -102,6 +102,10 @@ Preprocessor::Preprocessor(const PreprocessorOptions 
&PPOpts,
       CurSubmoduleState(&NullSubmoduleState) {
   OwnsHeaderSearch = OwnsHeaders;
 
+  // Only record check points if we might highlight diagnostic snippets.
+  RecordCheckPoints = getDiagnostics().getDiagnosticOptions().getShowColors() 
!=
+                      ShowColorsKind::Off;
+
   // Default to discarding comments.
   KeepComments = false;
   KeepMacroComments = false;
@@ -1014,7 +1018,8 @@ void Preprocessor::Lex(Token &Result) {
     }
   }
 
-  if (CurLexer && ++CheckPointCounter == CheckPointStepSize) {
+  if (RecordCheckPoints && CurLexer &&
+      ++CheckPointCounter == CheckPointStepSize) {
     CheckPoints[CurLexer->getFileID()].push_back(CurLexer->BufferPtr);
     CheckPointCounter = 0;
   }


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

Reply via email to