================
@@ -556,6 +562,7 @@ VarDecl *Sema::buildCoroutinePromise(SourceLocation Loc) {
VD->setInit(MaybeCreateExprWithCleanups(Result.get()));
VD->setInitStyle(VarDecl::CallInit);
CheckCompleteVariableDeclaration(VD);
+ markCoroutineParametersReferenced(*FD);
----------------
Lane0218 wrote:
Sorry, my previous explanation was too abstract, let me clarify it.
Before adding this line, consider:
```cpp
task promise_constructor_uses_parameter(promise_arg a) {
co_return;
}
```
where `promise_type` has a viable `promise_type(promise_arg)` constructor.
Clang creates an implicit coroutine-frame copy of `a` without marking the
original `ParmVarDecl` as referenced. The promise constructor then uses that
implicit copy rather than the original declaration. As a result, the original
`a` remains unreferenced, and Clang incorrectly emits:
```text
warning: unused parameter 'a'
```
After adding this line, once `InitSeq.Perform` succeeds, we know that the
coroutine parameter copies are actually passed to the selected promise
constructor. We then mark the corresponding original parameters as referenced,
so the incorrect warning is no longer emitted.
If overload resolution falls back to the default constructor, this line is not
reached, so a genuinely unused parameter is still diagnosed.
We could instead change the general bookkeeping to propagate references from
implicit coroutine parameter copies back to the original parameters. However,
that would unnecessarily broaden the scope of this PR, so we chose the current
localized fix.
https://github.com/llvm/llvm-project/pull/217518
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits