================
@@ -467,6 +467,41 @@ struct TransferFunctions : public 
StmtVisitor<TransferFunctions> {
               AllValuesAreNoReturn = false;
     }
   }
+
+  void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *CE) {
+    if (CE->getOperator() == OO_Call && CE->getNumArgs() > 0) {
+      Expr *Obj = CE->getArg(0)->IgnoreParenCasts();
+      if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Obj))
+        Obj = MTE->getSubExpr();
+      if (auto *DRE = dyn_cast<DeclRefExpr>(Obj)) {
+        auto *D = dyn_cast<VarDecl>(DRE->getDecl());
+        if (D->hasInit())
+          Obj = D->getInit();
+      }
+      Visit(Obj);
+    }
+  }
+
+  void VisitLambdaExpr(LambdaExpr *LE) {
+    for (const LambdaCapture &Capture : LE->captures())
+      if (Capture.capturesVariable())
+        if (const VarDecl *VD = dyn_cast<VarDecl>(Capture.getCapturedVar()))
+          if (VD == Var)
+            if (Capture.getCaptureKind() == LCK_ByRef)
+              AllValuesAreNoReturn = false;
+  }
+
+  void VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *MTE) {
+    Visit(MTE->getSubExpr());
+  }
+
+  void VisitExprWithCleanups(FullExpr *FE) {
+    Visit(FE->getSubExpr());
+  }
+
+  void VisitCXXConstructExpr(CXXConstructExpr *CE) {
+    Visit(CE->getArg(0));
----------------
spavloff wrote:

It is more about the way LambdaExpr can be reached from variable initializer. 
For example, the code:
```
auto LF = [&func_ptr]() { func_ptr = ordinary; };
```
produces AST like:
```
DeclStmt 0x129e8159a10 <line:10:3, col:72>
`-VarDecl 0x129e812a478 <col:3, col:71> col:8 used LF '(lambda at 
zz-01.cpp:10:13)' cinit
  `-ExprWithCleanups 0x129e81599f8 <col:13, col:71> '(lambda at 
zz-01.cpp:10:13)'
    `-CXXConstructExpr 0x129e81599c8 <col:13, col:71> '(lambda at 
zz-01.cpp:10:13)' 'void ((lambda at zz-01.cpp:10:13) &&) noexcept' elidable
      `-MaterializeTemporaryExpr 0x129e8159728 <col:13, col:71> '(lambda at 
zz-01.cpp:10:13)' xvalue
        `-LambdaExpr 0x129e812aa78 <col:13, col:71> '(lambda at 
zz-01.cpp:10:13)'
```
These 'Visit*' methods are introduced to support this kind of lambda usage.


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

Reply via email to