Skip to content

Commit 07583f5

Browse files
Merge pull request #77267 from nate-chandler/general-coro/20241028/1
[SIL] Add verifier check to abort_apply.
2 parents ffb22d7 + 46882c6 commit 07583f5

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,12 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
21202120
void checkAbortApplyInst(AbortApplyInst *AI) {
21212121
require(getAsResultOf<BeginApplyInst>(AI->getOperand())->isBeginApplyToken(),
21222122
"operand of abort_apply must be a begin_apply");
2123+
auto *mvi = getAsResultOf<BeginApplyInst>(AI->getOperand());
2124+
auto *bai = cast<BeginApplyInst>(mvi->getParent());
2125+
require(!bai->getSubstCalleeType()->isCalleeAllocatedCoroutine() ||
2126+
AI->getFunction()->getASTContext().LangOpts.hasFeature(
2127+
Feature::CoroutineAccessorsUnwindOnCallerError),
2128+
"abort_apply of callee-allocated yield-once coroutine!?");
21232129
}
21242130

21252131
void checkEndApplyInst(EndApplyInst *AI) {

test/SIL/verifier_failures.sil

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import Builtin
88

99
class C {}
1010

11+
protocol Error {}
12+
1113
// CHECK-LABEL: Begin Error in function end_borrow_1_addr_alloc_stack
1214
// CHECK: SIL verification failed: end_borrow of an address not produced by store_borrow
1315
// CHECK-LABEL: End Error in function end_borrow_1_addr_alloc_stack
@@ -44,3 +46,25 @@ sil [ossa] @dealloc_box_dead_end : $@convention(thin) () -> () {
4446
%retval = tuple()
4547
return %retval : $()
4648
}
49+
50+
// CHECK-LABEL: Begin Error in function abort_apply_callee_allocated_coro
51+
// CHECK: SIL verification failed: abort_apply of callee-allocated yield-once coroutine!?
52+
// CHECK: Verifying instruction:
53+
// CHECK: ({{%[^,]+}}, **[[TOKEN:%[^,]+]]**, {{%[^,]+}}) = begin_apply
54+
// CHECK: -> abort_apply [[TOKEN]]
55+
// CHECK-LABEL: End Error in function abort_apply_callee_allocated_coro
56+
sil [ossa] @abort_apply_callee_allocated_coro : $@convention(thin) () -> (@error any Error) {
57+
entry:
58+
(%value, %token, %allocation) = begin_apply undef() : $@yield_once_2 @convention(thin) () -> @yields @in_guaranteed ()
59+
try_apply undef() : $@convention(thin) () -> @error any Error, normal success, error failure
60+
61+
success(%val : $()):
62+
end_apply %token as $()
63+
dealloc_stack %allocation : $*Builtin.SILToken
64+
return undef : $()
65+
66+
failure(%error : @owned $any Error):
67+
abort_apply %token
68+
dealloc_stack %allocation : $*Builtin.SILToken
69+
throw %error : $any Error
70+
}

0 commit comments

Comments
 (0)