@@ -576,6 +576,18 @@ StackAllocationPromoter::promoteAllocationInBlock(SILBasicBlock *BB) {
576576 return LastStore;
577577}
578578
579+ // / Create a tuple value for an empty tuple or a tuple of empty tuples.
580+ SILValue createValueForEmptyTuple (SILType ty, SILInstruction *insertionPoint) {
581+ auto tupleTy = ty.castTo <TupleType>();
582+ SmallVector<SILValue, 4 > elements;
583+ for (unsigned idx = 0 , end = tupleTy->getNumElements (); idx < end; ++ idx) {
584+ SILType elementTy = ty.getTupleElementType (idx);
585+ elements.push_back (createValueForEmptyTuple (elementTy, insertionPoint));
586+ }
587+ SILBuilder builder (insertionPoint);
588+ return builder.createTuple (insertionPoint->getLoc (), ty, elements);
589+ }
590+
579591void MemoryToRegisters::removeSingleBlockAllocation (AllocStackInst *ASI) {
580592 LLVM_DEBUG (llvm::dbgs () << " *** Promoting in-block: " << *ASI);
581593
@@ -596,7 +608,7 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *ASI) {
596608 if (!RunningVal) {
597609 // Loading without a previous store is only acceptable if the type is
598610 // Void (= empty tuple) or a tuple of Voids.
599- RunningVal = SILUndef::get (ASI->getElementType (), *ASI-> getFunction () );
611+ RunningVal = createValueForEmptyTuple (ASI->getElementType (), Inst );
600612 }
601613 replaceLoad (cast<LoadInst>(Inst), RunningVal, ASI);
602614 ++NumInstRemoved;
0 commit comments