Skip to content

Commit 54d28ce

Browse files
committed
OpaqueArchetypeSpecializer: InitEnumDataAddr needs to respect type of operand.
rdar://50591831
1 parent 6b12277 commit 54d28ce

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/SILOptimizer/Transforms/SpecializeOpaqueArchetypes.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,30 @@ class OpaqueSpecializerCloner
138138
void visitEnumInst(EnumInst *Inst) {
139139
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
140140
SILValue opd = SILValue();
141+
auto newTy = getOpType(Inst->getType());
141142
if (Inst->hasOperand()) {
142-
SILType caseTy = Inst->getType().getEnumElementType(
143-
Inst->getElement(), getBuilder().getFunction().getModule());
144143
opd = getOpValue(Inst->getOperand());
145-
if (opd->getType() != caseTy) {
146-
opd = createCast(getOpLocation(Inst->getLoc()), opd, caseTy);
147-
}
144+
SILType newCaseTy = newTy.getEnumElementType(
145+
Inst->getElement(), getBuilder().getFunction().getModule());
146+
if (opd->getType() != newCaseTy)
147+
opd = createCast(getOpLocation(Inst->getLoc()), opd, newCaseTy);
148148
}
149149
recordClonedInstruction(
150150
Inst, getBuilder().createEnum(getOpLocation(Inst->getLoc()), opd,
151-
Inst->getElement(),
152-
getOpType(Inst->getType())));
151+
Inst->getElement(), newTy));
152+
}
153+
154+
void visitInitEnumDataAddrInst(InitEnumDataAddrInst *Inst) {
155+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
156+
auto opd = getOpValue(Inst->getOperand());
157+
auto caseTy = opd->getType().getEnumElementType(
158+
Inst->getElement(), getBuilder().getFunction().getModule());
159+
auto expectedTy = getOpType(Inst->getType());
160+
if (expectedTy != caseTy)
161+
expectedTy = caseTy;
162+
recordClonedInstruction(Inst, getBuilder().createInitEnumDataAddr(
163+
getOpLocation(Inst->getLoc()), opd,
164+
Inst->getElement(), expectedTy));
153165
}
154166

155167
/// Projections should not change the type if the type is not specialized.

0 commit comments

Comments
 (0)