[clang] [LifetimeSafety] Add origin tracking for lambda captures (PR #185216)

Zhijie Wang via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 7 10:37:07 PST 2026


================
@@ -51,7 +51,19 @@ class MissingOriginCollector
 } // namespace
 
 bool hasOrigins(QualType QT) {
-  return QT->isPointerOrReferenceType() || isGslPointerType(QT);
+  if (QT->isPointerOrReferenceType() || isGslPointerType(QT))
+    return true;
+  const auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+    return false;
+  // TODO: Limit to lambdas for now. This will be extended to user-defined
+  // structs with pointer-like fields.
+  if (!RD->isLambda())
+    return false;
+  for (const auto *FD : RD->fields())
+    if (hasOrigins(FD->getType()))
----------------
aeft wrote:

recursive call.

test case: `capture_lambda`

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


More information about the cfe-commits mailing list