[clang] [LifetimeSafety] Catch intra-method lifetime_capture_by(this) dangles (PR #204630)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 1 23:23:30 PDT 2026
================
@@ -858,6 +858,13 @@ void FactsGenerator::handleExitBlock() {
FactMgr.createFact<GlobalEscapeFact>(O.ID, VD));
}
}
+
+ // A borrow captured via [[clang::lifetime_capture_by(this)]] flows into the
+ // never-expiring `this` origin, so it is not otherwise live at the captured
+ // local's expiry. Keep `this` live at exit so the dangle is caught.
+ if (auto ThisOrigins = FactMgr.getOriginMgr().getThisOrigins())
+ EscapesInCurrentBlock.push_back(FactMgr.createFact<ThisEscapeFact>(
+ (*ThisOrigins)->getOuterOriginID(), AC.getDecl()->getEndLoc()));
----------------
NeKon69 wrote:
Can I ask more of a general naming convention question?
As per your comment above, this fact is here only to make sure `this` origin stays live, then why is the fact named `ThisEscapeFact`? It's not like we 100% know that something escapes to `this`, we just make the origin there live, though maybe I am missing something? (the same thing can be said about `GlobalEscapeFact` and `FieldEscapeFact`, since I feel like they are much different from `ReturnEscapeFact` where we actually prove that the origin escapes)
https://github.com/llvm/llvm-project/pull/204630
More information about the cfe-commits
mailing list