@@ -679,18 +679,18 @@ replaceLoad(SILInstruction *inst, SILValue newValue, AllocStackInst *asi,
679679 }
680680}
681681
682- // / Instantiate the specified empty type by recursively tupling and structing
683- // / the empty types aggregated together at each level.
684- static SILValue createValueForEmptyType (SILType ty,
685- SILInstruction *insertionPoint,
686- SILBuilderContext &ctx) {
682+ // / Instantiate the specified type by recursively tupling and structing the
683+ // / unique instances of the empty types and undef "instances" of the non-empty
684+ // / types aggregated together at each level.
685+ static SILValue createEmptyAndUndefValue (SILType ty,
686+ SILInstruction *insertionPoint,
687+ SILBuilderContext &ctx) {
687688 auto *function = insertionPoint->getFunction ();
688- assert (ty.isEmpty (*function));
689689 if (auto tupleTy = ty.getAs <TupleType>()) {
690690 SmallVector<SILValue, 4 > elements;
691691 for (unsigned idx : range (tupleTy->getNumElements ())) {
692692 SILType elementTy = ty.getTupleElementType (idx);
693- auto element = createValueForEmptyType (elementTy, insertionPoint, ctx);
693+ auto element = createEmptyAndUndefValue (elementTy, insertionPoint, ctx);
694694 elements.push_back (element);
695695 }
696696 SILBuilderWithScope builder (insertionPoint, ctx);
@@ -707,15 +707,14 @@ static SILValue createValueForEmptyType(SILType ty,
707707 SmallVector<SILValue, 4 > elements;
708708 for (auto *field : decl->getStoredProperties ()) {
709709 auto elementTy = ty.getFieldType (field, module , tec);
710- auto element = createValueForEmptyType (elementTy, insertionPoint, ctx);
710+ auto element = createEmptyAndUndefValue (elementTy, insertionPoint, ctx);
711711 elements.push_back (element);
712712 }
713713 SILBuilderWithScope builder (insertionPoint, ctx);
714714 return builder.createStruct (insertionPoint->getLoc (), ty, elements);
715+ } else {
716+ return SILUndef::get (ty, *insertionPoint->getFunction ());
715717 }
716- llvm::errs () << " Attempting to create value for illegal empty type:\n " ;
717- ty.print (llvm::errs ());
718- llvm::report_fatal_error (" illegal empty type: neither tuple nor struct." );
719718}
720719
721720// / Whether lexical lifetimes should be added for the values stored into the
@@ -1982,7 +1981,7 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
19821981 // empty--an aggregate of types without storage.
19831982 runningVals = {
19841983 LiveValues::toReplace (asi,
1985- /* replacement=*/ createValueForEmptyType (
1984+ /* replacement=*/ createEmptyAndUndefValue (
19861985 asi->getElementType (), inst, ctx)),
19871986 /* isStorageValid=*/ true };
19881987 }
0 commit comments