Blocks that capture themselves (and escape) after initialization currently codegen wrong because this:
bool capturedByInit = Init && emission.IsEscapingByRef && isCapturedBy(D, Init); Address Loc = capturedByInit ? emission.Addr : emission.getObjectAddress(*this);
Already adjusts Loc from thr alloca to a GEP. This code:
if (emission.IsEscapingByRef) Loc = emitBlockByrefAddress(Loc, &D, /*follow=*/false);
Was trying to do the same adjustment, and a GEP on a GEP (returning an int) triggers an assertion.
rdar://problem/47943027
This seems like something we're likely regret eventually. If we've already drilled down to the storage, we should propagate that information into this rather than trying to detect it retroactively here.