@@ -1688,8 +1688,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
1688
1688
}
1689
1689
1690
1690
static bool isLegalSILTokenProducer (SILValue value) {
1691
- if (auto *baResult = isaResultOf<BeginApplyInst>(value))
1692
- return baResult->isBeginApplyToken ();
1691
+ if (auto *baResult = isaResultOf<BeginApplyInst>(value)) {
1692
+ auto *bai = cast<BeginApplyInst>(baResult->getParent ());
1693
+ return value == bai->getTokenResult () ||
1694
+ value == bai->getCalleeAllocationResult ();
1695
+ }
1693
1696
1694
1697
if (isa<OpenPackElementInst>(value))
1695
1698
return true ;
@@ -3772,12 +3775,23 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
3772
3775
}
3773
3776
3774
3777
void checkDeallocStackInst (DeallocStackInst *DI) {
3778
+ auto isTokenFromCalleeAllocatedBeginApply = [](SILValue value) -> bool {
3779
+ auto *inst = value->getDefiningInstruction ();
3780
+ if (!inst)
3781
+ return false ;
3782
+ auto *bai = dyn_cast<BeginApplyInst>(inst);
3783
+ if (!bai)
3784
+ return false ;
3785
+ return value == bai->getCalleeAllocationResult ();
3786
+ };
3775
3787
require (isa<SILUndef>(DI->getOperand ()) ||
3776
3788
isa<AllocStackInst>(DI->getOperand ()) ||
3777
3789
isa<AllocVectorInst>(DI->getOperand ()) ||
3778
3790
(isa<PartialApplyInst>(DI->getOperand ()) &&
3779
- cast<PartialApplyInst>(DI->getOperand ())->isOnStack ()),
3780
- " Operand of dealloc_stack must be an alloc_stack, alloc_vector or partial_apply "
3791
+ cast<PartialApplyInst>(DI->getOperand ())->isOnStack ()) ||
3792
+ (isTokenFromCalleeAllocatedBeginApply (DI->getOperand ())),
3793
+ " Operand of dealloc_stack must be an alloc_stack, alloc_vector or "
3794
+ " partial_apply "
3781
3795
" [stack]" );
3782
3796
}
3783
3797
void checkDeallocPackInst (DeallocPackInst *DI) {
@@ -6768,7 +6782,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
6768
6782
};
6769
6783
6770
6784
struct BBState {
6771
- std::vector<SingleValueInstruction* > Stack;
6785
+ std::vector<SILValue > Stack;
6772
6786
6773
6787
// / Contents: BeginAccessInst*, BeginApplyInst*.
6774
6788
std::set<SILInstruction*> ActiveOps;
@@ -6818,9 +6832,15 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
6818
6832
}
6819
6833
6820
6834
if (i.isAllocatingStack ()) {
6821
- state.Stack .push_back (cast<SingleValueInstruction>(&i));
6822
-
6823
- } else if (i.isDeallocatingStack ()) {
6835
+ if (auto *BAI = dyn_cast<BeginApplyInst>(&i)) {
6836
+ state.Stack .push_back (BAI->getCalleeAllocationResult ());
6837
+ } else {
6838
+ state.Stack .push_back (cast<SingleValueInstruction>(&i));
6839
+ }
6840
+ // Not "else if": begin_apply both allocates stack and begins an
6841
+ // operation.
6842
+ }
6843
+ if (i.isDeallocatingStack ()) {
6824
6844
SILValue op = i.getOperand (0 );
6825
6845
while (auto *mvi = dyn_cast<MoveValueInst>(op)) {
6826
6846
op = mvi->getOperand ();
0 commit comments