File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
SwiftCompilerSources/Sources/SIL/Utilities Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -323,8 +323,19 @@ public enum AccessBase : CustomStringConvertible, Hashable {
323
323
isDifferentAllocation ( rea. instance, otherRea. instance) ||
324
324
hasDifferentType ( rea. instance, otherRea. instance)
325
325
case ( . tail( let rta) , . tail( let otherRta) ) :
326
- return isDifferentAllocation ( rta. instance, otherRta. instance) ||
327
- hasDifferentType ( rta. instance, otherRta. instance)
326
+ if isDifferentAllocation ( rta. instance, otherRta. instance) {
327
+ return true
328
+ }
329
+ if hasDifferentType ( rta. instance, otherRta. instance) ,
330
+ // In contrast to `ref_element_addr`, tail addresses can also be obtained via a superclass
331
+ // (in case the derived class doesn't add any stored properties).
332
+ // Therefore if the instance types differ by sub-superclass relationship, the base is _not_ different.
333
+ !rta. instance. type. isExactSuperclass ( of: otherRta. instance. type) ,
334
+ !otherRta. instance. type. isExactSuperclass ( of: rta. instance. type)
335
+ {
336
+ return true
337
+ }
338
+ return false
328
339
case ( . argument( let arg) , . argument( let otherArg) ) :
329
340
return ( arg. convention. isExclusiveIndirect || otherArg. convention. isExclusiveIndirect) && arg != otherArg
330
341
Original file line number Diff line number Diff line change @@ -665,6 +665,25 @@ bb0:
665
665
%99 = tuple ()
666
666
return %99 : $()
667
667
}
668
+
669
+ class Derived: X {}
670
+
671
+ // CHECK-LABEL: @test_tail_addr_and_upcast
672
+ // CHECK: PAIR #10.
673
+ // CHECK-NEXT: %2 = ref_tail_addr %1 : $X, $Int32
674
+ // CHECK-NEXT: %3 = ref_tail_addr %0 : $Derived, $Int32
675
+ // CHECK-NEXT: MayAlias
676
+ sil @test_tail_addr_and_upcast : $@convention(thin) () -> () {
677
+ bb0:
678
+ %0 = alloc_ref $Derived
679
+ %1 = upcast %0 to $X
680
+ %2 = ref_tail_addr %1, $Int32
681
+ %3 = ref_tail_addr %0, $Int32
682
+ fix_lifetime %2
683
+ fix_lifetime %3
684
+ %r = tuple ()
685
+ return %r
686
+ }
668
687
669
688
class GenericClass<T> {
670
689
var x : T
You can’t perform that action at this time.
0 commit comments