[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 04:42:04 PST 2024


================
@@ -7575,15 +7577,27 @@ static void visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
     Path.pop_back();
   };
 
-  if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
-    VisitLifetimeBoundArg(Callee, ObjectArg);
-
   bool CheckCoroCall = false;
   if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
     CheckCoroCall = RD->hasAttr<CoroLifetimeBoundAttr>() &&
                     RD->hasAttr<CoroReturnTypeAttr>() &&
                     !Callee->hasAttr<CoroDisableLifetimeBoundAttr>();
   }
+
+  if (ObjectArg) {
+    bool CheckCoroObjArg = CheckCoroCall;
+    // Ignore `__promise.get_return_object()` as it is not lifetimebound.
+    if (CheckCoroObjArg && Callee->getDeclName().isIdentifier() &&
+        Callee->getName() == "get_return_object")
+      CheckCoroObjArg = false;
----------------
ilya-biryukov wrote:

There is also a similar use of the name in `CheckCoroutineWrapper`, I suggest to unify the check for matching this particular function across the two call sites.

The motivation to disable this for `get_return_object` is clear: it's often used as an implementation detail, so warning there creates noise. There could be better ways to do it, though.

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


More information about the cfe-commits mailing list