@@ -138,18 +138,30 @@ class OpaqueSpecializerCloner
138
138
void visitEnumInst (EnumInst *Inst) {
139
139
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
140
140
SILValue opd = SILValue ();
141
+ auto newTy = getOpType (Inst->getType ());
141
142
if (Inst->hasOperand ()) {
142
- SILType caseTy = Inst->getType ().getEnumElementType (
143
- Inst->getElement (), getBuilder ().getFunction ().getModule ());
144
143
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);
148
148
}
149
149
recordClonedInstruction (
150
150
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));
153
165
}
154
166
155
167
// / Projections should not change the type if the type is not specialized.
0 commit comments