Skip to content

Commit 6471188

Browse files
authored
Merge pull request #61883 from meg-gupta/lbisuniq
LoadBorrowImmutabilityVerifier: Mark is_unique as a write
2 parents eaa26f2 + ce332b9 commit 6471188

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/SIL/Verifier/LoadBorrowImmutabilityChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ bool GatherWritesVisitor::visitUse(Operand *op, AccessUseType useTy) {
9898
case SILInstructionKind::DeallocBoxInst:
9999
case SILInstructionKind::WitnessMethodInst:
100100
case SILInstructionKind::ExistentialMetatypeInst:
101-
case SILInstructionKind::IsUniqueInst:
102101
case SILInstructionKind::HopToExecutorInst:
103102
case SILInstructionKind::ExtractExecutorInst:
104103
case SILInstructionKind::ValueMetatypeInst:
@@ -115,6 +114,7 @@ bool GatherWritesVisitor::visitUse(Operand *op, AccessUseType useTy) {
115114
case SILInstructionKind::MarkFunctionEscapeInst:
116115
case SILInstructionKind::DeallocRefInst:
117116
case SILInstructionKind::DeallocPartialRefInst:
117+
case SILInstructionKind::IsUniqueInst:
118118
writeAccumulator.push_back(op);
119119
return true;
120120

test/SIL/OwnershipVerifier/load_borrow_verify_errors.sil

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-sil-opt %s -verify-continue-on-failure=true -o /dev/null 2>&1 | %FileCheck %s
2+
import Builtin
23

34
class Klass {}
45

@@ -71,3 +72,31 @@ bb6(%ld : @guaranteed $Klass):
7172
return %6 : $()
7273
}
7374

75+
struct ArrayIntBuffer {
76+
var storage : Builtin.NativeObject
77+
}
78+
79+
struct MyArray<T> {
80+
var buffer : ArrayIntBuffer
81+
}
82+
83+
struct MyStruct {
84+
}
85+
86+
// CHECK: Write: %4 = is_unique %1 : $*ArrayIntBuffer
87+
// CHECK: Begin Error in function test_is_unique
88+
// CHECK: SIL verification failed: Found load borrow that is invalidated by a local write?!: loadBorrowImmutabilityAnalysis.isImmutable(LBI)
89+
// CHECK: End Error in function test_is_unique
90+
sil [ossa] @test_is_unique : $@convention(thin) (@in MyArray<MyStruct>) -> () {
91+
bb0(%0 : $*MyArray<MyStruct>):
92+
%1 = struct_element_addr %0 : $*MyArray<MyStruct>, #MyArray.buffer
93+
%2 = load_borrow %1 : $*ArrayIntBuffer
94+
%3 = struct $MyArray<MyStruct>(%2 : $ArrayIntBuffer)
95+
%6 = is_unique %1 : $*ArrayIntBuffer
96+
%7 = struct $MyArray<MyStruct>(%2 : $ArrayIntBuffer)
97+
end_borrow %2 : $ArrayIntBuffer
98+
destroy_addr %0 : $*MyArray<MyStruct>
99+
%t = tuple ()
100+
return %t : $()
101+
}
102+

0 commit comments

Comments
 (0)