bug 45566 shows the process of building coroutine frame won't consider that the lifetimes of different local variables are not overlapped, which means the compiler could generates smaller frame.
struct big_structure { big_structure(); char dummy[500]; }; cppcoro::task<void> alternative_paths(bool cond) { // 1072 byte coroutine frame if (cond) { big_structure a; process(a); co_await something(); } else { big_structure b; process2(b); co_await something(); } } void normal_function(bool cond) { // 512 byte stack frame if (cond) { big_structure a; process(a); } else { big_structure b; process2(b); } }
This patch calculate the lifetime range of each alloca by StackLifetime class. Then the patch build non-overlapped sets for allocas whose lifetime ranges are not overlapped. We use the largest type in a non-overlapped set as the field type in the frame. In insertSpills process, if we find the type of field is not the same with the alloca, we cast the pointer to the field type to the pointer to the alloca type. Since the lifetime range of alloca in one non-overlapped set is not overlapped with each other, it should be ok to reuse the storage space in the frame.
Test plan: check-llvm, check-clang, cppcoro, folly
This isn't needed anymore