[clang] [LifetimeSafety] Track moved declarations to prevent false positives (PR #170007)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 16 10:07:22 PST 2026


================
@@ -341,6 +359,11 @@ void FactsGenerator::handleLifetimeEnds(const CFGLifetimeEnds &LifetimeEnds) {
   // Iterate through all loans to see if any expire.
   for (const auto &Loan : FactMgr.getLoanMgr().getLoans()) {
     const AccessPath &LoanPath = Loan.Path;
+    // Skip loans for declarations that have been moved. When a value is moved,
+    // the original owner no longer has ownership and its destruction should not
+    // cause the loan to expire, preventing false positives.
+    if (MovedDecls.contains(LoanPath.D))
----------------
usx95 wrote:

I am not totally convinced of the upside of such a heuristic. Doing this would require another dataflow/reachability problem and I don't think that is worth the complexity.
Note that this only switches the analysis off for only the moved decls but not for all the rest of the functions. I would prefer having the heuristics simpler given that this is a major limitation of our lifetime model.

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


More information about the cfe-commits mailing list