================
@@ -556,6 +562,7 @@ VarDecl *Sema::buildCoroutinePromise(SourceLocation Loc) {
         VD->setInit(MaybeCreateExprWithCleanups(Result.get()));
         VD->setInitStyle(VarDecl::CallInit);
         CheckCompleteVariableDeclaration(VD);
+        markCoroutineParametersReferenced(*FD);
----------------
Lane0218 wrote:

Thanks for pointing this out.

`buildCoroutinePromise` passes the coroutine parameter copies (`q_i`) to the 
promise constructor. The references created for these arguments therefore mark 
the parameter copies in the coroutine frame, while `-Wunused-parameter` checks 
the original function parameters (`p_i`).

We only know that these copies are part of a valid promise-constructor call 
after `InitSeq.Perform` succeeds. Therefore, at that point, we propagate the 
referenced state back to the original parameters with 
`markCoroutineParametersReferenced(*FD)`.

We considered changing the reference bookkeeping for these temporary 
parameter-copy expressions, or changing the general `BuildDeclRefExpr` 
behavior. However, that would affect broader semantic analysis behavior and 
unnecessarily expand the scope of this PR. Keeping the adjustment at this 
coroutine-specific call site is more localized and avoids changing the existing 
reference-tracking contract.

I also added a comment at the call site to make this mapping explicit.

https://github.com/llvm/llvm-project/pull/217518
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to