This is an archive of the discontinued LLVM Phabricator instance.

[Coroutines] Implement fix for cwg2563 issue and enable RVO under certain conditions
ClosedPublic

Authored by bruno on Mar 8 2023, 7:15 PM.

Details

Summary
  • The cwg2563 issue is fixed by delaying GRO initialization only when the types mismatch between GRO and function return.
  • When the types match, directly initialize, enabling RVO to kick in as introduced in https://reviews.llvm.org/D117087

Background:
https://github.com/llvm/llvm-project/issues/56532
https://cplusplus.github.io/CWG/issues/2563.html
https://github.com/cplusplus/papers/issues/1414

Depends on D145639

Diff Detail

Event Timeline

bruno created this revision.Mar 8 2023, 7:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2023, 7:15 PM
Herald added subscribers: hoy, modimo, wenlei. · View Herald Transcript
bruno requested review of this revision.Mar 8 2023, 7:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2023, 7:15 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
weiwang added a subscriber: weiwang.Mar 8 2023, 8:31 PM
ChuanqiXu added inline comments.Mar 9 2023, 1:48 AM
clang/lib/CodeGen/CGCoroutine.cpp
475

nit. Rewords it if you like.

483–499

I'll feel better if we can attach the conclusion and links from the wg21.

500–508

What's the case about returning void and the return_object type is different from the returning type?

clang/lib/Sema/SemaCoroutine.cpp
1733

Let's have some comments here.

clang/test/SemaCXX/coroutine-no-move-ctor.cpp
24–26

How about adding a failing case that the types are not matched?

bruno marked 3 inline comments as done.Mar 15 2023, 12:13 PM
bruno added inline comments.
clang/lib/CodeGen/CGCoroutine.cpp
483–499

I can add some of that but unfortunately we don't have the working yet, it still has a CWG round to go: https://github.com/cplusplus/papers/issues/1414

The best explanation for the problem is under Gor's writeup: https://github.com/GorNishanov/await/blob/master/2023_Issaquah/cwg2563-response.md, I instead added a comment based on it since we cannot guarantee this link will be there forever.

500–508

In that case we do DirectEmit since there's no reason to delay initialization, am I missing something?

clang/test/SemaCXX/coroutine-no-move-ctor.cpp
24–26

I'm having trouble crafting one. I extracted similar examples from other testcases and even though I can confirm they correctly apply delayed initialization, they don't require copies (usually directly call conversion operators or similar) and we don't trigger the reverse usecase, do you have one testcase in mind I could use?

bruno updated this revision to Diff 505588.Mar 15 2023, 12:13 PM
bruno marked 2 inline comments as done.

Update after reviewer comments

ChuanqiXu added inline comments.Mar 15 2023, 7:23 PM
clang/lib/CodeGen/CGCoroutine.cpp
500–508

I mean it looks invalid if the function returns void and the return_object_type returns a non-void type. So we can judge this by hasSameType() directly.

clang/test/SemaCXX/coroutine-no-move-ctor.cpp
24–26

Oh, I don't have an existing test. Although not the best, maybe you can try to emit the codes to LLVM IR and match that.

bruno updated this revision to Diff 507085.Mar 21 2023, 12:21 PM

Address last round of review

bruno marked 2 inline comments as done.Mar 21 2023, 12:21 PM
bruno updated this revision to Diff 507087.Mar 21 2023, 12:29 PM

Add release notes entry.

ChuanqiXu accepted this revision.Mar 21 2023, 7:21 PM

LGTM. Thanks.

clang/docs/ReleaseNotes.rst
222–223 ↗(On Diff #507087)

I feel it would slightly better to claim that the RVO is till performed if the return type matches with the type of get_return_object(). So that the users won't get worries.

clang/test/CodeGenCoroutines/coro-gro.cpp
107 ↗(On Diff #507087)

Add a newline.

This revision is now accepted and ready to land.Mar 21 2023, 7:21 PM
bruno updated this revision to Diff 507224.Mar 21 2023, 9:25 PM

Apply last round of reviews before landing

bruno marked 2 inline comments as done.Mar 21 2023, 9:25 PM
This revision was landed with ongoing or failed builds.Mar 21 2023, 9:43 PM
This revision was automatically updated to reflect the committed changes.