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

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 16 10:23:32 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))
----------------
Xazax-hun wrote:

On a second thought I think this is not that important for now. This starts to make a difference if/once we model other sources of invalidation that are not dtors. I think I am fine with this as is for now. 

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


More information about the cfe-commits mailing list