@@ -237,6 +237,15 @@ public enum AccessBase : CustomStringConvertible, Hashable {
237
237
}
238
238
}
239
239
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
+
240
249
func argIsDistinct( _ arg: FunctionArgument , from other: AccessBase ) -> Bool {
241
250
if arg. convention. isExclusiveIndirect {
242
251
// Exclusive indirect arguments cannot alias with an address for which we know that it
@@ -252,16 +261,19 @@ public enum AccessBase : CustomStringConvertible, Hashable {
252
261
// First handle all pairs of the same kind (except `yield` and `pointer`).
253
262
case ( . box( let pb) , . box( let otherPb) ) :
254
263
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)
256
266
case ( . stack( let asi) , . stack( let otherAsi) ) :
257
267
return asi != otherAsi
258
268
case ( . global( let global) , . global( let otherGlobal) ) :
259
269
return global != otherGlobal
260
270
case ( . class( let rea) , . class( let otherRea) ) :
261
271
return rea. fieldIndex != otherRea. fieldIndex ||
262
- isDifferentAllocation ( rea. instance, otherRea. instance)
272
+ isDifferentAllocation ( rea. instance, otherRea. instance) ||
273
+ hasDifferentType ( rea. instance, otherRea. instance)
263
274
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)
265
277
case ( . argument( let arg) , . argument( let otherArg) ) :
266
278
return ( arg. convention. isExclusiveIndirect || otherArg. convention. isExclusiveIndirect) && arg != otherArg
267
279
0 commit comments