@@ -178,6 +178,16 @@ static bool isTrivialEnumElem(EnumElementDecl *elem, SILType enumType,
178
178
enumType.getEnumElementType (elem, function).isTrivial (*function);
179
179
}
180
180
181
+ static bool injectsNoPayloadCase (InjectEnumAddrInst *IEAI) {
182
+ if (!IEAI->getElement ()->hasAssociatedValues ())
183
+ return true ;
184
+ SILType enumType = IEAI->getOperand ()->getType ();
185
+ SILFunction *function = IEAI->getFunction ();
186
+ SILType elemType = enumType.getEnumElementType (IEAI->getElement (), function);
187
+ // Handle empty types (e.g. the empty tuple) as no-payload.
188
+ return elemType.isEmpty (*function);
189
+ }
190
+
181
191
static bool isOrHasEnum (SILType type) {
182
192
return type.getASTType ().findIf ([](Type ty) {
183
193
return ty->getEnumOrBoundGenericEnum () != nullptr ;
@@ -349,7 +359,7 @@ void MemoryLifetimeVerifier::initDataflowInBlock(SILBasicBlock *block,
349
359
case SILInstructionKind::InjectEnumAddrInst: {
350
360
auto *IEAI = cast<InjectEnumAddrInst>(&I);
351
361
int enumIdx = locations.getLocationIdx (IEAI->getOperand ());
352
- if (enumIdx >= 0 && !IEAI-> getElement ()-> hasAssociatedValues ( )) {
362
+ if (enumIdx >= 0 && injectsNoPayloadCase (IEAI )) {
353
363
// This is a bit tricky: an injected no-payload case means that the
354
364
// "full" enum is initialized. So, for the purpose of dataflow, we
355
365
// treat it like a full initialization of the payload data.
@@ -588,7 +598,7 @@ void MemoryLifetimeVerifier::checkBlock(SILBasicBlock *block, Bits &bits) {
588
598
case SILInstructionKind::InjectEnumAddrInst: {
589
599
auto *IEAI = cast<InjectEnumAddrInst>(&I);
590
600
int enumIdx = locations.getLocationIdx (IEAI->getOperand ());
591
- if (enumIdx >= 0 && !IEAI-> getElement ()-> hasAssociatedValues ( )) {
601
+ if (enumIdx >= 0 && injectsNoPayloadCase (IEAI )) {
592
602
// Again, an injected no-payload case is treated like a "full"
593
603
// initialization. See initDataflowInBlock().
594
604
requireBitsClear (bits & nonTrivialLocations, IEAI->getOperand (), &I);
0 commit comments