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

Yitzhak Mandelbaum via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Dec 15 06:42:49 PST 2025


================
@@ -102,6 +102,11 @@ class FactsGenerator : public ConstStmtVisitor<FactsGenerator> {
   // corresponding to the left-hand side is updated to be a "write", thereby
   // exempting it from the check.
   llvm::DenseMap<const DeclRefExpr *, UseFact *> UseFacts;
+
+  // Tracks declarations that have been moved via std::move. This is used to
+  // prevent false positives when the original owner is destroyed after the
+  // value has been moved. This tracking is flow-insensitive.
----------------
ymand wrote:

Consider moving the comments on lines 195-201 here, or at least mentioning them. But, that's a matter of taste :)

Also, whether in comments or test maybe highlight some example impacts? e.g. modifying your test below:

```
{
  MyObj a;
  v = a;
  b = std::move(a);

  refresh(a); // For types which can take on valid state after move.
  v = a;
}
```

Or, a branch?
```
{
  MyObj a;
  v = a;
  if (c) {
    b = std::move(a);
  }
}
```



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


More information about the llvm-branch-commits mailing list