This is an archive of the discontinued LLVM Phabricator instance.

[Clang][SemaCXX][Coroutines] Fix misleading diagnostics with -Wunsequenced
ClosedPublic

Authored by bruno on Jan 18 2023, 7:48 PM.

Details

Summary

D115187 exposed CoroutineSuspendExpr's operand, which makes some nodes to show up twice during the traversal, confusing the check for unsequenced operations. Skip the operand since it's already handled as part of the common expression and get rid of the misleading warnings.

https://github.com/llvm/llvm-project/issues/56768

Diff Detail

Event Timeline

bruno created this revision.Jan 18 2023, 7:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2023, 7:48 PM
Herald added subscribers: hoy, modimo, wenlei. · View Herald Transcript
bruno requested review of this revision.Jan 18 2023, 7:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2023, 7:48 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Test failure is unrelated.

nridge added inline comments.Jan 21 2023, 12:44 AM
clang/lib/Sema/SemaChecking.cpp
15186

Out of curiosity, since getCommonExpr() is itself a subexpression of getReadyExpr(), getSuspendExpr(), and getResumeExpr() (which are also children of the CoroutineSuspendExpr), shouldn't getCommonExpr() be skipped for the same reason?

nridge added inline comments.Jan 21 2023, 12:48 AM
clang/test/SemaCXX/warn-unsequenced-coro.cpp
7

Consider including "Inputs/std-coroutine.h" instead, as in e.g. this test

ChuanqiXu accepted this revision.Jan 30 2023, 7:49 PM
ChuanqiXu added inline comments.
clang/lib/Sema/SemaChecking.cpp
15186

since getCommonExpr() is itself a subexpression of getReadyExpr(), getSuspendExpr(), and getResumeExpr()

This looks not true. For this example:

co_await foo();

foo() is the Operand. And the Common is auto __tmp__ = operator co_await(foo()). ReadyExpr should be __tmp__.await_ready();. SuspendExpr should be __tmp__.await_suspend(); and ResumeExpr should be __tmp__.await_resume();.

So the method here looks good to me.

This revision is now accepted and ready to land.Jan 30 2023, 7:49 PM
bruno updated this revision to Diff 494707.Feb 3 2023, 12:31 PM

Update patch to reuse std-coroutine.h and add a few more other bits there.

bruno added a comment.Feb 3 2023, 12:33 PM

Thanks for the review, will push once all tests pass!

clang/lib/Sema/SemaChecking.cpp
15186

foo() is the Operand. And the Common is auto __tmp__ = operator co_await(foo()). ReadyExpr should be __tmp__.await_ready();. SuspendExpr should be __tmp__.await_suspend(); and ResumeExpr should be __tmp__.await_resume();.

Exactly!

bruno updated this revision to Diff 494740.Feb 3 2023, 2:39 PM

Update checks that rely on coroutine_traits in std-coroutine.h

bruno added a comment.Feb 3 2023, 3:33 PM

Only test failing is ClangScanDeps/modules-full.cpp on Windoes, which is unrelated to this change.

This revision was landed with ongoing or failed builds.Feb 3 2023, 3:39 PM
This revision was automatically updated to reflect the committed changes.
nridge added inline comments.Feb 5 2023, 1:26 AM
clang/lib/Sema/SemaChecking.cpp
15186

Thank you for the explanation! I overlooked the fact that ReadyExpr/SuspendExpr/ResumeExpr use an OpaqueValueExpr wrapping CommonExpr rather than using CommonExpr directly.