@@ -483,10 +483,11 @@ static void unrollForEach(ArrayInfo &arrayInfo, TryApplyInst *forEachCall,
483
483
// targets must be taking a phi argument.
484
484
SILBasicBlock *normalBB = forEachCall->getNormalBB ();
485
485
SILBasicBlock *errorBB = forEachCall->getErrorBB ();
486
- assert (errorBB->getSILPhiArguments ().size () == 1 &&
487
- normalBB->getSILPhiArguments ().size () == 1 );
486
+ assert (normalBB->getSILPhiArguments ().size () == 1 );
488
487
SILPhiArgument *normalArgument = normalBB->getSILPhiArguments ()[0 ];
489
- SILPhiArgument *errorArgument = errorBB->getSILPhiArguments ()[0 ];
488
+ SILPhiArgument *errorArgument = nullptr ;
489
+ if (errorBB->getSILPhiArguments ().size () == 1 )
490
+ errorArgument = errorBB->getSILPhiArguments ()[0 ];
490
491
491
492
// A generator for creating a basic block for use as the target of the
492
493
// "normal" branch of a try_apply.
@@ -503,8 +504,12 @@ static void unrollForEach(ArrayInfo &arrayInfo, TryApplyInst *forEachCall,
503
504
auto errorTargetGenerator = [&](SILBasicBlock *insertionBlock,
504
505
SILValue borrowedElem, SILValue storeBorrow) {
505
506
SILBasicBlock *newErrorBB = fun->createBasicBlockBefore (insertionBlock);
506
- SILValue argument = newErrorBB->createPhiArgument (
507
+ SILValue argument;
508
+ if (errorArgument) {
509
+ argument = newErrorBB->createPhiArgument (
507
510
errorArgument->getType (), errorArgument->getOwnershipKind ());
511
+ }
512
+
508
513
// Make the errorBB jump to the error target of the original forEach.
509
514
SILBuilderWithScope builder (newErrorBB, forEachCall);
510
515
if (storeBorrow) {
@@ -513,7 +518,11 @@ static void unrollForEach(ArrayInfo &arrayInfo, TryApplyInst *forEachCall,
513
518
if (borrowedElem) {
514
519
builder.createEndBorrow (forEachLoc, borrowedElem);
515
520
}
516
- builder.createBranch (forEachLoc, errorBB, argument);
521
+
522
+ if (argument)
523
+ builder.createBranch (forEachLoc, errorBB, argument);
524
+ else
525
+ builder.createBranch (forEachLoc, errorBB);
517
526
return newErrorBB;
518
527
};
519
528
0 commit comments