[llvm-branch-commits] [clang] [LifetimeSafety] Track per-field origins for record types (PR #195603)

Gábor Horváth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jun 1 01:25:42 PDT 2026


================
@@ -112,16 +122,29 @@ bool OriginManager::hasOrigins(QualType QT) const {
   // stored lambda's origins.
   if (isStdCallableWrapperType(RD))
     return true;
-  // TODO: Limit to lambdas for now. This will be extended to user-defined
-  // structs with pointer-like fields.
-  if (!RD->isLambda())
+  // A lambda has origins when any capture has a tracked type; the lambda
+  // itself is tracked as a single origin.
+  if (RD->isLambda()) {
+    for (const auto *FD : RD->fields())
+      if (hasOrigins(FD->getType()))
+        return true;
+    return false;
+  }
+  // TODO: Unions are not tracked.
+  if (RD->isUnion())
     return false;
   for (const auto *FD : RD->fields())
-    if (hasOrigins(FD->getType()))
+    if (FD->getAccess() == AS_public && hasOrigins(FD->getType()))
       return true;
   return false;
 }
 
+bool OriginManager::isTrackedField(const CXXRecordDecl *RD,
+                                   const FieldDecl *FD) const {
+  return FD->getAccess() == AS_public && hasOrigins(FD->getType()) &&
----------------
Xazax-hun wrote:

In case we are analyzing a method of a class `C`, we can access the private fields of this class and the protected fields of the base classes. So I think we might want to broaden this depending on what we are analyzing. 

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


More information about the llvm-branch-commits mailing list