This is an archive of the discontinued LLVM Phabricator instance.

[clang][PR55406] co_return CFG fix
AbandonedPublic

Authored by urnathan on May 13 2022, 6:05 AM.

Details

Summary

PR55406 is an issue where an incorrect CFG is constructed containing
duplicate references to subtrees. That's due to co_return keeping the
original expression and the promise call. It needs the former for (a)
instantiation and (b) co_returns with void expressions.

Add a flag to CoreturnStmt indicating whether the operand member is
needed for the void-return case. This simplifies code-generation but
also allows the CFG generator to look at that flag to determine
whether it needs to emit the operand in addition to the promise call.

Diff Detail

Event Timeline

urnathan created this revision.May 13 2022, 6:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 6:05 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
urnathan requested review of this revision.May 13 2022, 6:05 AM

This one looks like a workaround for me. It tries to skip a CFG check for the operand of return_value to avoid a potential crash. The true solution should be to construct the CFG correctly.

Please clarify. This is fixing a bug where the CFG was being incorrectly constructed.

Please clarify. This is fixing a bug where the CFG was being incorrectly constructed.

I thought we could avoid the crash by a simple fix (see the comment) in CFG.cpp instead of touching coroutine things. And today I've tried we could pass all the tests by checking the promise call only. But I just realize that we might miss a check for the expressions in return_void but it is not covered by tests. I think it makes sense to fix the crash first (don't add IsVoid in CoreturnStmt) and checking the expressions in later patches if it is needed. Since expressions generally wouldn't break the CFG and the CFG analysis for coroutines are not matured too.

clang/lib/Analysis/CFG.cpp
3110–3111

This is not true for co_return statement. According to http://eel.is/c++draft/stmt.return.coroutine, after co_return we need to execute codes in final suspend points. So the CFG analysis might not be accurate for coroutines. Maybe it is good to leave a FIXME here.

3142

Why we don't use Block here?

3143–3148

According to http://eel.is/c++draft/stmt.return.coroutine#2.2, the expression is sequenced before p.return_void(); Also, this is not covered by tests. We could pass the current test by write the following:

return Visit(CRS->getPromiseCall());
urnathan abandoned this revision.May 18 2022, 4:55 AM