[clang] [clang][Diagnostics] Only record lexer check points when colors are enabled (PR #204926)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 20 05:47:12 PDT 2026
https://github.com/AnonMiraj created https://github.com/llvm/llvm-project/pull/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
>From 6f15db3e1232d7f18f6732a1338960b3aa22b49e Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Sat, 20 Jun 2026 14:41:32 +0300
Subject: [PATCH] [clang][Diagnostics] Only record lexer check points when
colors are enabled
---
clang/include/clang/Lex/Preprocessor.h | 3 +++
clang/lib/Lex/Preprocessor.cpp | 6 +++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 8b684e85eb1c1..9f592892f9218 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -381,6 +381,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 1e21b4a94cea3..f58d8589c1afd 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -101,6 +101,9 @@ Preprocessor::Preprocessor(const PreprocessorOptions &PPOpts,
CurSubmoduleState(&NullSubmoduleState) {
OwnsHeaderSearch = OwnsHeaders;
+ // Only record check points if we might highlight diagnostic snippets.
+ RecordCheckPoints = getDiagnostics().getDiagnosticOptions().ShowColors;
+
// Default to discarding comments.
KeepComments = false;
KeepMacroComments = false;
@@ -1011,7 +1014,8 @@ void Preprocessor::Lex(Token &Result) {
}
}
- if (CurLexer && ++CheckPointCounter == CheckPointStepSize) {
+ if (RecordCheckPoints && CurLexer &&
+ ++CheckPointCounter == CheckPointStepSize) {
CheckPoints[CurLexer->getFileID()].push_back(CurLexer->BufferPtr);
CheckPointCounter = 0;
}
More information about the cfe-commits
mailing list