[clang] [LifetimeSafety] Introduce a liveness-based lifetime policy (PR #159991)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 7 10:20:09 PDT 2025


================
@@ -1087,11 +1073,19 @@ class LoanPropagationAnalysis
   /// Merges two lattices by taking the union of loans for each origin.
   // TODO(opt): Keep the state small by removing origins which become dead.
   Lattice join(Lattice A, Lattice B) {
-    OriginLoanMap JoinedOrigins =
-        utils::join(A.Origins, B.Origins, OriginLoanMapFactory,
-                    [&](LoanSet S1, LoanSet S2) {
-                      return utils::join(S1, S2, LoanSetFactory);
-                    });
+    OriginLoanMap JoinedOrigins = utils::join(
+        A.Origins, B.Origins, OriginLoanMapFactory,
+        [&](const LoanSet *S1, const LoanSet *S2) {
+          assert((S1 || S2) && "unexpectedly merging 2 empty sets");
+          if (!S1)
+            return *S2;
+          if (!S2)
+            return *S1;
+          return utils::join(*S1, *S2, LoanSetFactory);
+        },
+        // Asymmetric join is a performance win. For origins present only on one
+        // branch, the loan set can be carried over as-is.
+        /*SymmetricJoin=*/false);
----------------
usx95 wrote:

Thanks. Done in this PR itself.

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


More information about the cfe-commits mailing list