-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] Preserve coroutine parameter referenced state #70973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation Loc) { | |
if (PD->getType()->isDependentType()) | ||
continue; | ||
|
||
// Preserve the referenced state for unused parameter diagnostics. | ||
bool DeclReferenced = PD->isReferenced(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we will construct the parameter moves at the very beginning of the coroutine function, I am wondering if it is really possible that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Let's take a look at this very simple coroutine. Suppose
Sema is first asked to compile When the parser encounters What Suppose that our function has subsequent The aforementioned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. |
||
|
||
ExprResult PDRefExpr = | ||
BuildDeclRefExpr(PD, PD->getType().getNonReferenceType(), | ||
ExprValueKind::VK_LValue, Loc); // FIXME: scope? | ||
|
||
PD->setReferenced(DeclReferenced); | ||
bcardosolopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (PDRefExpr.isInvalid()) | ||
return false; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify -std=c++20 %s | ||
|
||
#include "Inputs/std-coroutine.h" | ||
|
||
struct awaitable { | ||
bool await_ready() noexcept; | ||
void await_resume() noexcept; | ||
void await_suspend(std::coroutine_handle<>) noexcept; | ||
}; | ||
|
||
struct task : awaitable { | ||
struct promise_type { | ||
task get_return_object() noexcept; | ||
awaitable initial_suspend() noexcept; | ||
awaitable final_suspend() noexcept; | ||
void unhandled_exception() noexcept; | ||
void return_void() noexcept; | ||
}; | ||
}; | ||
|
||
task foo(int a) { // expected-warning{{unused parameter 'a'}} | ||
co_return; | ||
} | ||
|
||
task bar(int a, int b) { // expected-warning{{unused parameter 'b'}} | ||
a = a + 1; | ||
co_return; | ||
} | ||
|
||
void create_closure() { | ||
auto closure = [](int c) -> task { // expected-warning{{unused parameter 'c'}} | ||
co_return; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readers can understand what is going on here. But they may be confused about the motivation. Let's add a comment to explain the reasons. I mean, something like, if we don't do so, we can't diagnose the unused parameter things.