This is an archive of the discontinued LLVM Phabricator instance.

Fix codegen for coroutine with function-try-block
ClosedPublic

Authored by MatzeB on Mar 23 2023, 2:04 PM.

Details

Summary

This fixes an assertion error when writing a coroutine with a function-try-block. In this case the function body is not a CompoundStmt so the code constructing an artificial CXXTryStmt must also construct a CompoundStmt for it.

While on it adjust the CXXStmt::Create function to only accept CompoundStmt*.

Diff Detail

Event Timeline

MatzeB created this revision.Mar 23 2023, 2:04 PM
Herald added a project: Restricted Project. · View Herald Transcript
MatzeB requested review of this revision.Mar 23 2023, 2:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2023, 2:04 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
bruno accepted this revision.Mar 23 2023, 4:46 PM

LGTM! @ChuanqiXu wdyt?

clang/test/CodeGenCoroutines/coro-function-try-block.cpp
2

Space after -triple=x86_64

This revision is now accepted and ready to land.Mar 23 2023, 4:46 PM
MatzeB added inline comments.Mar 23 2023, 4:54 PM
clang/test/CodeGenCoroutines/coro-function-try-block.cpp
2

it is -triple=x86_64-- (lazy mans way of writing -triple=x86_64-unknown-unknown)

ChuanqiXu requested changes to this revision.Mar 23 2023, 7:38 PM

Thanks for finding this! We didn't notice this before.

clang/lib/CodeGen/CGCoroutine.cpp
736–738

Can we try to move the logic to CoroutineStmtBuilder? That makes me feel better. And it will be helpful to add a comment to tell that we're handling the case the function body is function-try-block.

738

It reads better to specify the potential type for Body.

clang/test/CodeGenCoroutines/coro-function-try-block.cpp
22–24

I expect to see the nested try statements in the case.

This revision now requires changes to proceed.Mar 23 2023, 7:38 PM
MatzeB updated this revision to Diff 508792.Mar 27 2023, 2:08 PM
MatzeB marked an inline comment as done.
ChuanqiXu added inline comments.Mar 27 2023, 11:38 PM
clang/lib/CodeGen/CGCoroutine.cpp
736–738

It looks like you didn't address the comments. Would you like to address it? I don't mind to address it later myself.

MatzeB updated this revision to Diff 509173.Mar 28 2023, 4:45 PM
MatzeB added inline comments.
clang/lib/CodeGen/CGCoroutine.cpp
736–738

I'll add a detailed comment. But would you be fine leaving the statements here as-is? The logic only makes sense in the context of using the Body to create a CXXTryStmt below (it's really an effect of CXXTryStmt only accepting CompountStmt operands).

736–738

Did you mean to create a new function named CoroutineStmtBuilder like I did now?

738

I will mention a single-statement body as an example in the comment now. Putting an assert here feels unnecessary and may be in the way if in the future we ever allow other types of single-statement function bodies.

clang/test/CodeGenCoroutines/coro-function-try-block.cpp
22–24

This was mostly meant as a test for "does not crash the compiler", so it is just checking some parts of the output without caring too much what they are specifically.

I cannot test for nested try statements, because in llvm-ir those are already lowered to unwind tables and landing pad blocks, but there's neither a "try" statement nor an immediate nesting I could test for.

ChuanqiXu accepted this revision.Mar 28 2023, 6:43 PM

Since the patch itself is good and not large. Let me handle the trivial refactoring later.

clang/lib/CodeGen/CGCoroutine.cpp
736–738

Did you mean to create a new function named CoroutineStmtBuilder like I did now?

No, I mean we should construct this in Sema.

Putting an assert here feels unnecessary and may be in the way if in the future we ever allow other types of single-statement function bodies.

Personally I prefer the more precise style.

This revision is now accepted and ready to land.Mar 28 2023, 6:43 PM
MatzeB added inline comments.Mar 30 2023, 11:08 AM
clang/lib/CodeGen/CGCoroutine.cpp
736–738

No, I mean we should construct this in Sema.

I'll land the patch as-is then and leave the refactoring to you if necessary.

This revision was landed with ongoing or failed builds.Mar 30 2023, 11:18 AM
This revision was automatically updated to reflect the committed changes.