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

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 11 07:29:01 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;
----------------
usx95 wrote:

Promise type lookup would need to go through coroutine traits. We could lookup `coroutine_traits<R>::promise_type` but does not work with `coroutine_traits` specialized for non-empty parameter list.
The new approach implicitly adds `[[clang::coro_wrapper]]` and `[[clang::coro_disable_lifetimebound]]` to `get_return_type` found through a promise lookup.
WDYT ?

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


More information about the cfe-commits mailing list