Skip to content

Commit 1c023fd

Browse files
committed
[ConsumeChecker] Check guaranteed arguments.
Such values could be referenced in a ConsumeExpr, so the checker must check them. Furthermore, it's legal to consume such values so long as they aren't annotated `borrowing`.
1 parent 9bf9b00 commit 1c023fd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ bool ConsumeOperatorCopyableValuesChecker::check() {
400400
llvm::SmallSetVector<SILValue, 32> valuesToCheck;
401401

402402
for (auto *arg : fn->getEntryBlock()->getSILFunctionArguments()) {
403-
if (arg->getOwnershipKind() == OwnershipKind::Owned &&
403+
auto ownership = arg->getOwnershipKind();
404+
if ((ownership == OwnershipKind::Owned ||
405+
ownership == OwnershipKind::Guaranteed) &&
404406
!arg->getType().isMoveOnly()) {
405407
LLVM_DEBUG(llvm::dbgs() << "Found owned arg to check: " << *arg);
406408
valuesToCheck.insert(arg);

test/SILOptimizer/consume_operator_kills_copyable_values.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,26 @@ func consumeArrayAny() {
376376
_ = consume a
377377
}
378378

379+
func consumeConsuming(_ k: consuming Klass) {
380+
_ = consume k
381+
}
382+
383+
func consumeBorrowing(_ k: borrowing Klass) { // expected-error{{'k' is borrowed and cannot be consumed}}
384+
_ = consume k // expected-note{{consumed here}}
385+
}
386+
387+
func consumeOwned(_ k: __owned Klass) {
388+
_ = consume k
389+
}
390+
391+
func consumeShared(_ k: __shared Klass) {
392+
_ = consume k
393+
}
394+
395+
func consumeBare(_ k: Klass) {
396+
_ = consume k
397+
}
398+
379399
/////////////////////////
380400
// Partial Apply Tests //
381401
/////////////////////////

0 commit comments

Comments
 (0)