Skip to content

Commit 6f46d42

Browse files
committed
Allow a borrowed address to be passed as in_guaranteed arg in partial_apply [on_stack] only
1 parent 3ecc3d4 commit 6f46d42

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/SIL/Verifier/LoadBorrowImmutabilityChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ bool GatherWritesVisitor::visitUse(Operand *op, AccessUseType useTy) {
245245

246246
if (auto *pa = dyn_cast<PartialApplyInst>(user)) {
247247
auto argConv = ApplySite(user).getArgumentConvention(*op);
248-
if (argConv == SILArgumentConvention::Indirect_In_Guaranteed) {
248+
if (pa->isOnStack() &&
249+
argConv == SILArgumentConvention::Indirect_In_Guaranteed) {
249250
return true;
250251
}
251252

test/SIL/ownership-verifier/load_borrow_invalidation_partial_apply.sil

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all -inline %s -o /dev/null
1+
// RUN: %target-sil-opt -enable-sil-verify-all -inline %s -verify-continue-on-failure=true -o /dev/null 2>&1 | %FileCheck %s
2+
// REQUIRES: asserts
23

34
// Tests here are patterns we should not consider as broken
45

@@ -37,6 +38,7 @@ bb0(%0 : $*WrapperStruct):
3738
return %res : $()
3839
}
3940

41+
// CHECK-NOT: Function: 'caller1'
4042
sil [ossa] @caller1 : $@convention(thin) (@owned WrapperStruct) -> () {
4143
bb0(%0 : @owned $WrapperStruct):
4244
%stk = alloc_stack $WrapperStruct
@@ -49,6 +51,9 @@ bb0(%0 : @owned $WrapperStruct):
4951
return %res : $()
5052
}
5153

54+
// CHECK-LABEL: Begin Error in function caller2
55+
// CHECK: SIL verification failed: Found load borrow that is invalidated by a local write?!: loadBorrowImmutabilityAnalysis.isImmutable(LBI)
56+
// CHECK-LABEL: End Error in function caller2
5257
sil [ossa] @caller2 : $@convention(thin) (@owned WrapperStruct) -> () {
5358
bb0(%0 : @owned $WrapperStruct):
5459
%stk = alloc_stack $WrapperStruct

0 commit comments

Comments
 (0)