[clang] [LifetimeSafety] Catch intra-method lifetime_capture_by(this) dangles (PR #204630)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 2 03:50:29 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:
Ohhh.... Thank you, the naming makes sense now!
https://github.com/llvm/llvm-project/pull/204630
More information about the cfe-commits
mailing list