We hit an assert in AllocStackHoisting that is only triggered in a release lto
build.
Clang forwards the read of parent basic block of 'AssignedLoc' in the next
statement:
auto *EntryBB = AssignedLoc->getFunction()->getEntryBlock(); // read AssignedLoc->ParentBB
AssignedLoc->removeFromParent(); // writes AssignedLoc->ParentBB
To this read:
EntryBB->push_front(AssignedLoc); // read AssignedLoc->ParentBB and assert if non-null, *should reload*
As a temporary workaround outline code to prevent the miscompile.
rdar://29982182
Hoist alloc_stack instructions of 'generic' or resilient type to the entry
block. At the same time also perform a very simple stack coloring analysis.
This does not use a true liveness-analysis yet but rather employs some simple
conservative checks to see whether the live ranges of two alloc_stacks might
interfere.
AllocStackHoisting is an IRGen SIL pass. This allows for using IRGen's type
lowering information. Furthermore, hoisting and merging the alloc_stack
instructions this late does not interfere with SIL optimizations because the
resulting SIL never gets serialized.