This is an archive of the discontinued LLVM Phabricator instance.

[Coroutines] Do not add allocas for retcon coroutines
ClosedPublic

Authored by sebastian-ne on Nov 11 2022, 1:39 PM.

Details

Summary

Same as for async-style lowering, if there are no resume points in a
function, the coroutine frame pointer will be replaced by an undef,
making all accesses to the frame undefinde behavior.

Fix this by not adding allocas to the coroutine frame if there are no
resume points.

The test is new, I'll pre-commit if this is accepted.

Diff Detail

Event Timeline

sebastian-ne created this revision.Nov 11 2022, 1:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 1:39 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
sebastian-ne requested review of this revision.Nov 11 2022, 1:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 1:39 PM
ChuanqiXu accepted this revision.Nov 13 2022, 4:46 AM

To be honest, I'm not familiar with retcon ABI. But the explanation, the patch itself looks good. If you want to find a better reviewer, you can use git log for the coroutines updates.

This revision is now accepted and ready to land.Nov 13 2022, 4:46 AM

Not your code, but:

Maybe it would be cleaner to check whether we need a frame object at all instead of adding special case handling for allocas?
Then, based on that condition, we could skip setup of the frame type and pointer, and leave the alloca's unchanged.

If that's too much of a change, I'm fine with the proposed change, as it just fixes the existing condition.

llvm/test/Transforms/Coroutines/coro-retcon.ll
142

Note the unused frame pointer here.

This revision was landed with ongoing or failed builds.Nov 14 2022, 1:47 AM
This revision was automatically updated to reflect the committed changes.

Not your code, but:

Maybe it would be cleaner to check whether we need a frame object at all instead of adding special case handling for allocas?
Then, based on that condition, we could skip setup of the frame type and pointer, and leave the alloca's unchanged.

If that's too much of a change, I'm fine with the proposed change, as it just fixes the existing condition.

I committed this for now as it just extends the existing handling for async to retcon. I’ll take a look at implementing your suggestion.