[clang] f9d757d - [analyzer] Format the block entrance crash trace lazily (#244841)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 01:14:58 PST 2026


Author: Gábor Horváth
Date: 2026-11-23T09:14:53Z
New Revision: f9d757d2b7a2b8e4378cb03508a410a2001d822a

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

LOG: [analyzer] Format the block entrance crash trace lazily (#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

Co-authored-by: Gabor Horvath <gaborh at apple.com>

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Removed: 
    


################################################################################
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);
 }
 


        


More information about the cfe-commits mailing list