Skip to content

Commit 0f3c066

Browse files
committed
[6.1] Look through forwarding instructions while querying ownership root
While looking for ownership reference root to determine if address uses are within it's lifetime, skip through struct_extract/tuple_extract and other forwarding operations. Fixes rdar://142507746
1 parent 202de3a commit 0f3c066

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

include/swift/SIL/MemAccessUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,13 @@ class AccessBase : public AccessRepresentation {
638638
return findOwnershipReferenceRoot(getReference());
639639
}
640640

641+
/// Return the OSSA root of the reference being accessed
642+
/// looking through struct_extract, tuple_extract, etc.
643+
/// Precondition: isReference() is true.
644+
SILValue getOwnershipReferenceAggregate() const {
645+
return findOwnershipReferenceAggregate(getReference());
646+
}
647+
641648
/// Return the storage root of the reference being accessed.
642649
///
643650
/// Precondition: isReference() is true.

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ bool AddressOwnership::areUsesWithinLifetime(
10931093
if (!base.hasLocalOwnershipLifetime())
10941094
return true;
10951095

1096-
SILValue root = base.getOwnershipReferenceRoot();
1096+
SILValue root = base.getOwnershipReferenceAggregate();
10971097
BorrowedValue borrow(root);
10981098
if (borrow)
10991099
return borrow.areUsesWithinExtendedScope(uses, &deadEndBlocks);

test/SILOptimizer/cse_ossa_nontrivial.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,3 +1010,26 @@ bb0:
10101010
return %t : $()
10111011
}
10121012

1013+
// CHECK-LABEL: sil [ossa] @test_aggreate_tail_addr :
1014+
// CHECK: ref_tail_addr
1015+
// CHECK: ref_tail_addr
1016+
// CHECK-LABEL: } // end sil function 'test_aggreate_tail_addr'
1017+
sil [ossa] @test_aggreate_tail_addr : $@convention(thin) (@owned _NativeDictionary<Int, Klass>) -> () {
1018+
bb0(%0 : @owned $_NativeDictionary<Int, Klass>):
1019+
%49 = move_value [lexical] %0 : $_NativeDictionary<Int, Klass>
1020+
%50 = begin_borrow %49
1021+
%51 = struct_extract %50, #_NativeDictionary._storage
1022+
%52 = copy_value %51
1023+
%53 = ref_tail_addr %51, $_UnsafeBitset.Word
1024+
%59 = load [trivial] %53
1025+
end_borrow %50
1026+
%72 = begin_borrow %52
1027+
%73 = ref_tail_addr %72, $_UnsafeBitset.Word
1028+
%74 = struct_element_addr %73, #_UnsafeBitset.Word.value
1029+
%75 = struct_element_addr %74, #UInt._value
1030+
%76 = load [trivial] %75
1031+
end_borrow %72
1032+
destroy_value %52
1033+
destroy_value %49
1034+
unreachable
1035+
}

0 commit comments

Comments
 (0)