Skip to content

Commit 6966f12

Browse files
committed
OpaqueArchetypeSpecializer: InitEnumDataAddr needs to respect type of operand.
rdar://50591831
1 parent 8cb4456 commit 6966f12

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
@@ -133,18 +133,30 @@ class OpaqueSpecializerCloner
133133
void visitEnumInst(EnumInst *Inst) {
134134
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
135135
SILValue opd = SILValue();
136+
auto newTy = getOpType(Inst->getType());
136137
if (Inst->hasOperand()) {
137-
SILType caseTy = Inst->getType().getEnumElementType(
138-
Inst->getElement(), getBuilder().getFunction().getModule());
139138
opd = getOpValue(Inst->getOperand());
140-
if (opd->getType() != caseTy) {
141-
opd = createCast(getOpLocation(Inst->getLoc()), opd, caseTy);
142-
}
139+
SILType newCaseTy = newTy.getEnumElementType(
140+
Inst->getElement(), getBuilder().getFunction().getModule());
141+
if (opd->getType() != newCaseTy)
142+
opd = createCast(getOpLocation(Inst->getLoc()), opd, newCaseTy);
143143
}
144144
recordClonedInstruction(
145145
Inst, getBuilder().createEnum(getOpLocation(Inst->getLoc()), opd,
146-
Inst->getElement(),
147-
getOpType(Inst->getType())));
146+
Inst->getElement(), newTy));
147+
}
148+
149+
void visitInitEnumDataAddrInst(InitEnumDataAddrInst *Inst) {
150+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
151+
auto opd = getOpValue(Inst->getOperand());
152+
auto caseTy = opd->getType().getEnumElementType(
153+
Inst->getElement(), getBuilder().getFunction().getModule());
154+
auto expectedTy = getOpType(Inst->getType());
155+
if (expectedTy != caseTy)
156+
expectedTy = caseTy;
157+
recordClonedInstruction(Inst, getBuilder().createInitEnumDataAddr(
158+
getOpLocation(Inst->getLoc()), opd,
159+
Inst->getElement(), expectedTy));
148160
}
149161

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

0 commit comments

Comments
 (0)