[llvm-branch-commits] [clang] [LifetimeSafety][NFC] Add field-labeled child edges to OriginNode and generalize subtree walks (PR #201510)

Gábor Horváth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jun 8 07:50:44 PDT 2026


================
@@ -127,21 +127,30 @@ class AnalysisImpl
   /// A read operation makes the origin live with definite confidence, as it
   /// dominates this program point. A write operation kills the liveness of
   /// the origin since it overwrites the value.
+  ///
+  /// Walks the full subtree so loans held by any descendant (pointee
+  /// chain or field child) become visible at the use site.
   Lattice transfer(Lattice In, const UseFact &UF) {
+    return transferUseSubtree(In, UF, UF.getUsedOrigins());
+  }
+
+  Lattice transferUseSubtree(Lattice In, const UseFact &UF,
+                             const OriginNode *Cur) {
+    if (!Cur)
+      return In;
+    OriginID OID = Cur->getOriginID();
     Lattice Out = In;
-    for (const OriginNode *Cur = UF.getUsedOrigins(); Cur;
-         Cur = Cur->getPointeeChild()) {
-      OriginID OID = Cur->getOriginID();
-      // Write kills liveness.
-      if (UF.isWritten()) {
-        Out = Lattice(Factory.remove(Out.LiveOrigins, OID));
-      } else {
-        // Read makes origin live with definite confidence (dominates this
-        // point).
-        Out = Lattice(Factory.add(Out.LiveOrigins, OID,
-                                  LivenessInfo(&UF, LivenessKind::Must)));
-      }
+    // Write kills liveness.
+    if (UF.isWritten()) {
+      Out = Lattice(Factory.remove(Out.LiveOrigins, OID));
+    } else {
+      // Read makes origin live with definite confidence (dominates this
+      // point).
+      Out = Lattice(Factory.add(Out.LiveOrigins, OID,
+                                LivenessInfo(&UF, LivenessKind::Must)));
     }
+    for (const OriginNode::Edge &E : Cur->children())
----------------
Xazax-hun wrote:

Same here, instead of a hand-written traversal, we should use the efficient `forEachOrigin` (I suggested to introduce above).

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


More information about the llvm-branch-commits mailing list