@@ -178,6 +178,16 @@ static bool isTrivialEnumElem(EnumElementDecl *elem, SILType enumType,
178178 enumType.getEnumElementType (elem, function).isTrivial (*function);
179179}
180180
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+
181191static bool isOrHasEnum (SILType type) {
182192 return type.getASTType ().findIf ([](Type ty) {
183193 return ty->getEnumOrBoundGenericEnum () != nullptr ;
@@ -349,7 +359,7 @@ void MemoryLifetimeVerifier::initDataflowInBlock(SILBasicBlock *block,
349359 case SILInstructionKind::InjectEnumAddrInst: {
350360 auto *IEAI = cast<InjectEnumAddrInst>(&I);
351361 int enumIdx = locations.getLocationIdx (IEAI->getOperand ());
352- if (enumIdx >= 0 && !IEAI-> getElement ()-> hasAssociatedValues ( )) {
362+ if (enumIdx >= 0 && injectsNoPayloadCase (IEAI )) {
353363 // This is a bit tricky: an injected no-payload case means that the
354364 // "full" enum is initialized. So, for the purpose of dataflow, we
355365 // treat it like a full initialization of the payload data.
@@ -588,7 +598,7 @@ void MemoryLifetimeVerifier::checkBlock(SILBasicBlock *block, Bits &bits) {
588598 case SILInstructionKind::InjectEnumAddrInst: {
589599 auto *IEAI = cast<InjectEnumAddrInst>(&I);
590600 int enumIdx = locations.getLocationIdx (IEAI->getOperand ());
591- if (enumIdx >= 0 && !IEAI-> getElement ()-> hasAssociatedValues ( )) {
601+ if (enumIdx >= 0 && injectsNoPayloadCase (IEAI )) {
592602 // Again, an injected no-payload case is treated like a "full"
593603 // initialization. See initDataflowInBlock().
594604 requireBitsClear (bits & nonTrivialLocations, IEAI->getOperand (), &I);
0 commit comments