================
@@ -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()))
----------------
aeft wrote:

I tried several implementations: (1) Only `hasOrigins(FD->getType())` check for 
field (2) `isAccessedField(FD) && hasOrigins(FD->getType())` (3) 
`(FD->getAccess() == AS_public || isAccessedField(FD)) && 
hasOrigins(FD->getType())` (the current implementation)

(1) created origins for more records and it incured more regression (+0.18% -> 
+0.46%).
(2) produced False Positives. This is because it breaks the narrowing logic in 
`VisitMemberExpr`. I have a comment to explain this:
```cpp
    // A record can also be used as a whole (e.g. `s.inner`) while none of its
    // own fields (e.g. `s.inner.v`) are accessed. Narrowing that use still
    // needs the record to have origins (otherwise the use also keeps a sibling
    // like `s.v` live), so a public field with origins provides them even when
    // unaccessed.
```
(3) The current implementation. It fixed the FPs. But it seems still not ideal 
since it coupled the narrowing logic in a more general function (i.e., 
`hasOrigins`).

https://github.com/llvm/llvm-project/pull/195603
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to