[clang] [LifetimeSafety] Handle escape through assignment to global storage (PR #181646)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 16 05:54:55 PST 2026


================
@@ -354,6 +368,13 @@ void FactsGenerator::handleAssignment(const Expr *LHSExpr,
   // assigned.
   RHSList = getRValueOrigins(RHSExpr, RHSList);
 
+  if (GlobalLHS) {
+    for (OriginList *L = RHSList; L != nullptr; L = L->peelOuterOrigin()) {
+      EscapesInCurrentBlock.push_back(FactMgr.createFact<GlobalEscapeFact>(
+            L->getOuterOriginID(), GlobalLHS));
+    }
+  };
----------------
usx95 wrote:

This looks quite strict. You are essentially disallowing any assignment to a global pointer. What we would ideally want is ensure at function exit, no global dangles. This is similar to how we generate escape facts for field decls in the exit block only.

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


More information about the cfe-commits mailing list