@@ -45,6 +45,7 @@ private newtype TMemoryLocation =
4545 languageType = type .getCanonicalLanguageType ( )
4646 } or
4747 TUnknownMemoryLocation ( IRFunction irFunc ) or
48+ TUnknownNonLocalMemoryLocation ( IRFunction irFunc ) or
4849 TUnknownVirtualVariable ( IRFunction irFunc )
4950
5051/**
@@ -162,6 +163,26 @@ class UnknownMemoryLocation extends TUnknownMemoryLocation, MemoryLocation {
162163 final override string getUniqueId ( ) { result = "{Unknown}" }
163164}
164165
166+ /**
167+ * An access to memory that is not known to be confined to a specific `IRVariable`, but is known to
168+ * not access memory on the current function's stack frame.
169+ */
170+ class UnknownNonLocalMemoryLocation extends TUnknownNonLocalMemoryLocation , MemoryLocation {
171+ IRFunction irFunc ;
172+
173+ UnknownNonLocalMemoryLocation ( ) { this = TUnknownNonLocalMemoryLocation ( irFunc ) }
174+
175+ final override string toString ( ) { result = "{UnknownNonLocal}" }
176+
177+ final override VirtualVariable getVirtualVariable ( ) { result = TUnknownVirtualVariable ( irFunc ) }
178+
179+ final override Language:: LanguageType getType ( ) {
180+ result = any ( IRUnknownType type ) .getCanonicalLanguageType ( )
181+ }
182+
183+ final override string getUniqueId ( ) { result = "{UnknownNonLocal}" }
184+ }
185+
165186/**
166187 * An access to all aliased memory.
167188 */
@@ -194,6 +215,13 @@ Overlap getOverlap(MemoryLocation def, MemoryLocation use) {
194215 def instanceof UnknownMemoryLocation and
195216 result instanceof MayPartiallyOverlap
196217 or
218+ // An UnknownNonLocalMemoryLocation may partially overlap any location within the same virtual
219+ // variable, except a local variable.
220+ def .getVirtualVariable ( ) = use .getVirtualVariable ( ) and
221+ def instanceof UnknownNonLocalMemoryLocation and
222+ result instanceof MayPartiallyOverlap and
223+ not use .( VariableMemoryLocation ) .getVariable ( ) instanceof IRAutomaticVariable
224+ or
197225 exists ( VariableMemoryLocation defVariableLocation |
198226 defVariableLocation = def and
199227 (
@@ -202,6 +230,13 @@ Overlap getOverlap(MemoryLocation def, MemoryLocation use) {
202230 ( use instanceof UnknownMemoryLocation or use instanceof UnknownVirtualVariable ) and
203231 result instanceof MayPartiallyOverlap
204232 or
233+ // A VariableMemoryLocation that is not a local variable may partially overlap an unknown
234+ // non-local location within the same virtual variable.
235+ def .getVirtualVariable ( ) = use .getVirtualVariable ( ) and
236+ use instanceof UnknownNonLocalMemoryLocation and
237+ result instanceof MayPartiallyOverlap and
238+ not defVariableLocation .getVariable ( ) instanceof IRAutomaticVariable
239+ or
205240 // A VariableMemoryLocation overlaps another location within the same variable based on the relationship
206241 // of the two offset intervals.
207242 exists ( Overlap intervalOverlap |
@@ -327,6 +362,9 @@ MemoryLocation getResultMemoryLocation(Instruction instr) {
327362 or
328363 kind instanceof EscapedMayMemoryAccess and
329364 result = TUnknownMemoryLocation ( instr .getEnclosingIRFunction ( ) )
365+ or
366+ kind instanceof NonLocalMayMemoryAccess and
367+ result = TUnknownNonLocalMemoryLocation ( instr .getEnclosingIRFunction ( ) )
330368 )
331369 )
332370}
@@ -351,6 +389,9 @@ MemoryLocation getOperandMemoryLocation(MemoryOperand operand) {
351389 or
352390 kind instanceof EscapedMayMemoryAccess and
353391 result = TUnknownMemoryLocation ( operand .getEnclosingIRFunction ( ) )
392+ or
393+ kind instanceof NonLocalMayMemoryAccess and
394+ result = TUnknownNonLocalMemoryLocation ( operand .getEnclosingIRFunction ( ) )
354395 )
355396 )
356397}
0 commit comments