[clang] [LifetimeSafety] Add bailout for large CFGs (PR #170444)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 11 03:18:31 PST 2025


================
@@ -28,24 +28,46 @@
 #include "llvm/Support/TimeProfiler.h"
 #include <memory>
 
+#undef DEBUG_TYPE
+#define DEBUG_TYPE "lifetime-safety"
+
 namespace clang::lifetimes {
 namespace internal {
 
 LifetimeSafetyAnalysis::LifetimeSafetyAnalysis(AnalysisDeclContext &AC,
-                                               LifetimeSafetyReporter *Reporter)
-    : AC(AC), Reporter(Reporter) {}
+                                               LifetimeSafetyReporter *Reporter,
+                                               uint32_t CfgBlocknumThreshold)
+    : CfgBlocknumThreshold(CfgBlocknumThreshold), AC(AC), Reporter(Reporter) {
+  FactMgr.setBlockNumThreshold(CfgBlocknumThreshold);
+}
+
+bool LifetimeSafetyAnalysis::shouldBailOutCFGPreFactGeneration(const CFG& Cfg) const {
+  if ((CfgBlocknumThreshold > 0) &&
+      (Cfg.getNumBlockIDs() > CfgBlocknumThreshold)) {
+    LLVM_DEBUG(llvm::dbgs()
+               << "Aborting Lifetime Safety analysis for current CFG as it has "
+                  "blocks exceeding the thresold. Number of blocks: "
+               << Cfg.getNumBlockIDs() << "\n");
----------------
usx95 wrote:

Suggestion:  
`LifetimeSafety: Skipping function <FN_NAME> due to large CFG: <count> blocks (threshold: <threshold>)`

See `FactManager::dump()` for function name extraction.


https://github.com/llvm/llvm-project/pull/170444


More information about the cfe-commits mailing list