This is an archive of the discontinued LLVM Phabricator instance.

[coroutines] Remove assert on CoroutineParameterMoves in Sema::buildCoroutineParameterMoves
ClosedPublic

Authored by junparser on Oct 16 2019, 12:55 AM.

Details

Summary

The assertion of CoroutineParameterMoves happens when build coroutine function with arguments multiple time while fails to build promise type.

Fix: use return false instead.

Test Plan: check-clang

Diff Detail

Event Timeline

junparser created this revision.Oct 16 2019, 12:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 16 2019, 12:55 AM
rjmccall resigned from this revision.Oct 24 2019, 3:53 PM

Despite generally knowing about coroutines and generally knowing about Clang, I actually don't know the Clang coroutine code and can't review this properly.

Despite generally knowing about coroutines and generally knowing about Clang, I actually don't know the Clang coroutine code and can't review this properly.

thanks anyway~

modocache requested changes to this revision.Nov 21 2019, 12:28 PM

Sorry for the slow response here, @junparser!

The test case you came up with here is great! I can see the issue is that ScopeInfo->CoroutineParameterMoves are built up when Clang parses the first co_await a, but are not cleared when lookupPromiseType results in an error. As a result, when Clang hits the second co_await a, it's in a state that the current code didn't anticipate. Your test case does a great job demonstrating this. Your fix for the problem also looks good to me! My only suggestion is to make the test case just a little clearer, as I'll explain...

(Also, in the future could you please upload your patches with full context? You can read https://llvm.org/docs/Phabricator.html for more details. I think the section explaining the web interface might be relevant to you, where it suggests git show HEAD -U999999 > mypatch.patch. The reason I ask is because on Phabricator I can see what lines you're proposing should be added, but not the surrounding source lines, which made this more difficult to review.)

test/SemaCXX/coroutines.cpp
93 ↗(On Diff #225167)

This is a great test case, thanks for coming up with it! However, I think it could be a little clearer, though: right now the int a variable is shadowing the awaitable a that's declared further up in this file. At first, I wasn't sure whether the shadowing had something to do with the test, but in fact it doesn't. This test case demonstrates the issue but without the confusion, I think:

int no_promise_type_multiple_awaits(int) { // expected-error {{this function cannot be a coroutine: 'std::experimental::coroutine_traits<int, int>' has no member named 'promise_type'}}
  co_await a;
  co_await a;
}
This revision now requires changes to proceed.Nov 21 2019, 12:28 PM
junparser updated this revision to Diff 230581.Nov 21 2019, 7:29 PM

update as @modocache's suggestion

Sorry for the slow response here, @junparser!

The test case you came up with here is great! I can see the issue is that ScopeInfo->CoroutineParameterMoves are built up when Clang parses the first co_await a, but are not cleared when lookupPromiseType results in an error. As a result, when Clang hits the second co_await a, it's in a state that the current code didn't anticipate. Your test case does a great job demonstrating this. Your fix for the problem also looks good to me! My only suggestion is to make the test case just a little clearer, as I'll explain...

(Also, in the future could you please upload your patches with full context? You can read https://llvm.org/docs/Phabricator.html for more details. I think the section explaining the web interface might be relevant to you, where it suggests git show HEAD -U999999 > mypatch.patch. The reason I ask is because on Phabricator I can see what lines you're proposing should be added, but not the surrounding source lines, which made this more difficult to review.)

Thanks so much for reviewing the patch and giving the helpful advise.

modocache accepted this revision.Nov 21 2019, 7:37 PM

LGTM, thanks! Please let me know if you'd like me to commit this change.

This revision is now accepted and ready to land.Nov 21 2019, 7:37 PM

LGTM, thanks! Please let me know if you'd like me to commit this change.

commit it please, thanks!

This revision was automatically updated to reflect the committed changes.

Thanks again for the patch @junparser! And sorry the review took so long!