Skip to content

Commit f7e7fed

Browse files
committed
Use AccessPath exact use visitor in LoadBorrowImmutabilityChecker
1 parent 18c04b5 commit f7e7fed

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

lib/SIL/Verifier/LoadBorrowImmutabilityChecker.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GatherWritesVisitor : public AccessUseVisitor {
4949

5050
public:
5151
GatherWritesVisitor(SmallVectorImpl<Operand *> &writes)
52-
: AccessUseVisitor(AccessUseType::Overlapping,
52+
: AccessUseVisitor(AccessUseType::Exact,
5353
NestedAccessType::StopAtAccessBegin),
5454
writeAccumulator(writes) {}
5555

@@ -339,12 +339,6 @@ bool LoadBorrowImmutabilityAnalysis::isImmutableInScope(
339339
if (deadEndBlocks.isDeadEnd(write->getParent())) {
340340
continue;
341341
}
342-
// A destroy_value will be a definite write only when the destroy is on the
343-
// ownershipRoot
344-
if (isa<DestroyValueInst>(write)) {
345-
if (op->get() != ownershipRoot)
346-
continue;
347-
}
348342

349343
if (borrowLiveness.isWithinBoundary(write)) {
350344
llvm::errs() << "Write: " << *write;

test/SIL/OwnershipVerifier/load_borrow_invalidation_test.sil

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ bb0(%0 : @owned $Builtin.NativeObject):
429429
return %9999 : $()
430430
}
431431

432-
class ComplexStruct {
432+
class KlassWithStruct {
433433
var val : NonTrivialStruct
434434
}
435435

@@ -440,17 +440,51 @@ struct NonTrivialStruct {
440440
var val : Klass
441441
}
442442

443-
sil [ossa] @test_borrow : $@convention(thin) (@owned ComplexStruct) -> () {
444-
bb0(%0 : @owned $ComplexStruct):
445-
%2 = copy_value %0 : $ComplexStruct
446-
%4 = begin_borrow %2 : $ComplexStruct
447-
%5 = ref_element_addr %4 : $ComplexStruct, #ComplexStruct.val
443+
sil [ossa] @test_borrow : $@convention(thin) (@owned KlassWithStruct) -> () {
444+
bb0(%0 : @owned $KlassWithStruct):
445+
%2 = copy_value %0 : $KlassWithStruct
446+
%4 = begin_borrow %2 : $KlassWithStruct
447+
%5 = ref_element_addr %4 : $KlassWithStruct, #KlassWithStruct.val
448448
%6 = load_borrow %5 : $*NonTrivialStruct
449-
destroy_value %0 : $ComplexStruct
449+
destroy_value %0 : $KlassWithStruct
450450
end_borrow %6 : $NonTrivialStruct
451-
end_borrow %4 : $ComplexStruct
452-
destroy_value %2 : $ComplexStruct
451+
end_borrow %4 : $KlassWithStruct
452+
destroy_value %2 : $KlassWithStruct
453453
%ret = tuple ()
454454
return %ret : $()
455455
}
456456

457+
sil [ossa] @test_overlapping_write1 : $@convention(method) (@guaranteed KlassWithStruct) -> () {
458+
bb0(%0 : @guaranteed $KlassWithStruct):
459+
%2 = copy_value %0 : $KlassWithStruct
460+
%5 = ref_element_addr %0 : $KlassWithStruct, #KlassWithStruct.val
461+
%6 = begin_access [read] [dynamic] %5 : $*NonTrivialStruct
462+
%7 = load_borrow %6 : $*NonTrivialStruct
463+
%11 = alloc_stack $KlassWithStruct
464+
store %2 to [init] %11 : $*KlassWithStruct
465+
destroy_addr %11 : $*KlassWithStruct
466+
dealloc_stack %11 : $*KlassWithStruct
467+
end_borrow %7 : $NonTrivialStruct
468+
end_access %6 : $*NonTrivialStruct
469+
%t = tuple ()
470+
return %t : $()
471+
}
472+
473+
sil [ossa] @test_overlapping_write2 : $@convention(method) (@guaranteed KlassWithStruct) -> () {
474+
bb0(%0 : @guaranteed $KlassWithStruct):
475+
%2 = copy_value %0 : $KlassWithStruct
476+
%3 = begin_borrow %2 : $KlassWithStruct
477+
%5 = ref_element_addr %3 : $KlassWithStruct, #KlassWithStruct.val
478+
%6 = begin_access [read] [dynamic] %5 : $*NonTrivialStruct
479+
%7 = load_borrow %6 : $*NonTrivialStruct
480+
%11 = alloc_stack $KlassWithStruct
481+
%12 = store_borrow %0 to %11 : $*KlassWithStruct
482+
end_borrow %12 : $*KlassWithStruct
483+
dealloc_stack %11 : $*KlassWithStruct
484+
end_borrow %7 : $NonTrivialStruct
485+
end_access %6 : $*NonTrivialStruct
486+
end_borrow %3 : $KlassWithStruct
487+
destroy_value %2 : $KlassWithStruct
488+
%t = tuple ()
489+
return %t : $()
490+
}

0 commit comments

Comments
 (0)