[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 15 09:13:42 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;
+ // Coroutine lambda objects with empty capture list are not lifetimebound.
+ if (auto *LE = dyn_cast<LambdaExpr>(ObjectArg->IgnoreImplicit());
+ LE && LE->captures().empty())
+ CheckCoroObjArg = false;
----------------
ilya-biryukov wrote:
> I didn't get the logic here. Why it is not good to warn the undefined things?
Sorry, I wasn't clear here. I meant that if it is UB, we should warn for those cases too and remove this code path.
> I feel it is literally undefined. Since the spec doesn't say a lot about resumption/suspension about coroutines. Also the description of http://eel.is/c++draft/dcl.fct.def.coroutine#note-3 is vague too. It says it is likely to be an undefined behavior.
Yeah, this looks suspicious. At the same time, it's very similar to `delete this`, which (IIUC) is not UB as long as people are careful to not access `this` after doing it.
I have actually asked the CWG, but got no reply so far.
https://github.com/llvm/llvm-project/pull/77066
More information about the cfe-commits
mailing list