https://github.com/Xazax-hun created 
https://github.com/llvm/llvm-project/pull/244841

runCheckersForBlockEntrance created a PrettyStackTraceFormat on every block 
edge. It formats its message eagerly with two vsnprintf calls, and the message 
does not fit its inline buffer, so it also allocated each time.

Use a small PrettyStackTraceEntry subclass that keeps a reference to the 
BlockEntrance and formats the same text only when a crash trace is printed.

On some LLVM TUs (GVN, LiveVariables, RegionStore, SemaExpr) this reduces the 
instructions of the static analyzer by 0.6-1.0%. The cycles and peak memory 
changes are within noise. The diagnostics are unchanged.

Assisted-by: Claude Opus 5.5

From d5d2551105757fc0a7a77bb8ae4857ea2a4cb060 Mon Sep 17 00:00:00 2001
From: Gabor Horvath <[email protected]>
Date: Sat, 21 Nov 2026 02:01:25 +0000
Subject: [PATCH] [analyzer] Format the block entrance crash trace lazily

runCheckersForBlockEntrance created a PrettyStackTraceFormat on every
block edge. It formats its message eagerly with two vsnprintf calls, and
the message does not fit its inline buffer, so it also allocated each
time.

Use a small PrettyStackTraceEntry subclass that keeps a reference to the
BlockEntrance and formats the same text only when a crash trace is
printed.

On some LLVM TUs (GVN, LiveVariables, RegionStore, SemaExpr) this
reduces the instructions of the static analyzer by 0.6-1.0%. The cycles
and peak memory changes are within noise. The diagnostics are unchanged.

Assisted-by: Claude Opus 5.5
---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 21 ++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index e19be8c3a7b376..4293e175229634 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2515,13 +2515,26 @@ ExplodedNode *ExprEngine::processCFGBlockEntrance(const 
BlockEntrance &BE,
   return nullptr;
 }
 
+namespace {
+class PrettyStackTraceBlockEntrance : public llvm::PrettyStackTraceEntry {
+  const BlockEntrance &Entrance;
+
+public:
+  PrettyStackTraceBlockEntrance(const BlockEntrance &Entrance)
+      : Entrance(Entrance) {}
+
+  void print(raw_ostream &OS) const override {
+    OS << "Processing block entrance B"
+       << Entrance.getPreviousBlock()->getBlockID() << " -> B"
+       << Entrance.getBlock()->getBlockID() << "\n";
+  }
+};
+} // namespace
+
 void ExprEngine::runCheckersForBlockEntrance(const BlockEntrance &Entrance,
                                              ExplodedNode *Pred,
                                              ExplodedNodeSet &Dst) {
-  llvm::PrettyStackTraceFormat CrashInfo(
-      "Processing block entrance B%d -> B%d",
-      Entrance.getPreviousBlock()->getBlockID(),
-      Entrance.getBlock()->getBlockID());
+  PrettyStackTraceBlockEntrance CrashInfo(Entrance);
   getCheckerManager().runCheckersForBlockEntrance(Dst, Pred, Entrance, *this);
 }
 

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

Reply via email to