@@ -298,7 +298,7 @@ class AllNonLocalMemory extends TAllNonLocalMemory, MemoryLocation {
298298
299299 final override string toStringInternal ( ) { result = "{AllNonLocal}" }
300300
301- final override VirtualVariable getVirtualVariable ( ) { result = TAllAliasedMemory ( irFunc , false ) }
301+ final override AliasedVirtualVariable getVirtualVariable ( ) { result . getIRFunction ( ) = irFunc }
302302
303303 final override Language:: LanguageType getType ( ) {
304304 result = any ( IRUnknownType type ) .getCanonicalLanguageType ( )
@@ -311,6 +311,14 @@ class AllNonLocalMemory extends TAllNonLocalMemory, MemoryLocation {
311311 final override string getUniqueId ( ) { result = "{AllNonLocal}" }
312312
313313 final override predicate isMayAccess ( ) { isMayAccess = true }
314+
315+ override predicate canDefineReadOnly ( ) {
316+ // A "must" access that defines all non-local memory appears only on the `InitializeNonLocal`
317+ // instruction, which provides the initial definition for all memory outside of the current
318+ // function's stack frame. This memory includes string literals and other read-only globals, so
319+ // we allow such an access to be the definition for a use of a read-only location.
320+ not isMayAccess ( )
321+ }
314322}
315323
316324/**
@@ -341,16 +349,6 @@ class AllAliasedMemory extends TAllAliasedMemory, MemoryLocation {
341349
342350class AliasedVirtualVariable extends AllAliasedMemory , VirtualVariable {
343351 AliasedVirtualVariable ( ) { not isMayAccess ( ) }
344-
345- override predicate canDefineReadOnly ( ) {
346- // A must-def of all aliased memory is only used in two places:
347- // 1. In the prologue of the function, to provide a definition for all memory defined before the
348- // function was called. In this case, it needs to provide a definition even for read-only
349- // non-local variables.
350- // 2. As the result of a `Chi` instruction. These don't participate in overlap analysis, so it's
351- // OK if we let this predicate hold in that case.
352- any ( )
353- }
354352}
355353
356354/**
@@ -405,10 +403,16 @@ private Overlap getExtentOverlap(MemoryLocation def, MemoryLocation use) {
405403 use instanceof AllNonLocalMemory and
406404 result instanceof MustExactlyOverlap
407405 or
408- // AllNonLocalMemory may partially overlap any location within the same virtual variable,
409- // except a local variable.
410- result instanceof MayPartiallyOverlap and
411- not use .isAlwaysAllocatedOnStack ( )
406+ not use instanceof AllNonLocalMemory and
407+ not use .isAlwaysAllocatedOnStack ( ) and
408+ if use instanceof VariableMemoryLocation
409+ then
410+ // AllNonLocalMemory totally overlaps any non-local variable.
411+ result instanceof MustTotallyOverlap
412+ else
413+ // AllNonLocalMemory may partially overlap any other location within the same virtual
414+ // variable, except a stack variable.
415+ result instanceof MayPartiallyOverlap
412416 )
413417 or
414418 def .getVirtualVariable ( ) = use .getVirtualVariable ( ) and
0 commit comments