Skip to content

[SIL] Add verifier check to abort_apply. #77267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,12 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
void checkAbortApplyInst(AbortApplyInst *AI) {
require(getAsResultOf<BeginApplyInst>(AI->getOperand())->isBeginApplyToken(),
"operand of abort_apply must be a begin_apply");
auto *mvi = getAsResultOf<BeginApplyInst>(AI->getOperand());
auto *bai = cast<BeginApplyInst>(mvi->getParent());
require(!bai->getSubstCalleeType()->isCalleeAllocatedCoroutine() ||
AI->getFunction()->getASTContext().LangOpts.hasFeature(
Feature::CoroutineAccessorsUnwindOnCallerError),
"abort_apply of callee-allocated yield-once coroutine!?");
}

void checkEndApplyInst(EndApplyInst *AI) {
Expand Down
24 changes: 24 additions & 0 deletions test/SIL/verifier_failures.sil
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Builtin

class C {}

protocol Error {}

// CHECK-LABEL: Begin Error in function end_borrow_1_addr_alloc_stack
// CHECK: SIL verification failed: end_borrow of an address not produced by store_borrow
// CHECK-LABEL: End Error in function end_borrow_1_addr_alloc_stack
Expand Down Expand Up @@ -44,3 +46,25 @@ sil [ossa] @dealloc_box_dead_end : $@convention(thin) () -> () {
%retval = tuple()
return %retval : $()
}

// CHECK-LABEL: Begin Error in function abort_apply_callee_allocated_coro
// CHECK: SIL verification failed: abort_apply of callee-allocated yield-once coroutine!?
// CHECK: Verifying instruction:
// CHECK: ({{%[^,]+}}, **[[TOKEN:%[^,]+]]**, {{%[^,]+}}) = begin_apply
// CHECK: -> abort_apply [[TOKEN]]
// CHECK-LABEL: End Error in function abort_apply_callee_allocated_coro
sil [ossa] @abort_apply_callee_allocated_coro : $@convention(thin) () -> (@error any Error) {
entry:
(%value, %token, %allocation) = begin_apply undef() : $@yield_once_2 @convention(thin) () -> @yields @in_guaranteed ()
try_apply undef() : $@convention(thin) () -> @error any Error, normal success, error failure

success(%val : $()):
end_apply %token as $()
dealloc_stack %allocation : $*Builtin.SILToken
return undef : $()

failure(%error : @owned $any Error):
abort_apply %token
dealloc_stack %allocation : $*Builtin.SILToken
throw %error : $any Error
}