@@ -29,6 +29,14 @@ struct AddressWalkerState {
2929static SILValue
3030findRootValueForNonTupleTempAllocation (AllocationInst *allocInst,
3131 AddressWalkerState &state) {
32+ // These are instructions which we are ok with looking through when
33+ // identifying our allocation. It must always refer to the entire allocation.
34+ auto isAlloc = [&](SILValue value) -> bool {
35+ if (auto *ieai = dyn_cast<InitExistentialAddrInst>(value))
36+ value = ieai->getOperand ();
37+ return value == SILValue (allocInst);
38+ };
39+
3240 // Walk from our allocation to one of our writes. Then make sure that the
3341 // write writes to our entire value.
3442 for (auto &inst : allocInst->getParent ()->getRangeStartingAtInst (allocInst)) {
@@ -38,21 +46,21 @@ findRootValueForNonTupleTempAllocation(AllocationInst *allocInst,
3846 continue ;
3947
4048 if (auto *copyAddr = dyn_cast<CopyAddrInst>(&inst)) {
41- if (copyAddr->getDest () == allocInst &&
49+ if (isAlloc ( copyAddr->getDest ()) &&
4250 copyAddr->isInitializationOfDest ()) {
4351 return copyAddr->getSrc ();
4452 }
4553 }
4654
4755 if (auto *si = dyn_cast<StoreInst>(&inst)) {
48- if (si->getDest () == allocInst &&
56+ if (isAlloc ( si->getDest ()) &&
4957 si->getOwnershipQualifier () != StoreOwnershipQualifier::Assign) {
5058 return si->getSrc ();
5159 }
5260 }
5361
5462 if (auto *sbi = dyn_cast<StoreBorrowInst>(&inst)) {
55- if (sbi->getDest () == allocInst )
63+ if (isAlloc ( sbi->getDest ()) )
5664 return sbi->getSrc ();
5765 }
5866
0 commit comments