@@ -9,6 +9,7 @@ private import semmle.code.cpp.models.interfaces.PartialFlow as PartialFlow
9
9
private import semmle.code.cpp.models.interfaces.FunctionInputsAndOutputs as FIO
10
10
private import semmle.code.cpp.ir.internal.IRCppLanguage
11
11
private import semmle.code.cpp.ir.dataflow.internal.ModelUtil
12
+ private import semmle.code.cpp.ir.implementation.raw.internal.TranslatedInitialization
12
13
private import DataFlowPrivate
13
14
import SsaInternalsCommon
14
15
@@ -329,6 +330,17 @@ private predicate sourceVariableHasBaseAndIndex(SourceVariable v, BaseSourceVari
329
330
v .getIndirection ( ) = ind
330
331
}
331
332
333
+ /**
334
+ * Gets the instruction that computes the address that's used to
335
+ * initialize `v`.
336
+ */
337
+ private Instruction getInitializationTargetAddress ( IRVariable v ) {
338
+ exists ( TranslatedVariableInitialization init |
339
+ init .getIRVariable ( ) = v and
340
+ result = init .getTargetAddress ( )
341
+ )
342
+ }
343
+
332
344
/** An initial definition of an `IRVariable`'s address. */
333
345
private class DefAddressImpl extends DefImpl , TDefAddressImpl {
334
346
BaseIRVariable v ;
@@ -347,8 +359,15 @@ private class DefAddressImpl extends DefImpl, TDefAddressImpl {
347
359
final override Node0Impl getValue ( ) { none ( ) }
348
360
349
361
final override predicate hasIndexInBlock ( IRBlock block , int index ) {
350
- block = v .getIRVariable ( ) .getEnclosingIRFunction ( ) .getEntryBlock ( ) and
351
- index = 0
362
+ exists ( IRVariable var | var = v .getIRVariable ( ) |
363
+ block .getInstruction ( index ) = getInitializationTargetAddress ( var )
364
+ or
365
+ // If there is no translatated element that does initialization of the
366
+ // variable we place the SSA definition at the entry block of the function.
367
+ not exists ( getInitializationTargetAddress ( var ) ) and
368
+ block = var .getEnclosingIRFunction ( ) .getEntryBlock ( ) and
369
+ index = 0
370
+ )
352
371
}
353
372
354
373
override Cpp:: Location getLocation ( ) { result = v .getIRVariable ( ) .getLocation ( ) }
0 commit comments