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

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 7 18:17:03 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;
----------------
ChuanqiXu9 wrote:

The hardcoded name are not good. What's wrong with it? And if necessary, we'd better to check it with the built `CoroutineBodyStmt::getReturnStmt` (and maybe `CoroutineBodyStmt::getReturnStmtOnAllocFailure`?) If that is not built this time, can we perform that in `Sema::CheckCompletedCoroutineBody`? Maybe that will require a little bit refactor work, but I guess it may be worthy.

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


More information about the cfe-commits mailing list