@@ -237,6 +237,15 @@ public enum AccessBase : CustomStringConvertible, Hashable {
237237 }
238238 }
239239
240+ func hasDifferentType( _ lhs: Value , _ rhs: Value ) -> Bool {
241+ return lhs. type != rhs. type &&
242+ // If the types have unbound generic arguments then we don't know
243+ // the possible range of the type. A type such as $Array<Int> may
244+ // alias $Array<T>. Right now we are conservative and we assume
245+ // that $UnsafeMutablePointer<T> and $Int may alias.
246+ !lhs. type. hasArchetype && !rhs. type. hasArchetype
247+ }
248+
240249 func argIsDistinct( _ arg: FunctionArgument , from other: AccessBase ) -> Bool {
241250 if arg. convention. isExclusiveIndirect {
242251 // Exclusive indirect arguments cannot alias with an address for which we know that it
@@ -252,16 +261,19 @@ public enum AccessBase : CustomStringConvertible, Hashable {
252261 // First handle all pairs of the same kind (except `yield` and `pointer`).
253262 case ( . box( let pb) , . box( let otherPb) ) :
254263 return pb. fieldIndex != otherPb. fieldIndex ||
255- isDifferentAllocation ( pb. box. referenceRoot, otherPb. box. referenceRoot)
264+ isDifferentAllocation ( pb. box. referenceRoot, otherPb. box. referenceRoot) ||
265+ hasDifferentType ( pb. box, otherPb. box)
256266 case ( . stack( let asi) , . stack( let otherAsi) ) :
257267 return asi != otherAsi
258268 case ( . global( let global) , . global( let otherGlobal) ) :
259269 return global != otherGlobal
260270 case ( . class( let rea) , . class( let otherRea) ) :
261271 return rea. fieldIndex != otherRea. fieldIndex ||
262- isDifferentAllocation ( rea. instance, otherRea. instance)
272+ isDifferentAllocation ( rea. instance, otherRea. instance) ||
273+ hasDifferentType ( rea. instance, otherRea. instance)
263274 case ( . tail( let rta) , . tail( let otherRta) ) :
264- return isDifferentAllocation ( rta. instance, otherRta. instance)
275+ return isDifferentAllocation ( rta. instance, otherRta. instance) ||
276+ hasDifferentType ( rta. instance, otherRta. instance)
265277 case ( . argument( let arg) , . argument( let otherArg) ) :
266278 return ( arg. convention. isExclusiveIndirect || otherArg. convention. isExclusiveIndirect) && arg != otherArg
267279
0 commit comments