This is an archive of the discontinued LLVM Phabricator instance.

[coroutines] Respect alloca alignment requirements when building coroutine frame
ClosedPublic

Authored by GorNishanov on Apr 3 2018, 11:43 AM.

Details

Summary

If an alloca need to be stored in the coroutine frame and it has an alignment specified and the alignment does not match the natural alignment of the alloca type. Insert appropriate padding into the coroutine frame to make sure that it gets requested alignment.

For example for a packet type (which natural alignment is 1), but alloca alignment is 8, we may need to insert a padding field with required number of bytes to make sure it is properly aligned.

%PackedStruct = type <{ i64 }>
...
  %data = alloca %PackedStruct, align 8

If the previous field in the coroutine frame had alignment 2, we would have [6 x i8] inserted before %PackedStruct in the coroutine frame:

%f.Frame = type { ..., i16, [6 x i8], %PackedStruct }

Diff Detail

Repository
rL LLVM

Event Timeline

GorNishanov created this revision.Apr 3 2018, 11:43 AM
modocache accepted this revision.Apr 3 2018, 1:00 PM

Thank you, @GorNishanov, this is excellent! I've pulled this down and confirmed it fixes some nasty errors in a codebase I work on, related to [[ https://github.com/facebook/folly/blob/3cec1c6b4ccfa4b80effad376f6321ce9b70cec1/folly/Function.h#L253 | this usage of std::aligned_storage ]]. The problem also reproduced with this much smaller example: https://reviews.llvm.org/P8076 -- and I've confirmed this change of yours fixes that, too. So, thank you!

The code itself looks good to me!

This revision is now accepted and ready to land.Apr 3 2018, 1:00 PM
This revision was automatically updated to reflect the committed changes.