Skip to content

Commit ceda41c

Browse files
committed
AccessUtils: fix handling of store_borrow in AccessBase.isDistinct
The result of a store_borrow can "escape" to other access bases, like a "pointer" access base. Then a store-borrow access base is _not_ distinct from such another base.
1 parent 983d955 commit ceda41c

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

SwiftCompilerSources/Sources/SIL/Utilities/AccessUtils.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ public enum AccessBase : CustomStringConvertible, Hashable {
286286
case (.storeBorrow(let arg), .storeBorrow(let otherArg)):
287287
return arg.allocStack != otherArg.allocStack
288288

289-
// A StoreBorrow location can only be used by other StoreBorrows.
290-
case (.storeBorrow, _):
291-
return true
292-
case (_, .storeBorrow):
293-
return true
289+
// Handle the special case of store_borrow - alloc_stack, because that would give a false result in the default case.
290+
case (.storeBorrow(let sbi), .stack(let asi)):
291+
return sbi.allocStack != asi
292+
case (.stack(let asi), .storeBorrow(let sbi)):
293+
return sbi.allocStack != asi
294294

295295
default:
296296
// As we already handled pairs of the same kind, here we handle pairs with different kinds.

test/SILOptimizer/basic-aa.sil

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,3 +684,25 @@ bb0(%0 : @guaranteed $GenericClass<Int32>, %1 : @guaranteed $GenericClass<Int>):
684684
return %9999 : $()
685685
}
686686

687+
// CHECK-LABEL: @test_store_borrow
688+
// CHECK: PAIR #7.
689+
// CHECK-NEXT: %1 = alloc_stack $X
690+
// CHECK-NEXT: %2 = store_borrow %0 to %1 : $*X
691+
// CHECK-NEXT: MayAlias
692+
// CHECK: PAIR #13.
693+
// CHECK-NEXT: %2 = store_borrow %0 to %1 : $*X
694+
// CHECK-NEXT: %4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*X
695+
// CHECK-NEXT: MayAlias
696+
sil [ossa] @test_store_borrow : $@convention(thin) (@guaranteed X) -> () {
697+
bb0(%0 : @guaranteed $X):
698+
%1 = alloc_stack $X
699+
%2 = store_borrow %0 to %1 : $*X
700+
%3 = address_to_pointer %2 : $*X to $Builtin.RawPointer
701+
%4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*X
702+
fix_lifetime %4 : $*X
703+
end_borrow %2 : $*X
704+
dealloc_stack %1 : $*X
705+
%7 = tuple ()
706+
return %7 : $()
707+
}
708+

0 commit comments

Comments
 (0)