@@ -133,18 +133,30 @@ class OpaqueSpecializerCloner
133
133
void visitEnumInst (EnumInst *Inst) {
134
134
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
135
135
SILValue opd = SILValue ();
136
+ auto newTy = getOpType (Inst->getType ());
136
137
if (Inst->hasOperand ()) {
137
- SILType caseTy = Inst->getType ().getEnumElementType (
138
- Inst->getElement (), getBuilder ().getFunction ().getModule ());
139
138
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);
143
143
}
144
144
recordClonedInstruction (
145
145
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));
148
160
}
149
161
150
162
// / Projections should not change the type if the type is not specialized.
0 commit comments