@@ -792,9 +792,16 @@ static Operand *getProjectedDefOperand(SILValue value) {
792792
793793// / If \p value is a an existential or enum, then return the existential or enum
794794// / operand. These operations are always rewritten by the UseRewriter and always
795- // / destructively reuse the same storage as their operand. Note that if the
796- // / operation's result is address-only, then the operand must be address-only
797- // / and therefore must mapped to ValueStorage.
795+ // / reuse the same storage as their operand. Note that if the operation's result
796+ // / is address-only, then the operand must be address-only and therefore must
797+ // / mapped to ValueStorage.
798+ // /
799+ // / open_existential_value must reuse storage because the boxed value is shared
800+ // / with other instances of the existential. An explicit copy is needed to
801+ // / obtain an owned value.
802+ // /
803+ // / unchecked_enum_data and switch_enum must reuse storage because extracting
804+ // / the payload destroys the enum value.
798805static Operand *getReusedStorageOperand (SILValue value) {
799806 switch (value->getKind ()) {
800807 default :
@@ -1180,15 +1187,18 @@ createStackAllocation(SILValue value) {
11801187
11811188 auto *openingInst = openingVal->getDefiningInstruction ();
11821189 assert (openingVal && " all opened archetypes should be resolved" );
1183- if (latestOpeningInst
1184- && pass.domInfo ->dominates (openingInst, latestOpeningInst)) {
1185- return ;
1190+ if (latestOpeningInst) {
1191+ if (pass.domInfo ->dominates (openingInst, latestOpeningInst))
1192+ return ;
1193+
1194+ assert (pass.domInfo ->dominates (latestOpeningInst, openingInst) &&
1195+ " opened archetypes must dominate their uses" );
11861196 }
11871197 latestOpeningInst = openingInst;
11881198 }
11891199 });
11901200 auto allocPt = latestOpeningInst ? std::next (latestOpeningInst->getIterator ())
1191- : pass.function ->begin ()->begin ();
1201+ : pass.function ->begin ()->begin ();
11921202 auto allocBuilder = pass.getBuilder (allocPt);
11931203 AllocStackInst *alloc = allocBuilder.createAllocStack (pass.genLoc (), allocTy);
11941204
0 commit comments