[clang] [LifetimeSafety] Add origin tracking for lambda captures (PR #185216)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 11 03:38:59 PDT 2026
================
@@ -431,6 +445,26 @@ void FactsGenerator::VisitMaterializeTemporaryExpr(
}
}
+void FactsGenerator::VisitLambdaExpr(const LambdaExpr *LE) {
+ // The lambda gets a single merged origin that aggregates all captured
+ // pointer-like origins. Currently we only need to detect whether the lambda
+ // outlives any capture.
+ OriginList *LambdaList = getOriginsList(*LE);
+ if (!LambdaList)
+ return;
+ bool Kill = true;
+ for (const Expr *Init : LE->capture_inits()) {
+ if (!Init)
+ continue;
+ OriginList *InitList = getOriginsList(*Init);
+ if (!InitList)
+ continue;
+ CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
+ LambdaList->getOuterOriginID(), InitList->getOuterOriginID(), Kill));
----------------
Xazax-hun wrote:
Oh, I see!
Actually, I think it makes sense to only model outer origins for now as they are less likely to have false positives. We can add FIXMEs and potentially fix the rest once we have tree origins.
https://github.com/llvm/llvm-project/pull/185216
More information about the cfe-commits
mailing list