@@ -438,7 +438,32 @@ class SsaPhiNode extends SsaPseudoDefinition, TPhi {
438438 */
439439private newtype TGlobalSsaWithFields =
440440 TGlobalRoot ( SsaGlobalVariable v ) or
441- TGlobalStep ( GlobalWithFields base , Field f ) { exists ( accessPathAux ( base , f ) ) }
441+ TGlobalStep ( GlobalWithFields base , Field f ) { exists ( accessGlobalPathAux ( base , f ) ) }
442+
443+
444+ /**
445+ * Gets a representation of `insn` as an ssa-with-fields value if there is one.
446+ */
447+ private TGlobalSsaWithFields accessGlobalPath ( IR:: Instruction insn ) {
448+ exists ( SsaGlobalVariable v | insn = v .getAUse ( ) | result = TGlobalRoot ( v ) )
449+ or
450+ exists ( GlobalWithFields base , Field f | insn = accessGlobalPathAux ( base , f ) | result = TGlobalStep ( base , f ) )
451+ }
452+
453+ /**
454+ * Gets a data-flow node that reads a field `f` from a node that is represented
455+ * by ssa-with-fields value `base`.
456+ */
457+ private IR:: Instruction accessGlobalPathAux ( TGlobalSsaWithFields base , Field f ) {
458+ exists ( IR:: FieldReadInstruction fr , IR:: Instruction frb |
459+ fr .getBase ( ) = frb or
460+ fr .getBase ( ) = IR:: implicitDerefInstruction ( frb .( IR:: EvalInstruction ) .getExpr ( ) )
461+ |
462+ base = accessGlobalPath ( frb ) and
463+ f = fr .getField ( ) and
464+ result = fr
465+ )
466+ }
442467
443468/**
444469 * An SSA variable, possibly with a chain of field reads on it.
@@ -541,34 +566,34 @@ class SsaWithFields extends TSsaWithFields {
541566
542567
543568/** An SSA variable with zero or more fields read from it. */
544- class GlobalWithFields extends TSsaWithFields {
569+ class GlobalWithFields extends TGlobalSsaWithFields {
545570 /**
546571 * Gets the SSA variable corresponding to the base of this SSA variable with fields.
547572 *
548573 * For example, the SSA variable corresponding to `a` for the SSA variable with fields
549574 * corresponding to `a.b`.
550575 */
551- SsaVariable getBaseVariable ( ) {
552- this = TRoot ( result )
576+ SsaGlobalVariable getBaseVariable ( ) {
577+ this = TGlobalRoot ( result )
553578 or
554- exists ( GlobalWithFields base | this = TStep ( base , _) | result = base .getBaseVariable ( ) )
579+ exists ( GlobalWithFields base | this = TGlobalStep ( base , _) | result = base .getBaseVariable ( ) )
555580 }
556581
557582 /** Gets a use that refers to this SSA variable with fields. */
558- DataFlow:: Node getAUse ( ) { this = accessPath ( result .asInstruction ( ) ) }
583+ DataFlow:: Node getAUse ( ) { this = accessGlobalPath ( result .asInstruction ( ) ) }
559584
560585 /** Gets the type of this SSA variable with fields. */
561586 Type getType ( ) {
562- exists ( SsaVariable var | this = TRoot ( var ) | result = var .getType ( ) )
587+ exists ( SsaGlobalVariable var | this = TGlobalRoot ( var ) | result = var .getType ( ) )
563588 or
564- exists ( Field f | this = TStep ( _, f ) | result = f .getType ( ) )
589+ exists ( Field f | this = TGlobalStep ( _, f ) | result = f .getType ( ) )
565590 }
566591
567592 /** Gets a textual representation of this element. */
568593 string toString ( ) {
569- exists ( SsaVariable var | this = TRoot ( var ) | result = "(" + var + ")" )
594+ exists ( SsaGlobalVariable var | this = TGlobalRoot ( var ) | result = "(" + var + ")" )
570595 or
571- exists ( GlobalWithFields base , Field f | this = TStep ( base , f ) | result = base + "." + f .getName ( ) )
596+ exists ( GlobalWithFields base , Field f | this = TGlobalStep ( base , f ) | result = base + "." + f .getName ( ) )
572597 }
573598
574599 /**
@@ -587,9 +612,9 @@ class GlobalWithFields extends TSsaWithFields {
587612 * `"a.b"`.
588613 */
589614 string getQualifiedName ( ) {
590- exists ( SsaVariable v | this = TRoot ( v ) and result = v .getSourceVariable ( ) .getName ( ) )
615+ exists ( SsaGlobalVariable v | this = TGlobalRoot ( v ) and result = v .getSourceVariable ( ) .getName ( ) )
591616 or
592- exists ( GlobalWithFields base , Field f | this = TStep ( base , f ) |
617+ exists ( GlobalWithFields base , Field f | this = TGlobalStep ( base , f ) |
593618 result = base .getQualifiedName ( ) + "." + f .getName ( )
594619 )
595620 }
0 commit comments