@@ -679,18 +679,18 @@ replaceLoad(SILInstruction *inst, SILValue newValue, AllocStackInst *asi,
679
679
}
680
680
}
681
681
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) {
687
688
auto *function = insertionPoint->getFunction ();
688
- assert (ty.isEmpty (*function));
689
689
if (auto tupleTy = ty.getAs <TupleType>()) {
690
690
SmallVector<SILValue, 4 > elements;
691
691
for (unsigned idx : range (tupleTy->getNumElements ())) {
692
692
SILType elementTy = ty.getTupleElementType (idx);
693
- auto element = createValueForEmptyType (elementTy, insertionPoint, ctx);
693
+ auto element = createEmptyAndUndefValue (elementTy, insertionPoint, ctx);
694
694
elements.push_back (element);
695
695
}
696
696
SILBuilderWithScope builder (insertionPoint, ctx);
@@ -707,15 +707,14 @@ static SILValue createValueForEmptyType(SILType ty,
707
707
SmallVector<SILValue, 4 > elements;
708
708
for (auto *field : decl->getStoredProperties ()) {
709
709
auto elementTy = ty.getFieldType (field, module , tec);
710
- auto element = createValueForEmptyType (elementTy, insertionPoint, ctx);
710
+ auto element = createEmptyAndUndefValue (elementTy, insertionPoint, ctx);
711
711
elements.push_back (element);
712
712
}
713
713
SILBuilderWithScope builder (insertionPoint, ctx);
714
714
return builder.createStruct (insertionPoint->getLoc (), ty, elements);
715
+ } else {
716
+ return SILUndef::get (ty, *insertionPoint->getFunction ());
715
717
}
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." );
719
718
}
720
719
721
720
// / Whether lexical lifetimes should be added for the values stored into the
@@ -1982,7 +1981,7 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
1982
1981
// empty--an aggregate of types without storage.
1983
1982
runningVals = {
1984
1983
LiveValues::toReplace (asi,
1985
- /* replacement=*/ createValueForEmptyType (
1984
+ /* replacement=*/ createEmptyAndUndefValue (
1986
1985
asi->getElementType (), inst, ctx)),
1987
1986
/* isStorageValid=*/ true };
1988
1987
}
0 commit comments