================
@@ -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));
----------------
usx95 wrote:

Ah. I missed this. We only propagate outer origins from source. This means we 
would not be able to catch

```cpp
string s = "42";
string_view p = s;
auto lambda = [&] { return p; };
s.push_back('c');  // invalidates p
lambda();  // should warn: use-after-invalidate
```

`lambda` would contain a loan to `p` and but not to `s`.

Please add a FIXME here to consider adding all loans once we move to more than 
one origins for lambdas. 

cc: @Xazax-hun 

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

Reply via email to