@@ -792,9 +792,16 @@ static Operand *getProjectedDefOperand(SILValue value) {
792
792
793
793
// / If \p value is a an existential or enum, then return the existential or enum
794
794
// / 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.
798
805
static Operand *getReusedStorageOperand (SILValue value) {
799
806
switch (value->getKind ()) {
800
807
default :
@@ -1180,15 +1187,18 @@ createStackAllocation(SILValue value) {
1180
1187
1181
1188
auto *openingInst = openingVal->getDefiningInstruction ();
1182
1189
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" );
1186
1196
}
1187
1197
latestOpeningInst = openingInst;
1188
1198
}
1189
1199
});
1190
1200
auto allocPt = latestOpeningInst ? std::next (latestOpeningInst->getIterator ())
1191
- : pass.function ->begin ()->begin ();
1201
+ : pass.function ->begin ()->begin ();
1192
1202
auto allocBuilder = pass.getBuilder (allocPt);
1193
1203
AllocStackInst *alloc = allocBuilder.createAllocStack (pass.genLoc (), allocTy);
1194
1204
0 commit comments